Add prompts to video generation and final message in listening audios.

This commit is contained in:
Cristiano Ferreira
2024-03-19 19:38:09 +00:00
parent 8b83a4163d
commit 274bd79c6a
2 changed files with 24 additions and 2 deletions

8
app.py
View File

@@ -634,7 +634,11 @@ def generate_speaking_video():
try:
data = request.get_json()
avatar = data.get("avatar", random.choice(list(AvatarEnum)).value)
sp1_result = create_video(data["question"], avatar)
prompts = data.get("prompts", [])
question = data.get("question")
if len(prompts) > 0:
question = question + " In your answer you should consider: " + " ".join(prompts)
sp1_result = create_video(question, avatar)
if sp1_result is not None:
sound_file_path = VIDEO_FILES_PATH + sp1_result
firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + sp1_result
@@ -644,7 +648,7 @@ def generate_speaking_video():
return {
"text": data["question"],
"prompts": data["prompts"] if "prompts" in data else [],
"prompts": prompts,
"title": data["topic"],
"video_url": sp1_video_url,
"video_path": sp1_video_path,

View File

@@ -36,6 +36,15 @@ def text_to_speech(text: str, file_name: str):
VoiceId=voice
)
audio_segments.append(tts_response['AudioStream'].read())
# Add finish message
audio_segments.append(client.synthesize_speech(
Engine="neural",
Text="This audio recording, for the listening exercise, has finished.",
OutputFormat="mp3",
VoiceId="Stephen"
)['AudioStream'].read())
# Combine the audio segments into a single audio file
combined_audio = b"".join(audio_segments)
# Save the combined audio to a single file
@@ -63,6 +72,15 @@ def conversation_text_to_speech(conversation: list, file_name: str):
VoiceId=segment["voice"]
)
audio_segments.append(response['AudioStream'].read())
# Add finish message
audio_segments.append(client.synthesize_speech(
Engine="neural",
Text="This audio recording, for the listening exercise, has finished.",
OutputFormat="mp3",
VoiceId="Stephen"
)['AudioStream'].read())
# Combine the audio segments into a single audio file
combined_audio = b"".join(audio_segments)
# Save the combined audio to a single file