Commit
·
36841c3
1
Parent(s):
d1d60a3
Update app.py
Browse files
app.py
CHANGED
@@ -632,18 +632,21 @@ def generate_story_and_speech(input_text, chatbot_role):
|
|
632 |
if last_history is not None:
|
633 |
# Convert the list of lists back into a list of tuples for the history
|
634 |
history_tuples = [tuple(entry) for entry in last_history]
|
635 |
-
|
|
|
636 |
if synthesized_speech:
|
|
|
|
|
637 |
# Access the BytesIO object containing the WAV file and extract bytes
|
638 |
-
speech_audio_bytes =
|
639 |
-
|
640 |
# Convert the speech audio bytes to base64 for JSON serialization
|
641 |
speech_audio_base64 = base64.b64encode(speech_audio_bytes).decode('utf8')
|
642 |
-
|
643 |
-
|
644 |
return {"text": story_text.strip(), "audio": speech_audio_base64}
|
|
|
|
|
|
|
645 |
else:
|
646 |
-
return {"text": "Failed to generate story", "audio": None}
|
647 |
|
648 |
# Create a Gradio Interface using only the `generate_story_and_speech()` function and the 'json' output type
|
649 |
demo = gr.Interface(
|
|
|
632 |
if last_history is not None:
|
633 |
# Convert the list of lists back into a list of tuples for the history
|
634 |
history_tuples = [tuple(entry) for entry in last_history]
|
635 |
+
|
636 |
+
synthesized_speech = generate_speech_for_sentence(history_tuples, chatbot_role, story_text, return_as_byte=True)
|
637 |
if synthesized_speech:
|
638 |
+
# Get the Gradio Audio object
|
639 |
+
audio_obj = synthesized_speech[1]
|
640 |
# Access the BytesIO object containing the WAV file and extract bytes
|
641 |
+
speech_audio_bytes = audio_obj.data # Use the 'data' attribute to get the bytearray
|
|
|
642 |
# Convert the speech audio bytes to base64 for JSON serialization
|
643 |
speech_audio_base64 = base64.b64encode(speech_audio_bytes).decode('utf8')
|
|
|
|
|
644 |
return {"text": story_text.strip(), "audio": speech_audio_base64}
|
645 |
+
else:
|
646 |
+
return {"text": "Failed to generate story (no synthesized speech)", "audio": None}
|
647 |
+
|
648 |
else:
|
649 |
+
return {"text": "Failed to generate story (last_history is empty)", "audio": None}
|
650 |
|
651 |
# Create a Gradio Interface using only the `generate_story_and_speech()` function and the 'json' output type
|
652 |
demo = gr.Interface(
|