Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import soundfile as sf
|
| 3 |
+
import tempfile
|
| 4 |
+
|
| 5 |
+
def save_audio_chunk_to_temp(audio):
|
| 6 |
+
if audio is None:
|
| 7 |
+
return "No audio received"
|
| 8 |
+
|
| 9 |
+
sample_rate, audio_data = audio
|
| 10 |
+
|
| 11 |
+
# Create a temporary file with .wav extension
|
| 12 |
+
temp_file = tempfile.NamedTemporaryFile(suffix=".wav", delete=False) # set delete=True to auto-delete
|
| 13 |
+
sf.write(temp_file.name, audio_data, sample_rate)
|
| 14 |
+
|
| 15 |
+
return f"Chunk saved to temporary file: {temp_file.name}"
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=save_audio_chunk_to_temp,
|
| 19 |
+
inputs=gr.Audio(source="microphone", streaming=True),
|
| 20 |
+
outputs="text",
|
| 21 |
+
live=True
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
iface.launch()
|