Background listing using speech_recognition python library - python

I am trying to implement a background listing using speech_recognition python library. Following code use for that. When I run this code I got the following error message. How can I solve this issue?
Error MSG:
RuntimeError: Decoder_set_kws returned -1
Python library - https://github.com/Uberi/speech_recognition#readme
Code:
import speech_recognition as sr
import time
r = sr.Recognizer()
# Words that sphinx should listen closely for. 0-1 is the sensitivity
# of the wake word.
keywords = [("google", 1), ("hey google", 1), ]
source = sr.Microphone(device_index = device_id, sample_rate = sample_rate, chunk_size = chunk_size)
def callback(recognizer, audio): # this is called from the background thread
try:
speech_as_text = recognizer.recognize_sphinx(audio, keyword_entries=keywords)
print(speech_as_text)
# Look for your "Ok Google" keyword in speech_as_text
if "google" in speech_as_text or "hey google":
recognize_main()
except sr.UnknownValueError:
print("Oops! Didn't catch that")
def recognize_main():
print("Recognizing Main...")
audio_data = r.listen(source)
# interpret the user's words however you normally interpret them
def start_recognizer():
print("Main...")
r.listen_in_background(source, callback)
time.sleep(1000000)
start_recognizer()
Full Error MSG:
Exception in thread Thread-6: Traceback (most recent call last):
File "C:\Users\aa\anaconda3\envs\env1\lib\threading.py", line 926, in
_bootstrap_inner
self.run() File "C:\Users\aa\anaconda3\envs\env1\lib\threading.py", line 870, in run
self._target(*self.args, **self.kwargs) File "C:\Users\aa\anaconda3\envs\env1\lib\site-packages\speech_recognition_init.py",
line 616, in threaded_listen
if running[0]: callback(self, audio) File "", line 16, in callback
speech_as_text = recognizer.recognize_sphinx(audio, keyword_entries=keywords) File
"C:\Users\aa\anaconda3\envs\env1\lib\site-packages\speech_recognition_init.py",
line 683, in recognize_sphinx
decoder.set_kws("keywords", f.name) File "C:\Users\aa\anaconda3\envs\env1\lib\site-packages\pocketsphinx\pocketsphinx.py",
line 309, in set_kws
return _pocketsphinx.Decoder_set_kws(self, name, keyfile) RuntimeError: Decoder_set_kws returned -1

Related

ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%SZ'

I am trying to run rq worker in ubuntu but when I type
rq worker
It gives me this error
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rq/utils.py", line 169, in utcparse
return datetime.datetime.strptime(string, _TIMESTAMP_FORMAT)
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rq/worker.py", line 508, in work
result = self.dequeue_job_and_maintain_ttl(timeout)
File "/usr/lib/python3/dist-packages/rq/worker.py", line 574, in dequeue_job_and_maintain_ttl
result = self.queue_class.dequeue_any(self.queues, timeout,
File "/usr/lib/python3/dist-packages/rq/queue.py", line 539, in dequeue_any
job = job_class.fetch(job_id, connection=connection)
File "/usr/lib/python3/dist-packages/rq/job.py", line 303, in fetch
job.refresh()
File "/usr/lib/python3/dist-packages/rq/job.py", line 515, in refresh
self.restore(data)
File "/usr/lib/python3/dist-packages/rq/job.py", line 478, in restore
self.started_at = str_to_date(obj.get('started_at'))
I am queueing a simple task from another file hello.py, the code:
def add(x, y):
return x + y
and this is my main.py code:
from flask import Flask
from redis import Redis
from hello import add
from rq import Queue
q = Queue(connection=Redis())
app = Flask(__name__)
#app.route("/")
def hello():
q.enqueue(add, 3, 7)
return "Task enqueued"
if __name__ == "__main__":
app.run(debug=True)
It is queueing the things in redis-server but it doesn't have a worker to run things, I just want a worker running in ubuntu. And the redis-server is hosted locally. I checked even the task is enqueueing properly but it is showing that their are 0 workers. I don't know what else to write but feel free to ask anything regarding this.
In the error you provided, there is no timestamp ('') being sent to rq :
ValueError: time data '' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
Check to see if you have a conflicting package called python-rq installed per this issue :
https://github.com/rq/rq/issues/1309
If not, check that your locale is set correctly in Ubuntu and the 'date' command produce the expected result. Next check that the Python also returns the correct date :
import datetime;
print(datetime.datetime.now())

Use spech_recognition to write down system audio

I am trying to use Python speech_recognition to get an input from the system audio and then to print it as output. Unfortunately, I'm having some problems with the devices list. In fact, it seems that speech_recognition only recognizes microphones as devices of input.
My idea is the following: I am very slow at writing down notes of important videocalls, so I would like to have Python speech_recognition write them down for me so I can catch up with missing pieces. Do you think it is possible? How?
This is my code until now:
import pyaudio
import speech_recognition as sr
r=sr.Recognizer()
r.energy_threshold=4000
for index, name in enumerate(sr.Microphone.list_microphone_names()):
print("Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
# returns a list of 15 devices (microphone, system speakers, headphones...)
with sr.Microphone(device_index=4) as source:
audio = r.listen(source)
# index = 4 is my headphones
try:
print("Speech was:" + r.recognize_google(audio))
except LookupError:
print('Speech not understood')
When just looking at it, it seems good. But when running it, it cannot recognize my headphones (system audio) as devices and returns the following errors:
Traceback (most recent call last):
File "...", line 10, in <module>
with sr.Microphone(device_index=4) as source:
File "...\speech_recognition\__init__.py", line 141, in __enter__
input=True, # stream is an input stream
File "...pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "...pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9998] Invalid number of channels
and when putting "normal microphone" as input:
line 858, in recognize_google
if not isinstance(actual_result, dict) or len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
Can you help me figure this out please?
The microphone error is given when the result of the audio wasn't understood as words. You can fix that by adding a try/except around the statement with "except [the name of the import].UnknownValueError. This will result in whatever is put under except to be run if the "UnknownValueError" error is encountered. As for the headphones, I believe the issue is that you are using an output device for an input function.

Python SpeechRecognition Library says my microphone is unavailable

I am trying to do speech recognition using python and the library SpeechRecognition. When I run the basic code from the docs I get the error message shown below.
Traceback (most recent call last):
File "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python37\lib\site-packages\speech_recognition\__main__.py", line 8, in <module>
with m as source: r.adjust_for_ambient_noise(source)
File "C:\Python37\lib\site-packages\speech_recognition\__init__.py", line 141, in __enter__
input=True, # stream is an input stream
File "C:\Python37\lib\site-packages\pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "C:\Python37\lib\site-packages\pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9985] Device unavailable
I have tried using multiple microphone indexes but none of them pick anything up (program runs forever until I quit it), but when I try it with my default actual microphone it gives me the error.
When running python -m speech_recognition to test if it was installed in command prompt I got the same error message as shown above so the code is not an issue. I have also tried running the program as an admin and made sure my microphone was set as default. I also only have python 3 installed so it is not an issue with multiple versions.
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Boss.. plz say some")
audio = r.listen(source)
print("143 Boss")
try:
text = r.recognize_google(audio)
except Exception as e:
print (e)
Use this code, if you still face problem comment else accept the answer.

im faceing the errors in speech recognition

import speech_recognition as sr
import pyaudio
r=sr.Recognizer()
with sr.Microphone()as source:
print(" speak :")
audio=r.listen(source)
try:
output=r.recognize_google(audio)
print(" you said :".format(output))
except:
print(" i cont recognize what u said place spaek clear")
ERRORS:
Traceback (most recent call last):
File "d:/codes/speechreg.py", line 5, in <module>
with sr.Microphone()as source:
File "C:\Users\bjman\AppData\Local\Programs\Python\Python37\lib\site-packages\speech_recognition\__init__.py", line 141, in __enter__
input=True, # stream is an input stream
File "C:\Users\bjman\AppData\Local\Programs\Python\Python37\lib\site-packages\pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "C:\Users\bjman\AppData\Local\Programs\Python\Python37\lib\site-packages\pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error
Have you tried to enable access to your microphone? Try enabling microphone using this guid.
I think your code didn't print the output. try to change the following line,
print(" you said :{}".format(output))
And this code will perform as your desire.You can try it as well!
import speech_recognition as sr
import pyaudio
r=sr.Recognizer()
with sr.Microphone()as source:
print(" speak :")
audio=r.listen(source)
try:
value = r.recognize_google(audio)
if str is bytes:
result = u"{}".format(value).encode("utf-8")
else:
result = "{}".format(value)
with open("outputs.txt","a") as f:
f.write(result)
print(result)
except:
print(" i cont recognize what u said place spaek clear")

I don't know what is wrong in my speech recognition program

Exception in Tkinter callback:
Traceback (most recent call last):
File "/Users/choihyomin/anaconda3/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "/Users/choihyomin/Documents/GitHub/Doby_OS/main.py", line 9, in DobbyIsListening
dobby.dobyisfree()
File "/Users/choihyomin/Documents/GitHub/Doby_OS/dobby.py", line 15, in dobyisfree
audio = r.listen(source,timeout = 2)
File "/Users/choihyomin/anaconda3/lib/python3.7/site-packages/speech_recognition/__init__.py", line 618, in listen
raise WaitTimeoutError("listening timed out while waiting for phrase to start")
speech_recognition.WaitTimeoutError: listening timed out while waiting for phrase to start
Hi, I'm a student who studies python.
I'm making AI using SpeechRecognition module.
I saw a YouTube tutorial and coded.
I installed SpeechRecognition and PyAudio. But it is not working:
with sr.Microphone() as source:
print("도비는 듣고 있어요!")
audio = r.listen(source,timeout = 2)
This is the part where the error comes in my code.
Any help would be appreciated.
Thank you

Categories

Resources