I wasn't very sure on what to title this question so I'm sorry if it's not understandable. This project that I've been working on is a Jarvis-related project (Python) recently and this is my error
Traceback (most recent call last):
File "C:\Users\Admin\Rohan_Python\Virtual Assistant.py", line 13, in <module>
text = recog.recognize_google(sound)
File "D:\Rohan_Python\lib\site-packages\speech_recognition\__init__.py", line 858, in
recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise
UnknownValueError()
speech_recognition.UnknownValueError
My code...
import pyttsx3 as py
import speech_recognition as sr
# initializing speech_recognition
engine = py.init()
engine.say("Hey there! I'm Trevor. A virtual assistant for
programmers.")
engine.runAndWait()
recog = sr.Recognizer()
with sr.Microphone() as Sound_source:
recog.energy_threshold = 10000
recog.adjust_for_ambient_noise(Sound_source, 1.2)
print("Listening...")
sound = recog.listen(Sound_source)
text = recog.recognize_google(sound)
print(text)
I think this might be a simple error but could someone explain what the error means and what my error is? Also do give me the solution. Please and Thanks!
Recognition failed. You should catch that error:
try:
text = recog.recognize_google(sound)
print(text)
except sr.UnknownValueError:
print("Could not understand")
Related
Used this standard code for speech recognition:
import sys
sys.path.append('/home/nagy/.local/lib/python3.9/site-packages')
import speech_recognition
import pyttsx3
r = speech_recognition.Recognizer()
while True:
with speech_recognition.Microphone() as mic:
r.adjust_for_ambient_noise(mic,duration=0.2)
audio = r.listen(mic)
words = r.recognize_sphinx(audio)
words=words.lower()
print(words)
This is the error I receivee:
Traceback (most recent call last):
File "speech.py", line 3, in <module>
import speech_recognition
File "/home/nagy/.local/lib/python3.9/site-packages/speech_recognition/__init__.py", line 1513
endpoint = f"https://api.assemblyai.com/v2/transcript/{transciption_id}" ^
SyntaxError: invalid syntax
I'm not sure exactly what the error is but I know it's in the speech recognition library.
I'm getting an error I have never seen in python before, and I'm having trouble finding any information on the internet that solves my problem. I'm trying to program a voice assistant. Here is my code:
from fuzzywuzzy import fuzz
import sys
#sys.path.insert(0, '/home/pi/AIY-voice-kit-python/src/aiy/voice')
from aiy.voice import tts
#import tts
tts.say('Harry activated')
from os import environ, path
import os
#sys.path.insert(0, '/home/pi/AIY-voice-kit-python/src/examples/voice')
#from __init__ import LiveSpeech, get_model_path
from pocketsphinx import LiveSpeech, get_model_path
model_path = get_model_path()
print("active")
speech = LiveSpeech(
verbose=False,
sampling_rate=16000,
buffer_size=2048,
no_search=False,
full_utt=False,
hmm=os.path.join(model_path, 'en-us'),
lm=os.path.join(model_path, 'en-us.lm.bin'),
dic=os.path.join(model_path, 'cmudict-en-us.dict')
)
for phrase in speech:
p = str(phrase)
print(p)
r1 = (fuzz.ratio(p,"harry"))
print(r1)
ri = int(r1)
if ri > 60():
print("you said my name")
I'm not having any problems with imports. It's just the speech recognition has accuracy issues which is why I'm experimenting with "fuzzywuzzy". Python spits this error at me:
Traceback (most recent call last):
File "/home/pi/Desktop/AIY-projects-python/src/examples/voice/speack.py", line 31, in <module>
if ri > 60():
TypeError: 'int' object is not callable
I don't know where to go from here. Does anyone know how to resolve this issue? (Yes I know stackoverflow already has a similar question, but the answers don't seem to apply my situation)
I don't think that you need the () so try
int(ri) > 60:
I have tried to make a Voice assistance using pyAudio, i have installed correct version of pyAudio for my python version but i have some module error poping up after running program, i hope someone can help me.
import os
import time
import playsound
import speech_recognition as sr
from gtts import gTTS
def speak(text):
tts = gTTS(text=text)
filename = "voice.mp3"
tts.save(filename)
playsound.playsound(filename)
os.remove(filename)
def get_audio():
r = sr.Recognizer()
with sr.Microphone() as source :
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio, language = 'en-EN')
print(said)
except Exception as e:
print("It didn't worked ")
return said
text = get_audio()
if "hello" in text:
speak("hello how are you")
if "what is your name" in text:
speak("My name is timmy")
Errors
Traceback (most recent call last):
File "C:/Users/Home/PycharmProjects/JARVIS/main.py", line 28, in <module>
text = get_audio()
File "C:/Users/Home/PycharmProjects/JARVIS/main.py", line 16, in get_audio
with sr.Microphone() as source :
File "C:\Users\Home\PycharmProjects\JARVIS\venv\lib\site-packages\speech_recognition\__init__.py", line 138, in __enter__
self.audio.open(
File "C:\Users\Home\PycharmProjects\JARVIS\venv\lib\site-packages\pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "C:\Users\Home\PycharmProjects\JARVIS\venv\lib\site-packages\pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error
i am trying to convert text to speech using pyttsx3 in python. but iam getting the error -- _pickle.UnpicklingError: invalid load key, '\x00'.
it worked once. later it didn't
my code
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
error i am receiving is --
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\pyttsx3__init__.py",
line 20, in init
eng = _activeEngines[driverName]
File "C:\ProgramData\Anaconda3\lib\weakref.py", line 137, in
getitem
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
...
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\gencache.py", line 113, in _LoadDicts
version = p.load()
_pickle.UnpicklingError: invalid load key, '\x00'.
python version is 3.7.3 |
pyttsx3 version is 2.71|
pywin32 version is 224
please help
I had this problem as well and fixed it by deleting gen_py in my temp directory.
You can find this folder here:
C:\Users\USERNAME\AppData\Local\Temp\gen_py
I am making a game, and I need to load some password protected audio files from a .zip file, but I get this error:
io.UnsupportedOperation: seek
io.UnsupportedOperation: seek
io.UnsupportedOperation: seek
b'hey you did it!' #THIS IS FROM THE PROGRAM
Traceback (most recent call last):
File "C:\Python36\lib\zipfile.py", line 849, in read
data = self._read1(n)
File "C:\Python36\lib\zipfile.py", line 917, in _read1
data += self._read2(n - len(data))
File "C:\Python36\lib\zipfile.py", line 949, in _read2
data = self._fileobj.read(n)
File "C:\Python36\lib\zipfile.py", line 705, in read
self._file.seek(self._pos)
AttributeError: 'NoneType' object has no attribute 'seek'
And this is my code below:
from zipfile import ZipFile
from PIL import Image
from io import BytesIO
import pygame
from pygame.locals import *
import pyganim
import sys
pygame.init()
root = pygame.display.set_mode((320, 240), 0, 32)
pygame.display.set_caption('image load test')
#THIS IS HOW TO LOAD IMAGES (WORKS)
with ZipFile("spam.zip", 'r') as archive:
mcimg = archive.read('a.png', pwd=b'onlyforthedev')
mc = pygame.image.load(BytesIO(mcimg))
anime = pyganim.PygAnimation([(mc, 100),
(mc, 100)])
anime.play()
#THIS IS HOW TO LOAD MUSIC (DOES NOT WORK)
with ZipFile('spam.zip') as zippie:
with zippie.open('zora.mp3', pwd=b'onlyforthedev') as zora:
pygame.mixer.music.load(zora)
pygame.mixer.music.play(-1)
#THIS IS HOW TO LOAD TEXT (WORKS)
with ZipFile('spam.zip') as myzip:
with myzip.open('eggs.txt', pwd=b'onlyforthedev') as myfile:
print(myfile.read())
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
root.fill((100, 50, 50))
anime.blit(root, (100, 50))
pygame.display.update()
What can I do to load sound files without raising such an error? And what is 'seek'?
I also get this error on python 3.6.
I am going to guess that pygame.mixer.music.load calls the seek method on zippie, which is a ZipExtFile.
From python 3.7 ZipExtFile objects now have a seek method. I think that if you upgrade to python 3.7.2 or newer, then your error should go away.
Try to replace
pygame.mixer.music.load(zora)
with
with BytesIO(zora.read()) as zora_bio:
pygame.mixer.music.load(zora_bio)
This worked for me on python 3.6 with h5py.File().
I'm guessing it's the same problem as with pygame..load().
EDIT:
I now realize the above solution already exists in your code when you LOAD IMAGES:
with ZipFile("spam.zip", 'r') as archive:
mcimg = archive.read('a.png', pwd=b'onlyforthedev')
mc = pygame.image.load(BytesIO(mcimg))
So for uniformity, you could LOAD MUSIC in a similar way:
with ZipFile('spam.zip') as zippie:
zora = zippie.read('zora.mp3', pwd=b'onlyforthedev')
pygame.mixer.music.load(BytesIO(zora))