Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from datetime import datetime
|
|
| 6 |
def process_audio(sample_rate, audio_data):
|
| 7 |
"""Resample to 16kHz and save as .wav file"""
|
| 8 |
if audio_data is None:
|
| 9 |
-
return "No audio recorded"
|
| 10 |
|
| 11 |
target_sample_rate = 16000
|
| 12 |
|
|
@@ -27,7 +27,8 @@ def process_audio(sample_rate, audio_data):
|
|
| 27 |
audio_int16 = (audio_data * 32767).astype(np.int16)
|
| 28 |
wavfile.write(output_path, target_sample_rate, audio_int16)
|
| 29 |
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
gr.Markdown("# Voice Recorder")
|
|
@@ -36,11 +37,12 @@ with gr.Blocks() as demo:
|
|
| 36 |
audio_input = gr.Audio(sources=["microphone"], type="numpy")
|
| 37 |
record_btn = gr.Button("Record")
|
| 38 |
output_text = gr.Textbox(label="Status")
|
|
|
|
| 39 |
|
| 40 |
record_btn.click(
|
| 41 |
-
fn=lambda x: process_audio(16000, x) if x is not None else "No audio",
|
| 42 |
inputs=[audio_input],
|
| 43 |
-
outputs=[output_text]
|
| 44 |
)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
|
|
|
| 6 |
def process_audio(sample_rate, audio_data):
|
| 7 |
"""Resample to 16kHz and save as .wav file"""
|
| 8 |
if audio_data is None:
|
| 9 |
+
return "No audio recorded", None
|
| 10 |
|
| 11 |
target_sample_rate = 16000
|
| 12 |
|
|
|
|
| 27 |
audio_int16 = (audio_data * 32767).astype(np.int16)
|
| 28 |
wavfile.write(output_path, target_sample_rate, audio_int16)
|
| 29 |
|
| 30 |
+
status = f"Saved: {output_path} (16kHz, {len(audio_int16)/target_sample_rate:.2f}s)"
|
| 31 |
+
return status, output_path
|
| 32 |
|
| 33 |
with gr.Blocks() as demo:
|
| 34 |
gr.Markdown("# Voice Recorder")
|
|
|
|
| 37 |
audio_input = gr.Audio(sources=["microphone"], type="numpy")
|
| 38 |
record_btn = gr.Button("Record")
|
| 39 |
output_text = gr.Textbox(label="Status")
|
| 40 |
+
output_file = gr.File(label="Download Recording", visible=True)
|
| 41 |
|
| 42 |
record_btn.click(
|
| 43 |
+
fn=lambda x: process_audio(16000, x) if x is not None else ("No audio", None),
|
| 44 |
inputs=[audio_input],
|
| 45 |
+
outputs=[output_text, output_file]
|
| 46 |
)
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|