Open krishanchanakas opened 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'
Try replacing >> command = listener.recognize_google(voice, language='en-US') with >> command = r.recognize_google(voice, language='en-US')
command = listener.recognize_google(voice, language='en-US')
command = r.recognize_google(voice, language='en-US')
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():
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'