Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,8 @@ def save_audio(audio, label, sample_rate, bit_depth):
|
|
15 |
# 將錄音儲存為 wav 檔案
|
16 |
sf.write(filename, audio_data, int(sample_rate), subtype=f'PCM_{bit_depth}')
|
17 |
|
18 |
-
|
|
|
19 |
|
20 |
|
21 |
# 介面設計
|
@@ -23,12 +24,12 @@ def create_interface():
|
|
23 |
sample_rate = gr.Dropdown(["44100", "48000"], label="選擇採樣率", value="44100")
|
24 |
bit_depth = gr.Dropdown(["16", "24"], label="選擇位深度", value="16")
|
25 |
label = gr.Textbox(label="輸入標記")
|
26 |
-
audio = gr.Audio(sources="microphone", type="numpy", label="錄音"
|
27 |
|
28 |
interface = gr.Interface(
|
29 |
fn=save_audio,
|
30 |
inputs=[audio, label, sample_rate, bit_depth],
|
31 |
-
outputs=["text"],
|
32 |
title="錄音程式",
|
33 |
description="錄音最大長度為 1 秒,儲存為 WAV 格式。",
|
34 |
)
|
|
|
15 |
# 將錄音儲存為 wav 檔案
|
16 |
sf.write(filename, audio_data, int(sample_rate), subtype=f'PCM_{bit_depth}')
|
17 |
|
18 |
+
# 返回檔案名作為下載連結
|
19 |
+
return filename, gr.File(filename)
|
20 |
|
21 |
|
22 |
# 介面設計
|
|
|
24 |
sample_rate = gr.Dropdown(["44100", "48000"], label="選擇採樣率", value="44100")
|
25 |
bit_depth = gr.Dropdown(["16", "24"], label="選擇位深度", value="16")
|
26 |
label = gr.Textbox(label="輸入標記")
|
27 |
+
audio = gr.Audio(sources="microphone", type="numpy", label="錄音")
|
28 |
|
29 |
interface = gr.Interface(
|
30 |
fn=save_audio,
|
31 |
inputs=[audio, label, sample_rate, bit_depth],
|
32 |
+
outputs=["text", "file"],
|
33 |
title="錄音程式",
|
34 |
description="錄音最大長度為 1 秒,儲存為 WAV 格式。",
|
35 |
)
|