Skip to content

Instantly share code, notes, and snippets.

@zakirangwala
Last active September 23, 2020 13:06
Show Gist options
  • Save zakirangwala/61a24022dffda8ef124d545b61103d52 to your computer and use it in GitHub Desktop.
Save zakirangwala/61a24022dffda8ef124d545b61103d52 to your computer and use it in GitHub Desktop.
Tutorial code : Listen Function
import speech_recognition as sr
# Listen to user input
def listen():
r = sr.Recognizer()
with sr.Microphone() as source:
speak("I'm Listening")
print("Listening...")
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
try:
print("Recognizing...")
speak('Recognizing')
query = r.recognize_google(audio, language='en-CA')
print("User said: {}".format(query))
except sr.UnknownValueError:
print("I cannot hear you")
speak("I cannot hear you")
except sr.RequestError:
print("Say that again please")
speak("Say that again please")
return "None"
return query
@kreezxil
Copy link

are you working on speech recognition for Linux? if so I'm highly interested.

@zakirangwala
Copy link
Author

Creating a Virtual Assistant, that I will be running on my raspberry pi.

@kreezxil
Copy link

kreezxil commented Sep 23, 2020 via email

@zakirangwala
Copy link
Author

I will be running the python script on a RaspberryPi OS Lite equipped Raspberry Pi Zero W

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment