Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import numpy as np
|
|
4 |
import edge_tts
|
5 |
import asyncio
|
6 |
import io
|
|
|
7 |
|
8 |
# Set up logging
|
9 |
import logging
|
@@ -22,15 +23,18 @@ def generate_podcast_script(api_key, content, duration):
|
|
22 |
{content}
|
23 |
|
24 |
The podcast should last approximately {duration}. Include natural speech patterns,
|
25 |
-
humor, and occasional off-topic chit-chat. Use speech fillers like
|
26 |
-
|
27 |
|
28 |
Format the script as alternating lines of dialogue without speaker labels.
|
29 |
-
Do not
|
30 |
Ensure the conversation flows naturally and stays relevant to the topic.
|
|
|
31 |
"""
|
32 |
response = model.generate_content(prompt)
|
33 |
-
|
|
|
|
|
34 |
|
35 |
async def text_to_speech(text, voice):
|
36 |
communicate = edge_tts.Communicate(text, voice)
|
@@ -65,7 +69,13 @@ async def render_podcast(api_key, script, voice1, voice2):
|
|
65 |
|
66 |
async def get_voice_list():
|
67 |
voices = await edge_tts.list_voices()
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# Gradio Interface
|
71 |
with gr.Blocks() as demo:
|
@@ -79,11 +89,28 @@ with gr.Blocks() as demo:
|
|
79 |
|
80 |
duration = gr.Radio(["1-5 min", "5-10 min", "10-15 min"], label="Estimated podcast duration")
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
with gr.Row():
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
87 |
|
88 |
generate_btn = gr.Button("Generate Script")
|
89 |
script_output = gr.Textbox(label="Generated Script", lines=10)
|
@@ -91,6 +118,13 @@ with gr.Blocks() as demo:
|
|
91 |
render_btn = gr.Button("Render Podcast")
|
92 |
audio_output = gr.Audio(label="Generated Podcast")
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
def generate_script_wrapper(api_key, content, duration):
|
95 |
return generate_podcast_script(api_key, content, duration)
|
96 |
|
|
|
4 |
import edge_tts
|
5 |
import asyncio
|
6 |
import io
|
7 |
+
import re
|
8 |
|
9 |
# Set up logging
|
10 |
import logging
|
|
|
23 |
{content}
|
24 |
|
25 |
The podcast should last approximately {duration}. Include natural speech patterns,
|
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 |
|
29 |
Format the script as alternating lines of dialogue without speaker labels.
|
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}.
|
33 |
"""
|
34 |
response = model.generate_content(prompt)
|
35 |
+
# Remove any special characters that might be read aloud
|
36 |
+
clean_text = re.sub(r'[^a-zA-Z0-9\s.,?!]', '', response.text)
|
37 |
+
return clean_text
|
38 |
|
39 |
async def text_to_speech(text, voice):
|
40 |
communicate = edge_tts.Communicate(text, voice)
|
|
|
69 |
|
70 |
async def get_voice_list():
|
71 |
voices = await edge_tts.list_voices()
|
72 |
+
voice_dict = {}
|
73 |
+
for voice in voices:
|
74 |
+
lang = voice["Locale"].split("-")[0]
|
75 |
+
if lang not in voice_dict:
|
76 |
+
voice_dict[lang] = []
|
77 |
+
voice_dict[lang].append(voice["Name"])
|
78 |
+
return voice_dict
|
79 |
|
80 |
# Gradio Interface
|
81 |
with gr.Blocks() as demo:
|
|
|
89 |
|
90 |
duration = gr.Radio(["1-5 min", "5-10 min", "10-15 min"], label="Estimated podcast duration")
|
91 |
|
92 |
+
voice_dict = asyncio.run(get_voice_list())
|
93 |
+
languages = list(voice_dict.keys())
|
94 |
+
language_names = {
|
95 |
+
'en': 'English',
|
96 |
+
'es': 'Spanish',
|
97 |
+
'fr': 'French',
|
98 |
+
'de': 'German',
|
99 |
+
'it': 'Italian',
|
100 |
+
'ja': 'Japanese',
|
101 |
+
'ko': 'Korean',
|
102 |
+
'pt': 'Portuguese',
|
103 |
+
'ru': 'Russian',
|
104 |
+
'zh': 'Chinese'
|
105 |
+
}
|
106 |
|
107 |
with gr.Row():
|
108 |
+
lang1_select = gr.Dropdown(label="Select Language 1", choices=[f"{language_names.get(lang, lang)} ({lang})" for lang in languages])
|
109 |
+
voice1_select = gr.Dropdown(label="Select Voice 1")
|
110 |
+
|
111 |
+
with gr.Row():
|
112 |
+
lang2_select = gr.Dropdown(label="Select Language 2", choices=[f"{language_names.get(lang, lang)} ({lang})" for lang in languages])
|
113 |
+
voice2_select = gr.Dropdown(label="Select Voice 2")
|
114 |
|
115 |
generate_btn = gr.Button("Generate Script")
|
116 |
script_output = gr.Textbox(label="Generated Script", lines=10)
|
|
|
118 |
render_btn = gr.Button("Render Podcast")
|
119 |
audio_output = gr.Audio(label="Generated Podcast")
|
120 |
|
121 |
+
def update_voices(lang):
|
122 |
+
lang_code = lang.split('(')[-1].strip(')')
|
123 |
+
return gr.Dropdown.update(choices=voice_dict[lang_code])
|
124 |
+
|
125 |
+
lang1_select.change(update_voices, inputs=[lang1_select], outputs=[voice1_select])
|
126 |
+
lang2_select.change(update_voices, inputs=[lang2_select], outputs=[voice2_select])
|
127 |
+
|
128 |
def generate_script_wrapper(api_key, content, duration):
|
129 |
return generate_podcast_script(api_key, content, duration)
|
130 |
|