Answers for "How to make speech recognition in Python faster"

0

how to fix speech recognition in python

import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:                # use the default microphone as the audio source
    audio = r.listen(source)                   # listen for the first phrase and extract it into audio data

try:
    print("You said " + r.recognize(audio))    # recognize speech using Google Speech Recognition
except LookupError:                           # speech is unintelligible
    print("Could not understand audio")
Posted by: Guest on May-05-2020
0

how to make a voice unlock system in python

# ctypes module to load windows library
import ctypes
# speech recognition module
import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

# recognize speech using Google Speech Recognition
try:
    # Here we are using default API which comes with the speech recognition module and is in built
    # If you want to use your own API key please use this code `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
    # instead of `r.recognize_google(audio)`
    cmd=r.recognize_google(audio)
    # handle the exceptions
except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))

# Match and compare the pattern of the voice command. You can change it yours.
if cmd=="lock my PC":
	# Load and execute the command to lock the PC. This function is available in default library (user32.dll) of windows
    ctypes.windll.user32.LockWorkStation()
Posted by: Guest on October-08-2020

Code answers related to "How to make speech recognition in Python faster"

Python Answers by Framework

Browse Popular Code Answers by Language