import os import streamlit as st from streamlit_webrtc import webrtc_streamer, WebRtcMode, AudioProcessorBase import av chunk_file = "temp_audio_chunk.wav" class AudioProcessor(AudioProcessorBase): def recv_audio(self, frame: av.AudioFrame) -> av.AudioFrame: audio = frame.to_ndarray() with open(chunk_file, "wb") as f: f.write(audio.tobytes()) return frame def main(): st.title("🎤 Simple Voice Recorder with Streamlit WebRTC") # WebRTC component for recording webrtc_ctx = webrtc_streamer( key="speech-to-text", mode=WebRtcMode.SENDONLY, audio_processor_factory=AudioProcessor ) # Display file info when recorded if os.path.exists(chunk_file): st.success("✅ Audio recorded successfully!") st.audio(chunk_file, format="audio/wav") if __name__ == "__main__": main()