bafifi4972 commited on
Commit
8e1e76f
·
verified ·
1 Parent(s): 544d495

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from supertonic import TTS
3
  import tempfile
4
  import os
 
5
 
6
  # Initialize TTS
7
  try:
@@ -31,16 +32,28 @@ def generate_speech(text, voice, language_name):
31
  style = tts.get_voice_style(voice_name=voice)
32
  wav, duration = tts.synthesize(text, voice_style=style, lang=lang_code)
33
 
34
- # ИСПРАВЛЕНИЕ: Создаем уникальный временный файл для каждого запроса
 
 
 
 
 
 
 
 
 
 
 
35
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
36
  output_path = tmp.name
37
 
38
  tts.save_audio(wav, output_path)
39
- readable_duration = float(duration)
40
 
41
  return output_path, f"Generation Successful! \nDuration: {readable_duration:.2f}s"
42
 
43
  except Exception as e:
 
 
44
  raise gr.Error(f"Generation failed: {str(e)}")
45
 
46
  with gr.Blocks(theme='soft', title="Supertonic 3 TTS") as demo:
@@ -65,5 +78,4 @@ with gr.Blocks(theme='soft', title="Supertonic 3 TTS") as demo:
65
  )
66
 
67
  if __name__ == "__main__":
68
- # ВАЖНО для Hugging Face Spaces:
69
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
2
  from supertonic import TTS
3
  import tempfile
4
  import os
5
+ import numpy as np # <-- Добавляем numpy
6
 
7
  # Initialize TTS
8
  try:
 
32
  style = tts.get_voice_style(voice_name=voice)
33
  wav, duration = tts.synthesize(text, voice_style=style, lang=lang_code)
34
 
35
+ # ==========================================
36
+ # ИСПРАВЛЕНИЕ ОШИБКИ С DURATION
37
+ # Превращаем в numpy массив, делаем плоским (flatten)
38
+ # и суммируем (на случай, если там массив из нескольких чанков)
39
+ # ==========================================
40
+ duration_array = np.asarray(duration).flatten()
41
+ if duration_array.size > 0:
42
+ readable_duration = float(duration_array.sum())
43
+ else:
44
+ readable_duration = 0.0
45
+
46
+ # Создаем уникальный временный файл
47
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
48
  output_path = tmp.name
49
 
50
  tts.save_audio(wav, output_path)
 
51
 
52
  return output_path, f"Generation Successful! \nDuration: {readable_duration:.2f}s"
53
 
54
  except Exception as e:
55
+ import traceback
56
+ traceback.print_exc() # Выведет точную ошибку в логи HF Spaces
57
  raise gr.Error(f"Generation failed: {str(e)}")
58
 
59
  with gr.Blocks(theme='soft', title="Supertonic 3 TTS") as demo:
 
78
  )
79
 
80
  if __name__ == "__main__":
 
81
  demo.launch(server_name="0.0.0.0", server_port=7860)