🔥Data Scientist Masters Program (Discount Code - YTBE15) - www.simplilearn.com/big-data-and-analytics/senior-data-scientist-masters-program-training?PyDn2gU9DJo&Comments&UA-cam 🔥IITK - Professional Certificate Course in Data Science (India Only) - www.simplilearn.com/iitk-professional-certificate-course-data-science?PyDn2gU9DJo&Comments&UA-cam 🔥Caltech Post Graduate Program in Data Science - www.simplilearn.com/post-graduate-program-data-science?PyDn2gU9DJo&Comments&UA-cam 🔥Brown University - Applied AI & Data Science - www.simplilearn.com/applied-ai-data-science-course?PyDn2gU9DJo&Comments&UA-cam
hi,can u help me for one issue? actually the speech recognization is not happening.it is not taking input and also None output i am getting only. import speech_recognition as sr import pyttsx3 import pywhatkit import datetime import pyaudio r = sr.Recognizer() machine = pyttsx3.init() def talk(text): machine.say(text) machine.runAndWait() def input(): try: with sr.Microphone(device_index = 0) as origin: print("listening") print((sr.Microphone.list_microphone_names())) speech = r.listen(origin) instruction = r.recognize_goggle(speech) instruction.lower() if "jarvis" in instruction: instruction = instruction.replace('jarvis', "") print(instruction) except: pass
print(instruction) if instruction is not None and "play" in instruction: song=instruction.replace('play', "") talk("playing" + song) pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction: time = datetime.datetime.now().strftime('%I: %M%p ') talk('current time' + time)
Hi There seem to be a few issues in your code that might be causing the problem. Here are a few suggestions: 1. You should rename your input() function to something else, as input is already a built-in function in Python and you don't want to override it. 2. In the input() function, you're catching all exceptions with a try/except block, which means that you won't see any error messages if something goes wrong. Instead, try to catch specific exceptions so you can see what's happening. 3. There's a typo in the r.recognize_google() method, which should be r.recognize_google() instead of r.recognize_goggle() Here's a modified version of your code with these issues fixed: import speech_recognition as sr import pyttsx3 import pywhatkit import datetime r = sr.Recognizer() machine = pyttsx3.init() def talk(text): machine.say(text) machine.runAndWait() def get_instruction(): try: with sr.Microphone(device_index=0) as source: print("listening") print(sr.Microphone.list_microphone_names()) r.adjust_for_ambient_noise(source) audio = r.listen(source, timeout=5) instruction = r.recognize_google(audio) instruction = instruction.lower() if "jarvis" in instruction: instruction = instruction.replace('jarvis', "") print(instruction) return instruction except sr.WaitTimeoutError: print("Timeout waiting for speech input") except sr.UnknownValueError: print("Unable to recognize speech") except sr.RequestError as e: print("Error in request to speech recognition service; {0}".format(e)) def play_instruction(): instruction = get_instruction() print(instruction) if instruction is not None and "play" in instruction: song = instruction.replace('play', "") talk("playing " + song) pywhatkit.playonyt(song) elif instruction is not None and 'time' in instruction: time = datetime.datetime.now().strftime('%I:%M %p') talk('current time ' + time) play_instruction() This code should now listen for speech input, recognize it using Google's speech recognition service, and then carry out an action based on the recognized instruction.
Thank you for choosing us as your learning partner. We are thrilled to hear that you enjoyed your experience with us! If you are looking to expand your knowledge further, we invite you to explore our other courses in the description box.
I got the same error and has resolved it. In first line of "play_jarvis()" function, make sure you have put the brackets., like this: instruction = input_instruction()
Hey You can refer to the above suggestion or try with this: Hi You can try this one: import speech_recognition as sr import pyttsx3 import pywhatkit import datetime r = sr.Recognizer() machine = pyttsx3.init() def talk(text): machine.say(text) machine.runAndWait() def get_instruction(): try: with sr.Microphone(device_index=0) as source: print("Listening...") r.adjust_for_ambient_noise(source) speech = r.listen(source) instruction = r.recognize_google(speech) instruction = instruction.lower() if "jarvis" in instruction: instruction = instruction.replace('jarvis', "") print(instruction) return instruction except sr.UnknownValueError: pass except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) return None def play_instruction(): instruction = get_instruction() print(instruction) if instruction is not None and "play" in instruction: song = instruction.replace('play', "") talk("Playing " + song) pywhatkit.playonyt(song) elif instruction is not None and 'time' in instruction: time = datetime.datetime.now().strftime('%I:%M %p') talk('The current time is ' + time) play_instruction()
If you’re seeing the "pip is not recognized as an internal or external command" error, it means that pip is not installed or not added to your system’s PATH. Here’s how to fix it: Install pip: If you don’t have pip installed, you can download and install it from the official website: pip.pypa.io/en/stable/installation/. Add pip to PATH: Open the Control Panel and go to System and Security > System > Advanced system settings. Click on Environment Variables. In the System variables section, find the PATH variable and select it. Click Edit. Add the path to the Scripts folder where pip is installed. For example, C:\Python39\Scripts\ (adjust according to your Python installation path). Click OK to save and close all dialogs. Verify Installation: Open a new command prompt window and type pip --version to check if pip is now recognized. If these steps don’t resolve the issue, consider reinstalling Python and ensuring that you select the option to add Python to PATH during installation.
We're so glad that you enjoyed your time learning with us! If you're interested in continuing your education and developing new skills, take a look at our course offerings in the description box. We're confident that you'll find something that piques your interest!
If your pip installer needs to be updated, you can do so using the following command in your terminal or command prompt: pip install --upgrade pip This will update pip to the latest version. After updating pip, you can install the SpeechRecognition package by running: pip install SpeechRecognition
It is showing error of NoModuleFoundError : No Module named 'speech_recognition' . However i have already installed SpeechRecognition amd checked also ..i didnt find any solution of it
Hi If you've already installed the SpeechRecognition module but are still getting a ModuleNotFoundError, it's possible that the module was installed in a different Python environment than the one you're currently using. Here are a few things you can try to troubleshoot the issue: 1. Check which version of Python you're using: Make sure that you're running the correct version of Python (i.e., the one where you installed the SpeechRecognition module). You can check your Python version by running python --version in your terminal or command prompt. 2. Check the location of the installed module: You can check the location where the SpeechRecognition module is installed by running pip show speechrecognition in your terminal or command prompt. Make sure that the location matches the Python environment you're currently using. 3. Install the module again: Try uninstalling and reinstalling the SpeechRecognition module using pip uninstall speechrecognition and pip install speechrecognition in your terminal or command prompt. This will ensure that the module is installed in the correct Python environment. 4. Use a virtual environment: Consider using a virtual environment (such as venv or conda) to create a separate Python environment for your project. This can help ensure that the correct version of Python and the required modules are being used. I hope one of these suggestions helps you resolve the issue. Let me know if you have any further questions!
Hi You can try this one: import speech_recognition as sr import pyttsx3 import pywhatkit import datetime r = sr.Recognizer() machine = pyttsx3.init() def talk(text): machine.say(text) machine.runAndWait() def get_instruction(): try: with sr.Microphone(device_index=0) as source: print("Listening...") r.adjust_for_ambient_noise(source) speech = r.listen(source) instruction = r.recognize_google(speech) instruction = instruction.lower() if "jarvis" in instruction: instruction = instruction.replace('jarvis', "") print(instruction) return instruction except sr.UnknownValueError: pass except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) return None def play_instruction(): instruction = get_instruction() print(instruction) if instruction is not None and "play" in instruction: song = instruction.replace('play', "") talk("Playing " + song) pywhatkit.playonyt(song) elif instruction is not None and 'time' in instruction: time = datetime.datetime.now().strftime('%I:%M %p') talk('The current time is ' + time) play_instruction()
Bro error line 65 play_jarvis Error line 35 in play_jarvis instruction = input_instruction Error line 31 in input_instruction return instruction Pls help bro
Hi Based on the error message you provided, it seems that you are encountering an error in a Python program or script related to creating a virtual assistant. The specific error is occurring on line 65 of the play_jarvis function, which is being called from line 35 in the play_jarvis function. Furthermore, there is an error on line 31 within the input_instruction function, where it attempts to return the value of the instruction variable. To troubleshoot the issue, you can examine the code surrounding these lines and look for any syntax errors or potential issues with variable assignments or function calls. Additionally, check if the necessary modules or libraries are imported correctly. If you are looking to expand your knowledge further, we invite you to explore our other courses in the description box.
Hi You can try this one: import speech_recognition as sr import pyttsx3 import pywhatkit import datetime r = sr.Recognizer() machine = pyttsx3.init() def talk(text): machine.say(text) machine.runAndWait() def get_instruction(): try: with sr.Microphone(device_index=0) as source: print("Listening...") r.adjust_for_ambient_noise(source) speech = r.listen(source) instruction = r.recognize_google(speech) instruction = instruction.lower() if "jarvis" in instruction: instruction = instruction.replace('jarvis', "") print(instruction) return instruction except sr.UnknownValueError: pass except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) return None def play_instruction(): instruction = get_instruction() print(instruction) if instruction is not None and "play" in instruction: song = instruction.replace('play', "") talk("Playing " + song) pywhatkit.playonyt(song) elif instruction is not None and 'time' in instruction: time = datetime.datetime.now().strftime('%I:%M %p') talk('The current time is ' + time) play_instruction()
hi,can u help me for one issue? actually the speech recognization is not happening.it is not taking input and also None output i am getting only. import speech_recognition as sr import pyttsx3 import pywhatkit import datetime import pyaudio r = sr.Recognizer() machine = pyttsx3.init() def talk(text): machine.say(text) machine.runAndWait() def input(): try: with sr.Microphone(device_index = 0) as origin: print("listening") print((sr.Microphone.list_microphone_names())) speech = r.listen(origin) instruction = r.recognize_goggle(speech) instruction.lower() if "jarvis" in instruction: instruction = instruction.replace('jarvis', "") print(instruction) except: pass
print(instruction) if instruction is not None and "play" in instruction: song=instruction.replace('play', "") talk("playing" + song) pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction: time = datetime.datetime.now().strftime('%I: %M%p ') talk('current time' + time)
There seem to be a few issues with your code that might be causing the speech recognition to not work properly. 1. recognize_goggle should be recognize_google: The method for recognizing speech is called recognize_google (with one 'o'), not recognize_goggle. 2. input function is a built-in function in Python: You should avoid naming your own functions with the same name as a built-in function in Python. In this case, the input function you defined is hiding the built-in input function. 3. You are setting the value of instruction to None in the play_instruction function: In the play_instruction function, you are setting the value of instruction to None before checking if it is not None and executing some code. This means that the code inside the if block will never execute. You should remove the line instruction = None in the play_instruction function. Here is a modified version of your code that should work better: import speech_recognition as sr import pyttsx3 import pywhatkit import datetime r = sr.Recognizer() machine = pyttsx3.init() def talk(text): machine.say(text) machine.runAndWait() def get_instruction(): try: with sr.Microphone(device_index=0) as source: print("Listening...") r.adjust_for_ambient_noise(source) speech = r.listen(source) instruction = r.recognize_google(speech) instruction = instruction.lower() if "jarvis" in instruction: instruction = instruction.replace('jarvis', "") print(instruction) return instruction except sr.UnknownValueError: pass except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) return None def play_instruction(): instruction = get_instruction() print(instruction) if instruction is not None and "play" in instruction: song = instruction.replace('play', "") talk("Playing " + song) pywhatkit.playonyt(song) elif instruction is not None and 'time' in instruction: time = datetime.datetime.now().strftime('%I:%M %p') talk('The current time is ' + time) play_instruction() I hope this helps! Let me know if you have any further questions.
🔥Data Scientist Masters Program (Discount Code - YTBE15) - www.simplilearn.com/big-data-and-analytics/senior-data-scientist-masters-program-training?PyDn2gU9DJo&Comments&UA-cam
🔥IITK - Professional Certificate Course in Data Science (India Only) - www.simplilearn.com/iitk-professional-certificate-course-data-science?PyDn2gU9DJo&Comments&UA-cam
🔥Caltech Post Graduate Program in Data Science - www.simplilearn.com/post-graduate-program-data-science?PyDn2gU9DJo&Comments&UA-cam
🔥Brown University - Applied AI & Data Science - www.simplilearn.com/applied-ai-data-science-course?PyDn2gU9DJo&Comments&UA-cam
hi,can u help me for one issue?
actually the speech recognization is not happening.it is not taking input and also None output i am getting only.
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import pyaudio
r = sr.Recognizer()
machine = pyttsx3.init()
def talk(text):
machine.say(text)
machine.runAndWait()
def input():
try:
with sr.Microphone(device_index = 0) as origin:
print("listening")
print((sr.Microphone.list_microphone_names()))
speech = r.listen(origin)
instruction = r.recognize_goggle(speech)
instruction.lower()
if "jarvis" in instruction:
instruction = instruction.replace('jarvis', "")
print(instruction)
except:
pass
def play_instruction():
instruction = input()
instruction = None
print(instruction)
if instruction is not None and "play" in instruction:
song=instruction.replace('play', "")
talk("playing" + song)
pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction:
time = datetime.datetime.now().strftime('%I: %M%p ')
talk('current time' + time)
play_instruction()
how to import this code in a framework and create a completed application
Hi
There seem to be a few issues in your code that might be causing the problem. Here are a few suggestions:
1. You should rename your input() function to something else, as input is already a built-in function in Python and you don't want to override it.
2. In the input() function, you're catching all exceptions with a try/except block, which means that you won't see any error messages if something goes wrong. Instead, try to catch specific exceptions so you can see what's happening.
3. There's a typo in the r.recognize_google() method, which should be r.recognize_google() instead of r.recognize_goggle()
Here's a modified version of your code with these issues fixed:
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
r = sr.Recognizer()
machine = pyttsx3.init()
def talk(text):
machine.say(text)
machine.runAndWait()
def get_instruction():
try:
with sr.Microphone(device_index=0) as source:
print("listening")
print(sr.Microphone.list_microphone_names())
r.adjust_for_ambient_noise(source)
audio = r.listen(source, timeout=5)
instruction = r.recognize_google(audio)
instruction = instruction.lower()
if "jarvis" in instruction:
instruction = instruction.replace('jarvis', "")
print(instruction)
return instruction
except sr.WaitTimeoutError:
print("Timeout waiting for speech input")
except sr.UnknownValueError:
print("Unable to recognize speech")
except sr.RequestError as e:
print("Error in request to speech recognition service; {0}".format(e))
def play_instruction():
instruction = get_instruction()
print(instruction)
if instruction is not None and "play" in instruction:
song = instruction.replace('play', "")
talk("playing " + song)
pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('current time ' + time)
play_instruction()
This code should now listen for speech input, recognize it using Google's speech recognition service, and then carry out an action based on the recognized instruction.
Hii sir !!!. i am facing one error can u please help me. name 'instruction' is not defined. this is my error. please sir tell what should i do.
It is recognizing voice but it's not responding.? Can someone tell me how to fix it..?
I loved this exercise thank you so much! How could I change the voice? Thank you in advance for your time!
Thank you for choosing us as your learning partner. We are thrilled to hear that you enjoyed your experience with us! If you are looking to expand your knowledge further, we invite you to explore our other courses in the description box.
helpful but can be improved anywys thanks for video mate well done
Yo this helped so much and I always appreciate th
Hello thank you for watching our video .We are glad that we could help you in your learning !
when i play.. terminal showed...
"typeError: argument of type 'function' is not iterable"
I got the same error and has resolved it.
In first line of "play_jarvis()" function, make sure you have put the brackets., like this:
instruction = input_instruction()
Hey
You can refer to the above suggestion or try with this:
Hi
You can try this one:
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
r = sr.Recognizer()
machine = pyttsx3.init()
def talk(text):
machine.say(text)
machine.runAndWait()
def get_instruction():
try:
with sr.Microphone(device_index=0) as source:
print("Listening...")
r.adjust_for_ambient_noise(source)
speech = r.listen(source)
instruction = r.recognize_google(speech)
instruction = instruction.lower()
if "jarvis" in instruction:
instruction = instruction.replace('jarvis', "")
print(instruction)
return instruction
except sr.UnknownValueError:
pass
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
return None
def play_instruction():
instruction = get_instruction()
print(instruction)
if instruction is not None and "play" in instruction:
song = instruction.replace('play', "")
talk("Playing " + song)
pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('The current time is ' + time)
play_instruction()
Thank you so much❤
Best code. Thanks
Sir program run krne k baad output mw yee sb likha aa rha h "Exited code =9009 in 0.828 seconds meaning"
Thank you for the interesting session..
Our pleasure!
Thank you sir
Welcome
At start its showing pip is not recognized as internal or external comadn,...... What to do
If you’re seeing the "pip is not recognized as an internal or external command" error, it means that pip is not installed or not added to your system’s PATH. Here’s how to fix it:
Install pip:
If you don’t have pip installed, you can download and install it from the official website: pip.pypa.io/en/stable/installation/.
Add pip to PATH:
Open the Control Panel and go to System and Security > System > Advanced system settings.
Click on Environment Variables.
In the System variables section, find the PATH variable and select it. Click Edit.
Add the path to the Scripts folder where pip is installed. For example, C:\Python39\Scripts\ (adjust according to your Python installation path).
Click OK to save and close all dialogs.
Verify Installation:
Open a new command prompt window and type pip --version to check if pip is now recognized.
If these steps don’t resolve the issue, consider reinstalling Python and ensuring that you select the option to add Python to PATH during installation.
hi, i did the exact coding but still the assistant is answering only the "who is" question or either saying please repeat what can i do to fix it??
may i know how to open comand prompt
sir please what v.scode extemtion do i need for this
I am not receiving audio what should I do
Hi there, Please try to open this video in incognito window or you can use any other browser.
I wish Jarvis had replied in bacha party way for who is Mahatma Gandhi 🙂
We're so glad that you enjoyed your time learning with us! If you're interested in continuing your education and developing new skills, take a look at our course offerings in the description box. We're confident that you'll find something that piques your interest!
"we will respond to the stuffs if you have problem"
later: only responds to the comments thanking them for the tutorial
Hey, Thank you for choosing us as your learning partner. If you have any queries, please feel free to reach out in comment section.
Front end and backend for this project plzzz
Mine says I have to update my pip installer
If your pip installer needs to be updated, you can do so using the following command in your terminal or command prompt:
pip install --upgrade pip
This will update pip to the latest version. After updating pip, you can install the SpeechRecognition package by running:
pip install SpeechRecognition
My also error if module is installed
Hey, Thank you for choosing us as your learning partner. Please specify your error.
tensorflow i guess
Plzzz reply is this AI project or not
It is showing error of NoModuleFoundError : No Module named 'speech_recognition' . However i have already installed SpeechRecognition amd checked also ..i didnt find any solution of it
i am having the same problem, did you fix it?
Hi
If you've already installed the SpeechRecognition module but are still getting a ModuleNotFoundError, it's possible that the module was installed in a different Python environment than the one you're currently using.
Here are a few things you can try to troubleshoot the issue:
1. Check which version of Python you're using: Make sure that you're running the correct version of Python (i.e., the one where you installed the SpeechRecognition module). You can check your Python version by running python --version in your terminal or command prompt.
2. Check the location of the installed module: You can check the location where the SpeechRecognition module is installed by running pip show speechrecognition in your terminal or command prompt. Make sure that the location matches the Python environment you're currently using.
3. Install the module again: Try uninstalling and reinstalling the SpeechRecognition module using pip uninstall speechrecognition and pip install speechrecognition in your terminal or command prompt. This will ensure that the module is installed in the correct Python environment.
4. Use a virtual environment: Consider using a virtual environment (such as venv or conda) to create a separate Python environment for your project. This can help ensure that the correct version of Python and the required modules are being used.
I hope one of these suggestions helps you resolve the issue. Let me know if you have any further questions!
Tell about this error bhai
Hey, Thank you for choosing us as your learning partner. Please specify your error.
bro can u plzz provide source code
Hi
You can try this one:
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
r = sr.Recognizer()
machine = pyttsx3.init()
def talk(text):
machine.say(text)
machine.runAndWait()
def get_instruction():
try:
with sr.Microphone(device_index=0) as source:
print("Listening...")
r.adjust_for_ambient_noise(source)
speech = r.listen(source)
instruction = r.recognize_google(speech)
instruction = instruction.lower()
if "jarvis" in instruction:
instruction = instruction.replace('jarvis', "")
print(instruction)
return instruction
except sr.UnknownValueError:
pass
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
return None
def play_instruction():
instruction = get_instruction()
print(instruction)
if instruction is not None and "play" in instruction:
song = instruction.replace('play', "")
talk("Playing " + song)
pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('The current time is ' + time)
play_instruction()
Bro error line 65 play_jarvis
Error line 35 in play_jarvis instruction = input_instruction
Error line 31 in input_instruction return instruction
Pls help bro
Hi
Based on the error message you provided, it seems that you are encountering an error in a Python program or script related to creating a virtual assistant. The specific error is occurring on line 65 of the play_jarvis function, which is being called from line 35 in the play_jarvis function.
Furthermore, there is an error on line 31 within the input_instruction function, where it attempts to return the value of the instruction variable.
To troubleshoot the issue, you can examine the code surrounding these lines and look for any syntax errors or potential issues with variable assignments or function calls. Additionally, check if the necessary modules or libraries are imported correctly.
If you are looking to expand your knowledge further, we invite you to explore our other courses in the description box.
please send source code
the code is not running
Hi
You can try this one:
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
r = sr.Recognizer()
machine = pyttsx3.init()
def talk(text):
machine.say(text)
machine.runAndWait()
def get_instruction():
try:
with sr.Microphone(device_index=0) as source:
print("Listening...")
r.adjust_for_ambient_noise(source)
speech = r.listen(source)
instruction = r.recognize_google(speech)
instruction = instruction.lower()
if "jarvis" in instruction:
instruction = instruction.replace('jarvis', "")
print(instruction)
return instruction
except sr.UnknownValueError:
pass
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
return None
def play_instruction():
instruction = get_instruction()
print(instruction)
if instruction is not None and "play" in instruction:
song = instruction.replace('play', "")
talk("Playing " + song)
pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('The current time is ' + time)
play_instruction()
hi,can u help me for one issue?
actually the speech recognization is not happening.it is not taking input and also None output i am getting only.
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import pyaudio
r = sr.Recognizer()
machine = pyttsx3.init()
def talk(text):
machine.say(text)
machine.runAndWait()
def input():
try:
with sr.Microphone(device_index = 0) as origin:
print("listening")
print((sr.Microphone.list_microphone_names()))
speech = r.listen(origin)
instruction = r.recognize_goggle(speech)
instruction.lower()
if "jarvis" in instruction:
instruction = instruction.replace('jarvis', "")
print(instruction)
except:
pass
def play_instruction():
instruction = input()
instruction = None
print(instruction)
if instruction is not None and "play" in instruction:
song=instruction.replace('play', "")
talk("playing" + song)
pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction:
time = datetime.datetime.now().strftime('%I: %M%p ')
talk('current time' + time)
play_instruction()
Me too bro, The input and output are not speeches
There seem to be a few issues with your code that might be causing the speech recognition to not work properly.
1. recognize_goggle should be recognize_google: The method for recognizing speech is called recognize_google (with one 'o'), not recognize_goggle.
2. input function is a built-in function in Python: You should avoid naming your own functions with the same name as a built-in function in Python. In this case, the input function you defined is hiding the built-in input function.
3. You are setting the value of instruction to None in the play_instruction function: In the play_instruction function, you are setting the value of instruction to None before checking if it is not None and executing some code. This means that the code inside the if block will never execute. You should remove the line instruction = None in the play_instruction function.
Here is a modified version of your code that should work better:
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
r = sr.Recognizer()
machine = pyttsx3.init()
def talk(text):
machine.say(text)
machine.runAndWait()
def get_instruction():
try:
with sr.Microphone(device_index=0) as source:
print("Listening...")
r.adjust_for_ambient_noise(source)
speech = r.listen(source)
instruction = r.recognize_google(speech)
instruction = instruction.lower()
if "jarvis" in instruction:
instruction = instruction.replace('jarvis', "")
print(instruction)
return instruction
except sr.UnknownValueError:
pass
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
return None
def play_instruction():
instruction = get_instruction()
print(instruction)
if instruction is not None and "play" in instruction:
song = instruction.replace('play', "")
talk("Playing " + song)
pywhatkit.playonyt(song)
elif instruction is not None and 'time' in instruction:
time = datetime.datetime.now().strftime('%I:%M %p')
talk('The current time is ' + time)
play_instruction()
I hope this helps! Let me know if you have any further questions.