Pelku commited on
Commit
53062d7
·
verified ·
1 Parent(s): 08da79e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
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
- # 1. Get the voice state dict for the selected voice
35
- if hasattr(m, "get_voice_state"):
36
- voice_state = m.get_voice_state(clean_voice)
37
- elif hasattr(m, "load_voice_state"):
38
- voice_state = m.load_voice_state(clean_voice)
 
 
 
39
  else:
40
- # Fallback to empty dict or voice lookup
41
- voice_state = m.get_state_for_voice(clean_voice) if hasattr(m, "get_state_for_voice") else {}
 
 
 
 
42
 
43
- # 2. Generate audio with (voice_state_dict, text)
44
- audio = m.generate_audio(voice_state, clean_text)
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 genuine Kyutai Pocket TTS running smoothly."),
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"),