Khoronus commited on
Commit
b02be6b
·
1 Parent(s): 628239f

First commit

Browse files
Files changed (3) hide show
  1. app.py +55 -0
  2. packages.txt +1 -0
  3. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import speech_recognition as sr
3
+
4
+ def speech_recognition():
5
+ """
6
+ Function to create a Streamlit application for real-time speech recognition.
7
+
8
+ This function uses the SpeechRecognition library to capture audio from the user's microphone
9
+ and convert it to text using a speech recognition engine.
10
+
11
+ The recognized text is displayed on the Streamlit application.
12
+
13
+ Returns:
14
+ - None
15
+ """
16
+
17
+ # Create a Streamlit application
18
+ st.title("Real-time Speech Recognition")
19
+
20
+ # Create a speech recognizer object
21
+ recognizer = sr.Recognizer()
22
+
23
+ # Create a microphone object
24
+ microphone = sr.Microphone()
25
+
26
+ # Start the microphone input
27
+ with microphone as source:
28
+ st.info("Listening...")
29
+
30
+ # Adjust microphone energy threshold to ambient noise for better recognition
31
+ recognizer.adjust_for_ambient_noise(source)
32
+
33
+ # Continuously listen for audio and convert it to text
34
+ while True:
35
+ try:
36
+ # Listen for audio input
37
+ audio = recognizer.listen(source)
38
+
39
+ # Recognize the audio and convert it to text
40
+ text = recognizer.recognize_google(audio)
41
+
42
+ # Display the recognized text on the Streamlit application
43
+ st.write("You said:", text)
44
+
45
+ except sr.UnknownValueError:
46
+ # If the speech recognizer could not understand the audio
47
+ st.warning("Could not understand audio")
48
+
49
+ except sr.RequestError as e:
50
+ # If there was an error with the speech recognition service
51
+ st.error(f"Error: {e}")
52
+
53
+ # Run the speech recognition function when the script is executed
54
+ if __name__ == "__main__":
55
+ speech_recognition()
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ requests
2
+ python-dotenv
3
+ transformers
4
+ streamlit
5
+ torch
6
+ datasets
7
+ IPython
8
+ torchaudio