Spaces:
Runtime error
Runtime error
engine = pyttsx3.init()
Browse files- app.py +21 -10
- requirements.txt +2 -1
app.py
CHANGED
@@ -116,22 +116,33 @@ def main_function(password: str, theme: str, language: str, method: str, rounds:
|
|
116 |
|
117 |
return chatbot_dialogue, audio_path, file_name
|
118 |
|
119 |
-
|
120 |
def dialogue_to_audio(dialogue, role1_gender, role2_gender):
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
128 |
|
129 |
-
tts = gTTS(text=text, lang='zh-tw')
|
130 |
file_path = "temp_audio.mp3"
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
return file_path
|
133 |
|
134 |
|
|
|
135 |
if __name__ == "__main__":
|
136 |
gr.Interface(
|
137 |
main_function,
|
|
|
116 |
|
117 |
return chatbot_dialogue, audio_path, file_name
|
118 |
|
|
|
119 |
def dialogue_to_audio(dialogue, role1_gender, role2_gender):
|
120 |
+
engine = pyttsx3.init()
|
121 |
+
|
122 |
+
# Fetch the list of available voices
|
123 |
+
voices = engine.getProperty('voices')
|
124 |
+
|
125 |
+
# Get voice IDs for male and female voices (you might need to adjust these based on available voices on your system)
|
126 |
+
male_voice_id = "com.apple.speech.synthesis.voice.alex" # Example ID for a male voice
|
127 |
+
female_voice_id = "com.apple.speech.synthesis.voice.victoria" # Example ID for a female voice
|
128 |
|
|
|
129 |
file_path = "temp_audio.mp3"
|
130 |
+
|
131 |
+
for i, item in enumerate(dialogue):
|
132 |
+
gender = role1_gender if i % 2 == 0 else role2_gender
|
133 |
+
voice_id = male_voice_id if gender == "male" else female_voice_id
|
134 |
+
|
135 |
+
# Set the voice
|
136 |
+
engine.setProperty('voice', voice_id)
|
137 |
+
|
138 |
+
# Now, synthesize the speech
|
139 |
+
engine.save_to_file(item['content'], file_path)
|
140 |
+
engine.runAndWait()
|
141 |
+
|
142 |
return file_path
|
143 |
|
144 |
|
145 |
+
|
146 |
if __name__ == "__main__":
|
147 |
gr.Interface(
|
148 |
main_function,
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
gradio
|
2 |
gtts
|
3 |
-
openai
|
|
|
|
1 |
gradio
|
2 |
gtts
|
3 |
+
openai
|
4 |
+
pyttsx3
|