kaoruhotarubi commited on
Commit
b5bfb00
·
1 Parent(s): f414bd3

updated tts

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -14,7 +14,7 @@ import random
14
  OUTPUT_DIR = "output"
15
  os.makedirs(OUTPUT_DIR, exist_ok=True)
16
 
17
-
18
  model_name = "TheBloke/Amethyst-13B-Mistral-AWQ"
19
 
20
  # Load the tokenizer
@@ -162,16 +162,28 @@ def get_emotion_image(emotion):
162
  # Select a random image for the given emotion
163
  return random.choice(emotion_images.get(emotion, ["assets/rena2.png"]))
164
 
 
165
  def generate_speech(text, emotion="happy"):
166
  """Generate speech from text using Coqui TTS."""
167
-
168
- output_path = "output/response.wav"
 
169
 
170
  # Ensure output directory exists
171
- os.makedirs(os.path.dirname(output_path), exist_ok=True)
 
 
 
 
 
 
 
 
 
172
 
173
- # Generate speech file
174
- tts.tts_to_file(text=text, file_path=output_path)
 
175
 
176
  return output_path
177
 
 
14
  OUTPUT_DIR = "output"
15
  os.makedirs(OUTPUT_DIR, exist_ok=True)
16
 
17
+ tts = TTS(model_name="tts_models/ja/kokoro/tacotron2-DDC")
18
  model_name = "TheBloke/Amethyst-13B-Mistral-AWQ"
19
 
20
  # Load the tokenizer
 
162
  # Select a random image for the given emotion
163
  return random.choice(emotion_images.get(emotion, ["assets/rena2.png"]))
164
 
165
+
166
  def generate_speech(text, emotion="happy"):
167
  """Generate speech from text using Coqui TTS."""
168
+
169
+ output_dir = "output"
170
+ output_path = os.path.join(output_dir, "response.wav")
171
 
172
  # Ensure output directory exists
173
+ os.makedirs(output_dir, exist_ok=True)
174
+
175
+ try:
176
+ # Generate speech file
177
+ tts.tts_to_file(text=text, file_path=output_path)
178
+ print(f"Generated speech saved to: {output_path}")
179
+
180
+ # Verify the file was created
181
+ if not os.path.exists(output_path):
182
+ raise FileNotFoundError(f"TTS output file not found: {output_path}")
183
 
184
+ except Exception as e:
185
+ print(f"Error generating speech: {e}")
186
+ return None
187
 
188
  return output_path
189