-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da0c2ee
commit 439a221
Showing
4 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import speech_recognition as sr | ||
|
||
class SpeechRecognition(): | ||
def __init__(self): | ||
self.r = sr.Recognizer() | ||
self.m = sr.Microphone() | ||
|
||
def listen(self): | ||
try: | ||
with self.m as source: self.r.adjust_for_ambient_noise(source) | ||
with self.m as source: self.audio = self.r.listen(source) | ||
message = self.r.recognize_google(self.audio) | ||
print("Google Speech Recognition thinks you said " + message) | ||
return message | ||
m.__exit__() | ||
r.__exit__() | ||
except sr.UnknownValueError: | ||
#print("Google Speech Recognition could not understand audio") | ||
return '' | ||
except sr.RequestError as e: | ||
#print("Could not request results from Google Speech Recognition service; {0}".format(e)) | ||
return '' |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters