Spaces:
Sleeping
Sleeping
Commit
•
906d570
1
Parent(s):
8b92f6f
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import os
|
|
|
4 |
from TTS.api import TTS
|
5 |
-
|
6 |
|
7 |
# Check if the user has agreed to the terms of service
|
8 |
tos_gr = gr.Checkbox(
|
@@ -30,19 +31,23 @@ def generate_voice(text, language, sample_voice, tos_agreed):
|
|
30 |
# Use the sample voice to convert text to speech
|
31 |
wav = tts.tts(text=text, speaker_wav=speaker_wav_path, language=language)
|
32 |
|
33 |
-
#
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Define the Gradio interface
|
37 |
iface = gr.Interface(
|
38 |
fn=generate_voice,
|
39 |
inputs=[
|
40 |
-
gr.Textbox(lines=3, label="Enter Text"),
|
41 |
-
gr.Dropdown(["es", "en", "fr"], label="Select Language"),
|
42 |
-
gr.File(label="Upload Sample Voice"),
|
43 |
-
tos_gr,
|
44 |
],
|
45 |
-
outputs=gr.Audio(label="Generated Audio")
|
46 |
)
|
47 |
|
48 |
# Launch the Gradio interface
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import os
|
4 |
+
import numpy as np
|
5 |
from TTS.api import TTS
|
6 |
+
from scipy.io.wavfile import write
|
7 |
|
8 |
# Check if the user has agreed to the terms of service
|
9 |
tos_gr = gr.Checkbox(
|
|
|
31 |
# Use the sample voice to convert text to speech
|
32 |
wav = tts.tts(text=text, speaker_wav=speaker_wav_path, language=language)
|
33 |
|
34 |
+
# Save the generated audio to a temporary file
|
35 |
+
output_path = "generated_audio.wav"
|
36 |
+
write(output_path, 22050, np.array(wav, dtype=np.int16)) # Use np.int16
|
37 |
+
|
38 |
+
# Return the path to the generated audio file
|
39 |
+
return output_path
|
40 |
|
41 |
# Define the Gradio interface
|
42 |
iface = gr.Interface(
|
43 |
fn=generate_voice,
|
44 |
inputs=[
|
45 |
+
gr.Textbox(lines=3, label="Enter Text"),
|
46 |
+
gr.Dropdown(["es", "en", "fr"], label="Select Language"),
|
47 |
+
gr.File(label="Upload Sample Voice"),
|
48 |
+
tos_gr,
|
49 |
],
|
50 |
+
outputs=gr.Audio(label="Generated Audio"),
|
51 |
)
|
52 |
|
53 |
# Launch the Gradio interface
|