Spaces:
Sleeping
Sleeping
File size: 884 Bytes
f8bad2d |
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 26 27 28 29 30 31 32 |
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()
|