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