import gradio as gr | |
import base64 | |
from Zonos_main.tts import ZonosTTS | |
# Initialize model ONCE when space starts | |
tts = ZonosTTS() # <-- MUST WORK WITHOUT ERRORS | |
def generate_audio(text): | |
try: | |
# Generate raw audio bytes (MODIFY THIS TO MATCH YOUR MODEL) | |
audio_bytes = tts.generate(text) # Should return bytes directly | |
# Convert to base64 | |
return f"data:audio/wav;base64,{base64.b64encode(audio_bytes).decode('utf-8')}" | |
except Exception as e: | |
raise gr.Error(f"TTS Failed: {str(e)}") | |
# Minimal interface | |
gr.Interface( | |
fn=generate_audio, | |
inputs=gr.Textbox(label="Input"), | |
outputs=gr.Audio(type="filepath"), | |
).launch() |