Spaces:
Sleeping
Sleeping
Steven Hillis
commited on
Commit
•
d86f106
1
Parent(s):
466a191
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
|
9 |
+
base_url = "https://api.sandbox.deepgram.com/nlu"
|
10 |
+
token_str = os.environ['DG_TOKEN']
|
11 |
+
def tts_fn(text, speed, pitch_steps, variability):
|
12 |
+
texts = [text]
|
13 |
+
response = requests.post(
|
14 |
+
f'{base_url}',
|
15 |
+
files=[('texts', ('texts', json.dumps(texts), 'application/json'))],
|
16 |
+
params={'synthesize': 'true', 'speed': speed, 'pitch_steps': int(pitch_steps), 'variability': variability},
|
17 |
+
headers={
|
18 |
+
'Authorization': f'Token {token_str}'
|
19 |
+
},
|
20 |
+
).json()
|
21 |
+
sample_rate = int(response['results'][0]['sample_rate'])
|
22 |
+
audio = np.array(response['results'][0]['audio'], dtype=np.float32)
|
23 |
+
return (sample_rate, audio)
|
24 |
+
|
25 |
+
|
26 |
+
app = gr.Blocks()
|
27 |
+
|
28 |
+
with app:
|
29 |
+
with gr.Tab("TTS MVP"):
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
pangram = "The beige hue on the waters of the loch impressed all, including the French queen, before she heard that symphony again, just as young Arthur wanted."
|
33 |
+
cherry = "Good evening. I'm a text to speech bot. Please allow me to assist you."
|
34 |
+
textbox = gr.TextArea(label="Text", placeholder="Type a sentence here", value=cherry)
|
35 |
+
speed = gr.Slider(minimum=0.0, maximum=2.0, value=1.1, step=0.1, label="Speed")
|
36 |
+
pitch_steps = gr.Slider(minimum=-24, maximum=24, value=0, step=1, label="Pitch Steps: 12 to an octave")
|
37 |
+
variability = gr.Slider(minimum=0.0, maximum=1.0, value=0.7, step=0.1, label="Variability")
|
38 |
+
|
39 |
+
with gr.Column():
|
40 |
+
audio_output = gr.Audio(label="Output Audio", elem_id='tts-audio')
|
41 |
+
btn = gr.Button("Generate")
|
42 |
+
btn.click(tts_fn, inputs=[textbox, speed, pitch_steps, variability], outputs=[audio_output])
|
43 |
+
app.launch(share=True)
|