Add prompts to video generation and final message in listening audios.
This commit is contained in:
8
app.py
8
app.py
@@ -634,7 +634,11 @@ def generate_speaking_video():
|
|||||||
try:
|
try:
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
avatar = data.get("avatar", random.choice(list(AvatarEnum)).value)
|
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:
|
if sp1_result is not None:
|
||||||
sound_file_path = VIDEO_FILES_PATH + sp1_result
|
sound_file_path = VIDEO_FILES_PATH + sp1_result
|
||||||
firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + sp1_result
|
firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + sp1_result
|
||||||
@@ -644,7 +648,7 @@ def generate_speaking_video():
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
"text": data["question"],
|
"text": data["question"],
|
||||||
"prompts": data["prompts"] if "prompts" in data else [],
|
"prompts": prompts,
|
||||||
"title": data["topic"],
|
"title": data["topic"],
|
||||||
"video_url": sp1_video_url,
|
"video_url": sp1_video_url,
|
||||||
"video_path": sp1_video_path,
|
"video_path": sp1_video_path,
|
||||||
|
|||||||
@@ -36,6 +36,15 @@ def text_to_speech(text: str, file_name: str):
|
|||||||
VoiceId=voice
|
VoiceId=voice
|
||||||
)
|
)
|
||||||
audio_segments.append(tts_response['AudioStream'].read())
|
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
|
# Combine the audio segments into a single audio file
|
||||||
combined_audio = b"".join(audio_segments)
|
combined_audio = b"".join(audio_segments)
|
||||||
# Save the combined audio to a single file
|
# 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"]
|
VoiceId=segment["voice"]
|
||||||
)
|
)
|
||||||
audio_segments.append(response['AudioStream'].read())
|
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
|
# Combine the audio segments into a single audio file
|
||||||
combined_audio = b"".join(audio_segments)
|
combined_audio = b"".join(audio_segments)
|
||||||
# Save the combined audio to a single file
|
# Save the combined audio to a single file
|
||||||
|
|||||||
Reference in New Issue
Block a user