Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import numpy as np
|
4 |
import wave
|
|
|
5 |
import whisper
|
6 |
import os
|
7 |
import streamlit.components.v1 as components
|
@@ -37,28 +37,27 @@ record_audio = st.checkbox("Record Audio")
|
|
37 |
if record_audio:
|
38 |
audio_frames = []
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
print(status, flush=True)
|
43 |
-
if any(indata):
|
44 |
-
audio_frames.append(indata.copy())
|
45 |
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
st.success("Recording stopped")
|
54 |
|
55 |
if audio_frames:
|
56 |
-
audio_data =
|
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
|
62 |
|
63 |
# Moved the submit_button check here
|
64 |
if 'submit_button' in st.session_state:
|
|
|
1 |
import streamlit as st
|
2 |
+
import pyaudio
|
|
|
3 |
import wave
|
4 |
+
import numpy as np
|
5 |
import whisper
|
6 |
import os
|
7 |
import streamlit.components.v1 as components
|
|
|
37 |
if record_audio:
|
38 |
audio_frames = []
|
39 |
|
40 |
+
p = pyaudio.PyAudio()
|
41 |
+
stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
|
|
|
|
|
|
|
42 |
|
43 |
+
st.text("Recording audio. Click 'Stop Recording' when finished.")
|
44 |
+
while st.button("Stop Recording"):
|
45 |
+
data = stream.read(1024)
|
46 |
+
audio_frames.append(data)
|
47 |
|
48 |
+
stream.stop_stream()
|
49 |
+
stream.close()
|
50 |
+
p.terminate()
|
51 |
|
52 |
st.success("Recording stopped")
|
53 |
|
54 |
if audio_frames:
|
55 |
+
audio_data = b''.join(audio_frames)
|
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:
|