Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from streamlit_webrtc import webrtc_streamer, WebRtcMode, AudioProcessorBase
|
4 |
+
import av
|
5 |
+
|
6 |
+
chunk_file = "temp_audio_chunk.wav"
|
7 |
+
|
8 |
+
class AudioProcessor(AudioProcessorBase):
|
9 |
+
def recv_audio(self, frame: av.AudioFrame) -> av.AudioFrame:
|
10 |
+
audio = frame.to_ndarray()
|
11 |
+
with open(chunk_file, "wb") as f:
|
12 |
+
f.write(audio.tobytes())
|
13 |
+
return frame
|
14 |
+
|
15 |
+
def main():
|
16 |
+
st.title("🎤 Simple Voice Recorder with Streamlit WebRTC")
|
17 |
+
|
18 |
+
# WebRTC component for recording
|
19 |
+
webrtc_ctx = webrtc_streamer(
|
20 |
+
key="speech-to-text",
|
21 |
+
mode=WebRtcMode.SENDONLY,
|
22 |
+
audio_processor_factory=AudioProcessor
|
23 |
+
)
|
24 |
+
|
25 |
+
# Display file info when recorded
|
26 |
+
if os.path.exists(chunk_file):
|
27 |
+
st.success("✅ Audio recorded successfully!")
|
28 |
+
st.audio(chunk_file, format="audio/wav")
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
main()
|