I am trying to test the personal assistant from here: https://pythonspot.com/en/personal-assistant-jarvis-in-python/
I am certain I have all modules and libraries etc. installed (took like 20 mins to set up!)
Issue is that when I run it, it does say "Hi Frank what can do for you?" but then it throws this error:
/usr/bin/python3.5 /home/me/PycharmProjects/PersonalAssistant/PersonalAssistant.py
Hi Frank, what can I do for you?
/home/me/.local/lib/python3.5/site-packages/urllib3/connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
tcgetattr(): Inappropriate ioctl for device
Playing MPEG stream from audio.mp3 ...
MPEG 2.0 layer III, 32 kbit/s, 24000 Hz mono
[0:02] Decoding of audio.mp3 finished.
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
Say something!
Traceback (most recent call last):
File "/home/me/PycharmProjects/PersonalAssistant/PersonalAssistant.py", line 58, in <module>
data = recordAudio()
File "/home/me/PycharmProjects/PersonalAssistant/PersonalAssistant.py", line 23, in recordAudio
audio = r.listen(source)
File "/home/me/.local/lib/python3.5/site-packages/speech_recognition/__init__.py", line 437, in listen
assert source.stream is not None, "Audio source must be opened before recording - see documentation for `AudioSource`"
AssertionError: Audio source must be opened before recording - see documentation for `AudioSource`
Process finished with exit code 1
This is the source code for reference:
#!/usr/bin/env python3
# Requires PyAudio and PySpeech.
import speech_recognition as sr
from time import ctime
import time
import os
from gtts import gTTS
def speak(audioString):
print(audioString)
tts = gTTS(text=audioString, lang='en')
tts.save("audio.mp3")
os.system("mpg321 audio.mp3")
def recordAudio():
# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# Speech recognition using Google Speech Recognition
data = ""
try:
# Uses the default API key
# To use another API key: `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
data = r.recognize_google(audio)
print("You said: " + data)
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))
return data
def jarvis(data):
if "how are you" in data:
speak("I am fine")
if "what time is it" in data:
speak(ctime())
if "where is" in data:
data = data.split(" ")
location = data[2]
speak("Hold on Frank, I will show you where " + location + " is.")
os.system("chromium-browser https://www.google.nl/maps/place/" + location + "/&")
# initialization time.sleep(2) speak("Hi Frank, what can I do for you?") while 1:
data = recordAudio()
jarvis(data)