Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
from Zonos_main.tts import ZonosTTS # Adjust import path as needed
|
| 5 |
+
|
| 6 |
+
# Initialize TTS model
|
| 7 |
+
tts = ZonosTTS()
|
| 8 |
+
|
| 9 |
+
def generate_audio(text):
|
| 10 |
+
try:
|
| 11 |
+
# Generate audio file path
|
| 12 |
+
output_path = "output.wav"
|
| 13 |
+
|
| 14 |
+
# Run TTS
|
| 15 |
+
tts.generate(text, output_path)
|
| 16 |
+
|
| 17 |
+
# Return audio file
|
| 18 |
+
return output_path
|
| 19 |
+
except Exception as e:
|
| 20 |
+
raise gr.Error(f"Audio generation failed: {str(e)}")
|
| 21 |
+
|
| 22 |
+
# Create Gradio interface
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=generate_audio,
|
| 25 |
+
inputs=gr.Textbox(label="Input Text"),
|
| 26 |
+
outputs=gr.Audio(label="Generated Speech"),
|
| 27 |
+
title="Zonos TTS Service",
|
| 28 |
+
description="Convert text to speech using Zonos TTS model"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Launch the app
|
| 32 |
+
demo.launch()
|