Update app.py
Browse files
app.py
CHANGED
|
@@ -87,6 +87,7 @@ def render_paragraphs(paragraphs):
|
|
| 87 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 88 |
gr.Markdown("## 🎙️ Edge TTS 語音合成與播客製作\n\n- 多段腳本自由增減、內容可清空\n- 介面直覺、操作友善、檔案自動管理")
|
| 89 |
|
|
|
|
| 90 |
with gr.Tab("語音合成"):
|
| 91 |
with gr.Row():
|
| 92 |
text_input = gr.Textbox(lines=5, label="輸入文本")
|
|
@@ -103,29 +104,32 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 103 |
)
|
| 104 |
clear_btn.click(fn=clear_textbox, outputs=text_input)
|
| 105 |
|
|
|
|
| 106 |
with gr.Tab("檢視已儲存語音"):
|
| 107 |
audio_files = gr.Dropdown(list_saved_audios(), label="選擇已儲存語音檔案", interactive=True)
|
| 108 |
saved_audio_output = gr.Audio(type="filepath", label="播放已儲存語音")
|
| 109 |
audio_files.change(fn=play_saved_audio, inputs=audio_files, outputs=saved_audio_output)
|
| 110 |
|
|
|
|
| 111 |
with gr.Tab("播客製作"):
|
| 112 |
gr.Markdown("### 📝 多段腳本輸入(可自由增減段落)")
|
| 113 |
paragraphs_state = gr.State([""])
|
| 114 |
|
| 115 |
# 用 gr.Column 重新渲染段落
|
| 116 |
paragraph_column = gr.Column()
|
| 117 |
-
|
| 118 |
# 初始化段落
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
paragraph_column.children = render_paragraphs([""])
|
| 124 |
|
| 125 |
add_btn = gr.Button("新增段落")
|
| 126 |
remove_btn = gr.Button("刪除段落")
|
| 127 |
clear_all_btn = gr.Button("全部清空")
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
add_btn.click(
|
| 130 |
lambda p: (add_paragraph(p), update_paragraph_ui(add_paragraph(p))),
|
| 131 |
inputs=paragraphs_state,
|
|
@@ -161,15 +165,17 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 161 |
desc = args[n+5]
|
| 162 |
return asyncio.run(podcast_produce(scripts, voice, rate, pitch, bgm, title, desc))
|
| 163 |
|
|
|
|
| 164 |
def get_inputs():
|
| 165 |
-
return
|
| 166 |
|
| 167 |
podcast_btn.click(
|
| 168 |
fn=on_podcast_btn_click,
|
| 169 |
-
inputs=get_inputs,
|
| 170 |
outputs=podcast_output
|
| 171 |
)
|
| 172 |
|
|
|
|
| 173 |
with gr.Tab("檢視已儲存播客"):
|
| 174 |
podcast_files = gr.Dropdown(list_saved_podcasts(), label="選擇已儲存播客檔案", interactive=True)
|
| 175 |
saved_podcast_output = gr.Audio(type="filepath", label="播放已儲存播客")
|
|
|
|
| 87 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 88 |
gr.Markdown("## 🎙️ Edge TTS 語音合成與播客製作\n\n- 多段腳本自由增減、內容可清空\n- 介面直覺、操作友善、檔案自動管理")
|
| 89 |
|
| 90 |
+
# 語音合成分頁
|
| 91 |
with gr.Tab("語音合成"):
|
| 92 |
with gr.Row():
|
| 93 |
text_input = gr.Textbox(lines=5, label="輸入文本")
|
|
|
|
| 104 |
)
|
| 105 |
clear_btn.click(fn=clear_textbox, outputs=text_input)
|
| 106 |
|
| 107 |
+
# 已存語音分頁
|
| 108 |
with gr.Tab("檢視已儲存語音"):
|
| 109 |
audio_files = gr.Dropdown(list_saved_audios(), label="選擇已儲存語音檔案", interactive=True)
|
| 110 |
saved_audio_output = gr.Audio(type="filepath", label="播放已儲存語音")
|
| 111 |
audio_files.change(fn=play_saved_audio, inputs=audio_files, outputs=saved_audio_output)
|
| 112 |
|
| 113 |
+
# 播客製作分頁
|
| 114 |
with gr.Tab("播客製作"):
|
| 115 |
gr.Markdown("### 📝 多段腳本輸入(可自由增減段落)")
|
| 116 |
paragraphs_state = gr.State([""])
|
| 117 |
|
| 118 |
# 用 gr.Column 重新渲染段落
|
| 119 |
paragraph_column = gr.Column()
|
|
|
|
| 120 |
# 初始化段落
|
| 121 |
+
paragraph_boxes = render_paragraphs([""])
|
| 122 |
+
for tb in paragraph_boxes:
|
| 123 |
+
paragraph_column.children += (tb,)
|
|
|
|
|
|
|
| 124 |
|
| 125 |
add_btn = gr.Button("新增段落")
|
| 126 |
remove_btn = gr.Button("刪除段落")
|
| 127 |
clear_all_btn = gr.Button("全部清空")
|
| 128 |
|
| 129 |
+
def update_paragraph_ui(paragraphs):
|
| 130 |
+
paragraph_column.children = tuple(render_paragraphs(paragraphs))
|
| 131 |
+
return gr.update()
|
| 132 |
+
|
| 133 |
add_btn.click(
|
| 134 |
lambda p: (add_paragraph(p), update_paragraph_ui(add_paragraph(p))),
|
| 135 |
inputs=paragraphs_state,
|
|
|
|
| 165 |
desc = args[n+5]
|
| 166 |
return asyncio.run(podcast_produce(scripts, voice, rate, pitch, bgm, title, desc))
|
| 167 |
|
| 168 |
+
# 收集 paragraph_column.children 作為 inputs
|
| 169 |
def get_inputs():
|
| 170 |
+
return list(paragraph_column.children) + [voice_input2, rate_input2, pitch_input2, bgm_input, podcast_title, podcast_desc]
|
| 171 |
|
| 172 |
podcast_btn.click(
|
| 173 |
fn=on_podcast_btn_click,
|
| 174 |
+
inputs=get_inputs(),
|
| 175 |
outputs=podcast_output
|
| 176 |
)
|
| 177 |
|
| 178 |
+
# 已存播客分頁
|
| 179 |
with gr.Tab("檢視已儲存播客"):
|
| 180 |
podcast_files = gr.Dropdown(list_saved_podcasts(), label="選擇已儲存播客檔案", interactive=True)
|
| 181 |
saved_podcast_output = gr.Audio(type="filepath", label="播放已儲存播客")
|