-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmic.py
22 lines (18 loc) · 853 Bytes
/
mic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
# NOTE: this example requires PyAudio because it uses the Microphone class
import speech_recognition as sr
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Calibrando... Silencio!")
r.adjust_for_ambient_noise(source)
print("Say something!")
audio = r.listen(source)
# recognize speech using Microsoft Bing Voice Recognition
BING_KEY = "" # Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
try:
print("Microsoft Bing Voice Recognition thinks you said " + r.recognize_bing(audio, key=BING_KEY))
except sr.UnknownValueError:
print("Microsoft Bing Voice Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))