Spaces:
Runtime error
Runtime error
def dialogue_to_audio(dialogue, role1_gender, role2_gender):
Browse files
app.py
CHANGED
@@ -117,13 +117,21 @@ def main_function(password: str, theme: str, language: str, method: str, rounds:
|
|
117 |
return chatbot_dialogue, audio_path, file_name
|
118 |
|
119 |
|
120 |
-
def dialogue_to_audio(dialogue):
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
tts = gTTS(text=text, lang='zh-tw')
|
123 |
file_path = "temp_audio.mp3"
|
124 |
tts.save(file_path)
|
125 |
return file_path
|
126 |
|
|
|
127 |
if __name__ == "__main__":
|
128 |
gr.Interface(
|
129 |
main_function,
|
|
|
117 |
return chatbot_dialogue, audio_path, file_name
|
118 |
|
119 |
|
120 |
+
def dialogue_to_audio(dialogue, role1_gender, role2_gender):
|
121 |
+
# Assuming the dialogue follows the format of alternating roles.
|
122 |
+
text = ""
|
123 |
+
for i, item in enumerate(dialogue):
|
124 |
+
gender = role1_gender if i % 2 == 0 else role2_gender
|
125 |
+
voice_attribute = "male" if gender == "male" else "female"
|
126 |
+
# For simplicity, we'll just prepend the voice attribute. In a real-world scenario, you'd use this to select different TTS voices.
|
127 |
+
text += f"{voice_attribute} voice: {item['content']} "
|
128 |
+
|
129 |
tts = gTTS(text=text, lang='zh-tw')
|
130 |
file_path = "temp_audio.mp3"
|
131 |
tts.save(file_path)
|
132 |
return file_path
|
133 |
|
134 |
+
|
135 |
if __name__ == "__main__":
|
136 |
gr.Interface(
|
137 |
main_function,
|