jarvis python code
Python hosting: Host, run, and code Python in the cloud!
I thought it would be cool to create a personal assistant in Python. If you are into movies you may have heard of Jarvis, an A.I. based character in the Iron Man films. In this tutorial we will create a robot.
In this tutorial you get started with coding your own Jarvis, the voice activated assistant in Iron Man. Jarvis is a voice assistant, similar to Apple’s Siri or Google Now. In this tutorial we use the power of the Python programming language and a text-to-speech service.
I’m going to be using Ubuntu Linux for this project but you should be able to use it in Windows or Mac as well. However, since there’s quite a bit of command line work required, I’d recommend doing this on a Linux machine.
The features I want to have are:
- Recognize spoken voice (Speech recognition)
- Answer in spoken voice (Text to speech)
- Answer simple commands
This is what you’ll create (watch the whole video, demo at the end):
Recognize spoken voice
Speech recognition can by done using the Python SpeechRecognition module. We make use of the Google Speech API because of it’s great quality.
Answer in spoken voice (Text To Speech)
Various APIs and programs are available for text to speech applications. Espeak and pyttsx work out of the box but sound very robotic. We decided to go with the Google Text To Speech API, gTTS.
Using it is as simple as:
The program below will answer spoken questions.
Leave a Reply:
How to compile and run that program
Download python from python.org and run with "python program.py"
hello! i am getting some error. Can you help me out . i googled it but couldnot find any solution..
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
Do you get this error with the top program or the bottom (complete) program? Are you using Ubuntu or another platform?
I found this which may be helpful: https://askubuntu.com/questions/608480/alsa-problems-with-python2-7-unable-to-open-slave
Im using a RaspberryPi with USB webcam. I try the 1st scrip to test the TTS and it works awesome, but when I try the complete program it gives me the above error.
I usually use the command in terminal: python [name].py but programs will not run if the filament has a space in it? What should I do?
Make sure the indention (4 spaces) is correct.
mine keeps coming up with an error saying ImportError: No module called 'speech_recognition'
OH! I didn't configure the microphone on my laptop!
last piece needs to be inside the with loop
hey Frank , i am run the above program .But i did not gat any error .
"[email protected]:~/Desktop# python3 jarvis.py
Hi Gokul, what can I do for you?"
and it cannot move to next step.!
what i do?
Verify that microphone input is processed by changing to:
If no microphone data is received, try changing your microphone settings or one of the other speech recognition APIs. A list of speech engines can be found on https://pypi.python.org/pypi/ SpeechRecognition
When I run the script,It shows,
Try another speech engine, maybe this one is not working. Sometimes the APIs change.
Here is the error I got, Frank. Any IDEA?
mpg321 is missing, install it to your system. If that doesn't solve all, change the speech engine too.
No problem. Ok. Thanks
In that try-except block, if i don't say something for a short period of time it says "Google Speech Recognition could not understand audio" and exits my program.(I am using the code to make a voice controlled bot. So after each command I need time to make bot move. Giving delay makes a fixed time for each order,so i don't want to use it.) Is there any way to control the time before the except block starts working??
Hi mate, I have downloaded gTTS, now what i want to do and where to save the both py files, whether it should get saved in separate file or in same file... And another doubt is you are saving that hello.mp3 what is that ?
That looks like another type of exception.
It may be another type of exception the try-catch block is getting.
Try adding these two exception handlers:
Let me know how that works out.
Save as different py files. The file hello.mp3 is the output file saved automatically. You'll also need to install the program mpg321.
Frank, I love the quality and execution of this program. I intend to build an interface to run some scientific equipment. I am not a programmer .... I generally hack my way through what I need to get the job done. I have written several basic programs to control the microscope.
This is a Windows 8.1 system. Is that an issue??
Installed the gTTS and SpeechRecognition. Having trouble getting PyAudio and PySpeech installed .... using python 3.3 and seems to need Visual C++ 10.0. Trying to work around that now. ....
When I try to run your example code (short version), I get a string of errors, the end of which oddly seems tied to a URL related to 'translate.google.com'.... if I interpret the error correctly.
I know it is a mess ...... any insights are appreciated!
BTW: It is tts.save that generates the error.
Thanks Edward! Windows 8.1 should not be an issue, at the time I had tested it on Ubuntu.
The gTTS module underneath uses the translate.google.com website, see inside the gtts source code. This website returns an audio file, which is played with any sound player (mpg321 as example).
In this case I see a connection error, do you have a firewall? It may also be throttling (too many connections). If you have an offline environment, try ms sapi or espeak. The speech recognition part also needs internet connection though.
How do you create an mp3 file from spoken via the Google TTS API?
If you just want an mp3, you can save the TTS output .save('hello.mp3'). If you want to save the spoken audio, you can do this:You can save as raw, wav, aiff and flac. For mp3, you may need to converse it using another module or it may have been added.
How do you install mpg321? Because I keep getting:
Instead of mpg321, try mpg123. You can install it with your package manager, but any audio player should do.
AssertionError: Audio source must be entered before listening, see documentation for ``AudioSource``; are you using ``source`` outside of a ``with`` statement?
PS C:\Users\BANKIM\OneDrive\Desktop\python program> c:; cd 'c:\Users\BANKIM\OneDrive\Desktop\python program'; & 'C:\Users\BANKIM\AppData\Local\Programs\Python\Python311\python.exe' 'c:\Users\BANKIM\.vscode\extensions\ms-python.python-2022.20.2\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '61547' '--' 'c:\Users\BANKIM\OneDrive\Desktop\python program\convert.py'
Hi, how to install pyaudio in android
pyaudio is not available for android, because it wraps PortAudio. PortAudio works on desktop platforms like Windows, Linux, Mac OS but not mobile
And can I change the STT language to Japanese?
Yes you can store returned data into a file, it is a Python string that you can write to a file like any other Python string. If the API allows it, you can change the language to Japanese
I tried to write your code but it doesn't seem to work for me, why am I getting this message? can you please help.
Try another speech recognition API, this one may be deprecated
Sir in my pc jarvis is using internet explorer as default browser how can i change it to chrome please suggest.
Change your default browser or run a custom command in the function, with the os.system function you can start any program