Spaces:
Sleeping
Sleeping
shahpalash10
commited on
Commit
•
24992c5
1
Parent(s):
a93b78a
Update app.py
Browse files
app.py
CHANGED
@@ -13,14 +13,17 @@ recognizer = sr.Recognizer()
|
|
13 |
# Create a Streamlit input element for microphone input
|
14 |
audio_input = st.empty()
|
15 |
|
|
|
|
|
|
|
|
|
16 |
# Check if the microphone input is requested
|
17 |
if st.checkbox("Use Microphone for English Input"):
|
18 |
with audio_input:
|
19 |
st.warning("Listening for audio input... Speak in English.")
|
20 |
try:
|
21 |
with sr.Microphone() as source:
|
22 |
-
#
|
23 |
-
p = pyaudio.PyAudio()
|
24 |
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
|
25 |
|
26 |
audio = b""
|
@@ -55,6 +58,7 @@ if st.checkbox("Use Microphone for English Input"):
|
|
55 |
st.warning("Speech recognition could not understand the audio.")
|
56 |
finally:
|
57 |
# Clean up audio resources
|
58 |
-
stream
|
59 |
-
|
|
|
60 |
p.terminate()
|
|
|
13 |
# Create a Streamlit input element for microphone input
|
14 |
audio_input = st.empty()
|
15 |
|
16 |
+
# Initialize PyAudio and stream variables
|
17 |
+
p = pyaudio.PyAudio()
|
18 |
+
stream = None
|
19 |
+
|
20 |
# Check if the microphone input is requested
|
21 |
if st.checkbox("Use Microphone for English Input"):
|
22 |
with audio_input:
|
23 |
st.warning("Listening for audio input... Speak in English.")
|
24 |
try:
|
25 |
with sr.Microphone() as source:
|
26 |
+
# Open the audio stream
|
|
|
27 |
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
|
28 |
|
29 |
audio = b""
|
|
|
58 |
st.warning("Speech recognition could not understand the audio.")
|
59 |
finally:
|
60 |
# Clean up audio resources
|
61 |
+
if stream:
|
62 |
+
stream.stop_stream()
|
63 |
+
stream.close()
|
64 |
p.terminate()
|