Spaces:
Build error
Build error
Create python
Browse files
python
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from TTS.api import TTS
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
import tempfile
|
| 5 |
+
|
| 6 |
+
# Initialize Coqui TTS with a pre-trained model
|
| 7 |
+
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
|
| 8 |
+
|
| 9 |
+
def text_to_audio(file):
|
| 10 |
+
"""Convert uploaded text file to audio."""
|
| 11 |
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
| 12 |
+
temp_file.write(file.read())
|
| 13 |
+
temp_path = temp_file.name
|
| 14 |
+
|
| 15 |
+
with open(temp_path, 'r') as f:
|
| 16 |
+
text = f.read()
|
| 17 |
+
|
| 18 |
+
# Generate audio
|
| 19 |
+
audio_path = os.path.join(tempfile.gettempdir(), "output.wav")
|
| 20 |
+
tts.tts_to_file(text, audio_path)
|
| 21 |
+
return "Conversion successful!", audio_path
|
| 22 |
+
|
| 23 |
+
interface = gr.Interface(
|
| 24 |
+
fn=text_to_audio,
|
| 25 |
+
inputs=gr.File(label="Upload your text file"),
|
| 26 |
+
outputs=[
|
| 27 |
+
gr.Textbox(label="Result"),
|
| 28 |
+
gr.Audio(label="Generated Audio")
|
| 29 |
+
]
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
interface.launch()
|