File size: 967 Bytes
0565a93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
import requests
import os
import tempfile
from scipy.io import wavfile


demo_keys = os.environ['DEMO_KEYS']
tts_url = "https://translation-api.ghananlp.org/tts/v1/tts"
translation_url = "https://translation-api.ghananlp.org/v1/translate"
headers ={
    # Request headers
    'Content-Type': 'application/json',
    'Cache-Control': 'no-cache',
    'Ocp-Apim-Subscription-Key': demo_keys
    }

def translate(text, source_language, target_language):
    data = {
        "in": text,
        "lang": source_language + "-" + target_language
    }
    response = requests.post(translation_url, headers=headers, json=data).text
    return response

gr.Interface(
    fn=synthesize,
    inputs=[
        gr.Text(label="Input Text"),
        gr.Radio(label="Language", choices=[
            "tw",
        ],
        value="tw"),
    ],
    outputs=[
        gr.Audio(label="Generated Speech", type="numpy"),
    ],
    title="ACity TTS Demo",
).launch()