Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
import tempfile
|
5 |
+
from scipy.io import wavfile
|
6 |
+
|
7 |
+
|
8 |
+
demo_keys = os.environ['DEMO_KEYS']
|
9 |
+
tts_url = "https://translation-api.ghananlp.org/tts/v1/tts"
|
10 |
+
translation_url = "https://translation-api.ghananlp.org/v1/translate"
|
11 |
+
headers ={
|
12 |
+
# Request headers
|
13 |
+
'Content-Type': 'application/json',
|
14 |
+
'Cache-Control': 'no-cache',
|
15 |
+
'Ocp-Apim-Subscription-Key': demo_keys
|
16 |
+
}
|
17 |
+
|
18 |
+
def translate(text, source_language, target_language):
|
19 |
+
data = {
|
20 |
+
"in": text,
|
21 |
+
"lang": source_language + "-" + target_language
|
22 |
+
}
|
23 |
+
response = requests.post(translation_url, headers=headers, json=data).text
|
24 |
+
return response
|
25 |
+
|
26 |
+
gr.Interface(
|
27 |
+
fn=synthesize,
|
28 |
+
inputs=[
|
29 |
+
gr.Text(label="Input Text"),
|
30 |
+
gr.Radio(label="Language", choices=[
|
31 |
+
"tw",
|
32 |
+
],
|
33 |
+
value="tw"),
|
34 |
+
],
|
35 |
+
outputs=[
|
36 |
+
gr.Audio(label="Generated Speech", type="numpy"),
|
37 |
+
],
|
38 |
+
title="ACity TTS Demo",
|
39 |
+
).launch()
|