Spaces:
Sleeping
Sleeping
| 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() | |