-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech.py
More file actions
20 lines (18 loc) · 778 Bytes
/
speech.py
File metadata and controls
20 lines (18 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import speech_recognition as sr
import win32com.client as wincl
speak = wincl.Dispatch("SAPI.SpVoice")
def getUserquery():
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
# recognize speech using Google Speech Recognition
try:
return r.recognize_google(audio)
except sr.UnknownValueError:
speak.Speak("Google Speech Recognition could not understand audio, Please type your query")
# print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
speak.Speak("Google Speech Recognition could not understand audio, Please type your query")
# print("Could not request results from Google Speech Recognition service; {0}".format(e))