rahgadda commited on
Commit
7d07aea
·
verified ·
1 Parent(s): 0d33f85

Initial Draft

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import speech_recognition as sr
3
+ from streaming_stt_nemo import Model
4
+
5
+ if "sv_load_flash-attn" not in st.session_state:
6
+ subprocess.run(
7
+ "pip install flash-attn --no-build-isolation",
8
+ env={"FLASH_ATTENTION_SKIP_CUDA_BUILD": "TRUE"},
9
+ shell=True,
10
+ )
11
+ st.session_state.sv_load_flash-attn = True
12
+
13
+ def main():
14
+ st.title("Speech to Text Converter")
15
+
16
+ # Create a recognizer object
17
+ r = sr.Recognizer()
18
+
19
+ # Create a microphone object
20
+ mic = sr.Microphone()
21
+
22
+ # Continuously listen for audio input
23
+ with mic as source:
24
+ st.write("Listening...")
25
+ while True:
26
+ try:
27
+ # Adjust the ambient noise threshold for better results
28
+ r.adjust_for_ambient_noise(source)
29
+
30
+ # Listen for audio input
31
+ audio = r.listen(source)
32
+
33
+ # Convert audio to text
34
+ default_lang = "en"
35
+ engines = {
36
+ default_lang: Model(default_lang)
37
+ }
38
+ model = engines[default_lang]
39
+ text = model.stt_file(audio)[0]
40
+
41
+ # Display the converted text
42
+ st.write("You said:", text)
43
+
44
+ except sr.UnknownValueError:
45
+ pass
46
+
47
+ if __name__ == "__main__":
48
+ main()