Spaces:
Running on Zero
Running on Zero
Upload app.py
Browse files
app.py
CHANGED
|
@@ -31,17 +31,24 @@ def generate_tts(text: str, voice: str):
|
|
| 31 |
m = get_model()
|
| 32 |
clean_voice = voice.replace("pocket-", "").replace("-", "_")
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
if hasattr(m, "
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
else:
|
| 40 |
-
#
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
audio = m.generate_audio(
|
| 45 |
|
| 46 |
if isinstance(audio, torch.Tensor):
|
| 47 |
audio_np = audio.detach().cpu().numpy()
|
|
@@ -54,7 +61,7 @@ def generate_tts(text: str, voice: str):
|
|
| 54 |
demo = gr.Interface(
|
| 55 |
fn=generate_tts,
|
| 56 |
inputs=[
|
| 57 |
-
gr.Textbox(label="Text to speak", value="Hello! This is
|
| 58 |
gr.Dropdown(choices=VOICE_LIST, value="stuart_bell", label="Voice"),
|
| 59 |
],
|
| 60 |
outputs=gr.Audio(label="Generated Audio", type="numpy"),
|
|
|
|
| 31 |
m = get_model()
|
| 32 |
clean_voice = voice.replace("pocket-", "").replace("-", "_")
|
| 33 |
|
| 34 |
+
# Initialize the model state with the specified voice
|
| 35 |
+
if hasattr(m, "init_model_state"):
|
| 36 |
+
try:
|
| 37 |
+
model_state = m.init_model_state(voice=clean_voice)
|
| 38 |
+
except TypeError:
|
| 39 |
+
model_state = m.init_model_state(clean_voice)
|
| 40 |
+
elif hasattr(m, "get_voice_state"):
|
| 41 |
+
model_state = m.get_voice_state(clean_voice)
|
| 42 |
else:
|
| 43 |
+
# Check all available methods on m for state initialization
|
| 44 |
+
init_fn = getattr(m, "get_initial_state", getattr(m, "new_state", None))
|
| 45 |
+
if init_fn:
|
| 46 |
+
model_state = init_fn(clean_voice)
|
| 47 |
+
else:
|
| 48 |
+
raise RuntimeError(f"Available methods on TTSModel: {[fn for fn in dir(m) if not fn.startswith('_')]}")
|
| 49 |
|
| 50 |
+
# Generate audio
|
| 51 |
+
audio = m.generate_audio(model_state, clean_text)
|
| 52 |
|
| 53 |
if isinstance(audio, torch.Tensor):
|
| 54 |
audio_np = audio.detach().cpu().numpy()
|
|
|
|
| 61 |
demo = gr.Interface(
|
| 62 |
fn=generate_tts,
|
| 63 |
inputs=[
|
| 64 |
+
gr.Textbox(label="Text to speak", value="Hello! This is Kyutai Pocket TTS running smoothly."),
|
| 65 |
gr.Dropdown(choices=VOICE_LIST, value="stuart_bell", label="Voice"),
|
| 66 |
],
|
| 67 |
outputs=gr.Audio(label="Generated Audio", type="numpy"),
|