Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.45k stars 2.4k forks source link

Python voice recognize error #552

Open krishanchanakas opened 3 years ago

krishanchanakas commented 3 years ago

Guys, I try to many ways to solve this problem my code:

import speech_recognition as sr import pyttsx3 import pywhatkit

listener = sr.Recognizer() microphone = sr.Microphone() r = sr.Recognizer() my_mic = sr.Microphone(device_index=1)

engine = pyttsx3.init() voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id) # use whatever voice_id you'd like

def talk(): engine.say('Hello Iam vino how can I help you') engine.runAndWait()

def take_command():

try:
    with microphone as source:
        print('listening....')
        voice = r.listen(source)
        command = listener.recognize_google(voice, language='en-US')
        command = command.lower()
        if 'alexa' in command:
            command = voice.replace('alexa', ' ')
            print(command)
        else:
            print('error')
except LookupError:
    #print('Could not understand the audio')
    pass
return command

def run_alexa(): command = take_command() print(command) if 'play' in command: song = command.replace('play', '') talk('playing ' + song) pywhatkit.playonyt(song)

run_alexa()

============ error message

ommand = listener.recognize_google(voice, language='en-US') AttributeError: 'Recognizer' object has no attribute 'recognize_google'

D-Kamunya commented 3 years ago

Try replacing >> command = listener.recognize_google(voice, language='en-US') with >> command = r.recognize_google(voice, language='en-US')