kaoruhotarubi commited on
Commit
b18df1d
·
1 Parent(s): 2a9ec3d

changed audio

Browse files
Files changed (2) hide show
  1. app.py +10 -8
  2. setup.sh +1 -18
app.py CHANGED
@@ -4,7 +4,8 @@ import torch
4
  import gradio as gr
5
  from PIL import Image
6
  from TTS.api import TTS
7
- from playsound import playsound
 
8
  import os
9
  import random
10
 
@@ -164,14 +165,14 @@ def get_emotion_image(emotion):
164
  def generate_speech(text, emotion="happy"):
165
  """Generate speech from text using Coqui TTS."""
166
 
167
- output_path = os.path.join(OUTPUT_DIR, "response.wav")
168
- model_name = "tts_models/ja/kokoro/tacotron2-DDC" # Adjust based on preferred voice
169
-
170
- tts = TTS(model_name=model_name, progress_bar=False, gpu=True)
171
-
172
  output_path = "output/response.wav"
 
 
 
 
 
173
  tts.tts_to_file(text=text, file_path=output_path)
174
-
175
  return output_path
176
 
177
  @spaces.GPU
@@ -262,7 +263,8 @@ Rena:"""
262
  tts_audio = generate_speech(response, emotion=current_emotion)
263
 
264
  # Play audio on the local system (for testing)
265
- playsound(tts_audio)
 
266
 
267
  # Add Rena's response to the conversation history
268
  conversation_history.append(f"Rena: {response}")
 
4
  import gradio as gr
5
  from PIL import Image
6
  from TTS.api import TTS
7
+ from pydub import AudioSegment
8
+ from pydub.playback import play
9
  import os
10
  import random
11
 
 
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
 
178
  @spaces.GPU
 
263
  tts_audio = generate_speech(response, emotion=current_emotion)
264
 
265
  # Play audio on the local system (for testing)
266
+ audio = AudioSegment.from_file(tts_audio, format="wav")
267
+ play(audio)
268
 
269
  # Add Rena's response to the conversation history
270
  conversation_history.append(f"Rena: {response}")
setup.sh CHANGED
@@ -1,19 +1,2 @@
1
- apt-get update
2
  #!/bin/bash -e
3
-
4
- apt-get update
5
-
6
- apt-get install -y \
7
- gobject-introspection \
8
- libgirepository1.0-dev \
9
- gir1.2-gtk-3.0 \
10
- python3-gi \
11
- python3-gi-cairo \
12
- libcairo2-dev \
13
- libglib2.0-dev \
14
- libgirepository1.0-dev \
15
- pkg-config \
16
- cmake \
17
- build-essential \
18
- meson \
19
- ninja-build
 
 
1
  #!/bin/bash -e
2
+ apt-get update && apt-get install -y ffmpeg