Patrick changed the structure #10
1 changed files with 32 additions and 0 deletions
|
@ -1 +1,33 @@
|
||||||
|
import speech_recognition as sr
|
||||||
|
|
||||||
|
|
||||||
|
class Voice:
|
||||||
|
@staticmethod
|
||||||
|
def listen():
|
||||||
|
recognizer = sr.Recognizer()
|
||||||
|
|
||||||
|
try:
|
||||||
|
recognizer = sr.Recognizer()
|
||||||
|
with sr.Microphone() as source:
|
||||||
|
print("Adjusting for ambient noise...")
|
||||||
|
recognizer.adjust_for_ambient_noise(source)
|
||||||
|
print("Listening...")
|
||||||
|
audio_data = recognizer.listen(source)
|
||||||
|
print("Audio captured")
|
||||||
|
try:
|
||||||
|
text = recognizer.recognize_sphinx(audio_data) # Using Google Web Speech API
|
||||||
|
except sr.UnknownValueError:
|
||||||
|
text = "ERROR"
|
||||||
|
except sr.RequestError as e:
|
||||||
|
text = "ERROR"
|
||||||
|
|
||||||
|
except sr.RequestError as e:
|
||||||
|
text = "ERROR"
|
||||||
|
except sr.UnknownValueError:
|
||||||
|
text = "ERROR"
|
||||||
|
except Exception as e:
|
||||||
|
text = "ERROR"
|
||||||
|
return text
|
||||||
|
print(listen())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue