Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import wave
|
4 |
import numpy as np
|
|
|
5 |
import whisper
|
6 |
import os
|
7 |
import streamlit.components.v1 as components
|
@@ -37,27 +37,28 @@ record_audio = st.checkbox("Record Audio")
|
|
37 |
if record_audio:
|
38 |
audio_frames = []
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
42 |
|
43 |
-
st.
|
44 |
-
|
45 |
-
data = stream.read(1024)
|
46 |
-
audio_frames.append(data)
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
st.success("Recording stopped")
|
53 |
|
54 |
if audio_frames:
|
55 |
-
audio_data =
|
56 |
with wave.open("recorded_audio.wav", "wb") as wf:
|
57 |
wf.setnchannels(1)
|
58 |
wf.setsampwidth(2)
|
59 |
wf.setframerate(44100)
|
60 |
-
wf.writeframes(audio_data)
|
61 |
|
62 |
# Moved the submit_button check here
|
63 |
if 'submit_button' in st.session_state:
|
|
|
1 |
import streamlit as st
|
2 |
+
import sounddevice as sd
|
|
|
3 |
import numpy as np
|
4 |
+
import wave
|
5 |
import whisper
|
6 |
import os
|
7 |
import streamlit.components.v1 as components
|
|
|
37 |
if record_audio:
|
38 |
audio_frames = []
|
39 |
|
40 |
+
def audio_callback(indata, frames, time, status):
|
41 |
+
if status:
|
42 |
+
print(status, flush=True)
|
43 |
+
if any(indata):
|
44 |
+
audio_frames.append(indata.copy())
|
45 |
|
46 |
+
if st.button("Stop Recording"):
|
47 |
+
sd.stop()
|
|
|
|
|
48 |
|
49 |
+
with st.spinner("Recording..."):
|
50 |
+
with sd.InputStream(callback=audio_callback):
|
51 |
+
st.text("Recording audio. Click 'Stop Recording' when finished.")
|
52 |
|
53 |
st.success("Recording stopped")
|
54 |
|
55 |
if audio_frames:
|
56 |
+
audio_data = np.concatenate(audio_frames, axis=0)
|
57 |
with wave.open("recorded_audio.wav", "wb") as wf:
|
58 |
wf.setnchannels(1)
|
59 |
wf.setsampwidth(2)
|
60 |
wf.setframerate(44100)
|
61 |
+
wf.writeframes(audio_data.tobytes())
|
62 |
|
63 |
# Moved the submit_button check here
|
64 |
if 'submit_button' in st.session_state:
|