I am making a Jarvis and for some reason I'm getting an error, when I say something. The error message is shown below:
Exception in thread Thread-1 (threaded_listen):
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\xy\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\speech_recognition\__init__.py", line 754, in threaded_listen
if running[0]: callback(self, audio)
^^^^^^^^^^^^^^^^^^^^^
File "d:\pr\AI\SMITH\main.py", line 24, in callBack
speech_as_text = recognizer.recognize_sphinx(audio, keyword_entries=keywords)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xy\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\speech_recognition\__init__.py", line 817, in recognize_sphinx
decoder = pocketsphinx.Decoder(config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "_pocketsphinx.pyx", line 852, in _pocketsphinx.Decoder.__init__
RuntimeError: Failed to initialize PocketSphinx
It should wait for the keyword hey smith, and then execute the command. But if I say anything, I just get that strange error message. Here is the code I wrote:
import pyttsx3
import speech_recognition as sr
import time
from openpyxl import *
import random
import pocketsphinx
r = sr.Recognizer()
keywords = [('smith',1), ('smith',1)]
src = sr.Microphone()
def Speech(txt):
rate = 100
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.setProperty('rate', rate+85)
engine.say(txt)
engine.runAndWait()
def callBack(recognizer, audio):
try:
speech_as_text = recognizer.recognize_sphinx(audio, keyword_entries=keywords)
print(speech_as_text)
if 'smith' or 'smit' in speech_as_text:
Speech('Yes?')
recMain()
except sr.UnknownValueError:
print("Repeat please!")
def startRec():
print("...")
r.listen_in_background(src, callBack)
time.sleep(1000000)
def recMain():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say")
audio = r.listen(source)
data = ""
try:
data = r.recognize_sphinx
data.lower()
print("The ask was: ", data)
if "hello" in data:
Speech('Hi!')
else:
Speech("Sorry, i didn't get it!")
except sr.UnknownValueError:
print('I did not understand it.')
except sr.RequestError as e:
print("Well, I'm gonna crash {0}".format(e))
def excel():
wb = load_workbook("cmds.xlsx")
wu = wb.get_sheet_by_name('User')
wr = wb.get_sheet_by_name('Replies')
global helloList
urow = wu['1']
helloList = [urow[x].value for x in range(len(urow))]
global reply_helloList
rrow = wr['1']
reply_helloList = [rrow[x].value for x in range(len(rrow))]
while 1:
startRec()