File tree 3 files changed +59
-0
lines changed
3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Script Title
2
+ A program that allows the user to convert the speech he/she inputs into the program into a text as well as the audio that is played in real time.
3
+
4
+ ### Prerequisites
5
+ speech_recognition, pyttsx3 and pyaudio libraries are required for this code.
6
+
7
+ To install speech_recognition: pip install SpeechRecognition
8
+ To install pyttsx3: pip install pyttsx3
9
+ To install pyaudio: pip install pyaudio
10
+
11
+ ### How to run the script
12
+ Just run the python file
13
+
14
+ ### Screenshot/GIF showing the sample use of the script
15
+ output.png
16
+
17
+ ## * Author Name*
18
+ ChiragNarvekar
Original file line number Diff line number Diff line change
1
+ import speech_recognition as sr
2
+ import pyttsx3
3
+
4
+ # Initializing the recognizer
5
+ r = sr .Recognizer ()
6
+
7
+ # Function to convert text to speech
8
+ def SpeakText (command ):
9
+ # Initializing the engine
10
+ engine = pyttsx3 .init ()
11
+ engine .say (command )
12
+ engine .runAndWait ()
13
+
14
+
15
+ # Looping infinitely for user to speak
16
+
17
+ while (1 ):
18
+ # Exception handling to handle exceptions at the runtime
19
+ try :
20
+ # using the microphone as source for input.
21
+ with sr .Microphone () as source2 :
22
+ # wait for a second to let the recognizer
23
+ # adjust the energy threshold based on
24
+ # the surrounding noise level
25
+ r .adjust_for_ambient_noise (source2 , duration = 0.2 )
26
+
27
+ #listens for the user's input
28
+ audio2 = r .listen (source2 )
29
+
30
+ # Using google to recognize audio
31
+ MyText = r .recognize_google (audio2 )
32
+ MyText = MyText .lower ()
33
+ enable_automatic_punctuation = True
34
+ print (MyText )
35
+ SpeakText (MyText )
36
+
37
+ except sr .RequestError as e :
38
+ print ("Could not request results; {0}" .format (e ))
39
+
40
+ except sr .UnknownValueError :
41
+ print ("unknown error occurred" )
You can’t perform that action at this time.
0 commit comments