Spaces:
Sleeping
Sleeping
Commit ·
fc6d1e9
1
Parent(s): 9c71b94
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import soundfile as sf
|
| 4 |
from pydub import AudioSegment
|
|
|
|
| 5 |
|
| 6 |
def record_audio(audio):
|
| 7 |
# 获取音频文件路径
|
|
@@ -19,7 +20,7 @@ def record_audio(audio):
|
|
| 19 |
channels=1
|
| 20 |
)
|
| 21 |
audio_segment = audio_segment.set_frame_rate(16000)
|
| 22 |
-
audio_data = audio_segment.get_array_of_samples()
|
| 23 |
sample_rate = 16000
|
| 24 |
|
| 25 |
# 保存音频文件为 voice.wav
|
|
@@ -33,7 +34,7 @@ with gr.Blocks() as demo:
|
|
| 33 |
gr.Markdown("### 录音功能")
|
| 34 |
|
| 35 |
with gr.Row():
|
| 36 |
-
record_button = gr.Audio(label="录音")
|
| 37 |
submit_button = gr.Button("提交录音")
|
| 38 |
|
| 39 |
message = gr.Textbox(label="消息")
|
|
@@ -42,4 +43,4 @@ with gr.Blocks() as demo:
|
|
| 42 |
submit_button.click(record_audio, inputs=record_button, outputs=[message, record_button])
|
| 43 |
|
| 44 |
# 启动 Gradio 应用
|
| 45 |
-
demo.launch()
|
|
|
|
| 2 |
import os
|
| 3 |
import soundfile as sf
|
| 4 |
from pydub import AudioSegment
|
| 5 |
+
import numpy as np
|
| 6 |
|
| 7 |
def record_audio(audio):
|
| 8 |
# 获取音频文件路径
|
|
|
|
| 20 |
channels=1
|
| 21 |
)
|
| 22 |
audio_segment = audio_segment.set_frame_rate(16000)
|
| 23 |
+
audio_data = np.array(audio_segment.get_array_of_samples())
|
| 24 |
sample_rate = 16000
|
| 25 |
|
| 26 |
# 保存音频文件为 voice.wav
|
|
|
|
| 34 |
gr.Markdown("### 录音功能")
|
| 35 |
|
| 36 |
with gr.Row():
|
| 37 |
+
record_button = gr.Audio(label="录音", type="filepath")
|
| 38 |
submit_button = gr.Button("提交录音")
|
| 39 |
|
| 40 |
message = gr.Textbox(label="消息")
|
|
|
|
| 43 |
submit_button.click(record_audio, inputs=record_button, outputs=[message, record_button])
|
| 44 |
|
| 45 |
# 启动 Gradio 应用
|
| 46 |
+
demo.launch()
|