Update app.py
Browse files
app.py
CHANGED
@@ -26,6 +26,7 @@ def generate_podcast_script(api_key, content, duration):
|
|
26 |
humor, and occasional off-topic chit-chat. Use speech fillers like um, ah,
|
27 |
yes, I see, Ok now. Vary the emotional tone.
|
28 |
Format the script as alternating lines of dialogue without speaker labels.
|
|
|
29 |
Do not use any special characters, markdown, or formatting. Only include the alternating dialogue lines.
|
30 |
Ensure the conversation flows naturally and stays relevant to the topic.
|
31 |
Limit the script length to match the requested duration of {duration}.
|
@@ -45,14 +46,13 @@ async def text_to_speech(text, voice):
|
|
45 |
return audio.read()
|
46 |
|
47 |
async def render_podcast(api_key, script, voice1, voice2):
|
48 |
-
lines = script.split('\n')
|
49 |
audio_segments = []
|
50 |
|
51 |
for i, line in enumerate(lines):
|
52 |
-
if
|
53 |
-
|
54 |
-
|
55 |
-
audio_segments.append(audio)
|
56 |
|
57 |
if not audio_segments:
|
58 |
logger.warning("No valid audio segments were generated.")
|
@@ -147,7 +147,8 @@ with gr.Blocks() as demo:
|
|
147 |
|
148 |
def update_voices(lang):
|
149 |
selected_lang = next((key for key, value in language_names.items() if value == lang), None)
|
150 |
-
|
|
|
151 |
|
152 |
lang1_select.change(update_voices, inputs=[lang1_select], outputs=[voice1_select])
|
153 |
lang2_select.change(update_voices, inputs=[lang2_select], outputs=[voice2_select])
|
|
|
26 |
humor, and occasional off-topic chit-chat. Use speech fillers like um, ah,
|
27 |
yes, I see, Ok now. Vary the emotional tone.
|
28 |
Format the script as alternating lines of dialogue without speaker labels.
|
29 |
+
Separate each line with a blank line.
|
30 |
Do not use any special characters, markdown, or formatting. Only include the alternating dialogue lines.
|
31 |
Ensure the conversation flows naturally and stays relevant to the topic.
|
32 |
Limit the script length to match the requested duration of {duration}.
|
|
|
46 |
return audio.read()
|
47 |
|
48 |
async def render_podcast(api_key, script, voice1, voice2):
|
49 |
+
lines = [line for line in script.split('\n') if line.strip()]
|
50 |
audio_segments = []
|
51 |
|
52 |
for i, line in enumerate(lines):
|
53 |
+
voice = voice1 if i % 2 == 0 else voice2
|
54 |
+
audio = await text_to_speech(line, voice)
|
55 |
+
audio_segments.append(audio)
|
|
|
56 |
|
57 |
if not audio_segments:
|
58 |
logger.warning("No valid audio segments were generated.")
|
|
|
147 |
|
148 |
def update_voices(lang):
|
149 |
selected_lang = next((key for key, value in language_names.items() if value == lang), None)
|
150 |
+
voices = voice_dict.get(selected_lang, [])
|
151 |
+
return gr.Dropdown(choices=voices, value=voices[0] if voices else None)
|
152 |
|
153 |
lang1_select.change(update_voices, inputs=[lang1_select], outputs=[voice1_select])
|
154 |
lang2_select.change(update_voices, inputs=[lang2_select], outputs=[voice2_select])
|