In the last post I did a quick sopare intro and we controlled a robotic arm via voice. Today I want to focus on simple one word commands and how to add custom features to sopare. And because I need something to control I use a smart mirror web interface which is one of my next projects I’m working on. It’s not yet a mirror but the frame, screen, a usb mic and some more parts are already assembled and I think this is a perfect example how to use sopare with one word commands.
So, let’s start with the requirements. Obviously, you need a Raspberry Pi 2/3. And a microphone. All my sopare systems are using USB microphones. Here is a list that I’m using for different objectives:
- Blue Microphones Snowball USB Mic (light control)
- Samson Meteor Mic USB Studio (robotic arm control)
- Foxnovo Portable USB 2.0 Mic (magic mirror control)
And of course, you need sopare in the latest version. Before we start the training, it’s a good time to check and adjust the mic input. As I’m working most of the time with a headless Pi, “alsamixer” is my preferred tool. Just make sure that the input is not too high and not too low. I get good results with mic input levels around the 2/3 mark when the mic input level is not yet in the red sector (see the video for a visual reference).
There is one more thing to check and to adjust: The “THRESHOLD” value from the sopare/config.py file. This threshold defines when sopare “starts listening”. Or, in other words, everything below this threshold should be noise or environment sound. But for the training or, later on, the voice recognition, the threshold should be low enough to trigger the processing. This depends a lot on your environment. To figure out your ideal threshold you can start sopare in debug/verbose mode and just take a look what’s happening. If you see a lot of lines scrolling down the screen and you don’t say your voice command than the threshold is too low. If you start talking and nothing happens, the threshold is too high. Find your personal threshold by testing around with the following command:
./sopare.py -l -v
and adjust the config setting accordingly.
Now we are ready for training. Training is easy as eating cake. In my case I want to train a word and sopare should recognize the word with the identifier “main”. All I have to do is start the training by running the following command:
./sopare.py -t main
When you see the line “start endless recording” on the screen it’s time to train by saying a word or playing a tone of making the sound that should be trained. Repeat this at least 3 times. After training, we need to compile the dictionary which includes the information about the trained sound. This can be done with the command:
./sopare.py -c
We are now ready to test the trained command(s):
../sopare.py -l
You should test if your trained command is recognized. Normally you should get quite far with the default settings. Short one word commands will result in false positives with the default settings. How to gain more precision is something for one of the next posts as this topic is quite complex and requires some more background which does not fit in this basic usage post.
CTRL-c to terminate the process and return to the command line. In the rare case that the process does not terminates completely, find out the PID with the command
ps aux | grep python
and kill the process(es) via
kill -3 PID
Now you may want to ask: How can I control stuff with sopare? Where does my code goes? Good questions. Sopare comes with a simple plugin interface. Just take a look into the directory “./plugins”. You see the standard plugin “print/__init__.py”. This plugin only contains two (2) lines of code that are relevant in terms of coding:
def run(readable_results, data, rawbuf): print readable_results
The interesting part for the basic usage is the list value “readable_results”. In my case the value contains something like
[u’main’]
If you simply copy the print plugin you can add your own code and control stuff. Offline and in real time. In any language you want. Or any sound you want. Next time we will talk a bit more about configuration and customization but for today I have to stop. Have fun and tell me what you think and where/how you are using sopare 🙂
Hi Bishoph,
thanks a lot for this post and also the video tutorial. Very much appreciated as I am looking for a solution to voice control my home automation system.
Everything works now according to your great instructions, however the precision of the word recognition could be better. Sometimes, completely unrelated words are detected as a key word. I think thats what you call false positive.
Would very much appreciate some hints or another great tutorial!
Best regards
Frank (auch aus Deutschland 😉 )
Hi Frank, you are welcome and cool that it works so far. In terms of precision and better recognition I guess I just need to step up and explain how this works 😉 All I can say right now is that it’s all about configuration…and the video tutorial would be really helpful to explain that. Please be patient until my priorities allow me to provide a new blog post and the corresponding video tutorial.
Thanks for your feedback.
Well I am eagerly waiting for your tutorial then. Would really appreciate those tips, I’m hitting kind of a ceiling here.
Also: How do you make sure that commands are recognised from different positions in the room? I have the issue that the command which was recorded directly next to the Mic, gets also only recognised next to the Mic.
Cheers
Hope I get some time next weekend…
In regards to different positions in a room: depends a lot on your microphone, where the mic is located and configuration. For example if the mic offers an omnidirectional mode and is located in the center of the room this would be my preferred setup. Of course the training and recognition goes hand in hand. If you have a mic that covers only one direction and you train very closely to the mic but in reality you want results from different angles and distances you choose either lower similarities, use a different mic, tweak config options or train the same word more often under different conditions. There is no silver bullet I can offer here so let’s see if and how the next tutorial shed some light into this topic 🙂
could you help me in my project i am doing a project that i control a car with voice with 9 voice commands
1-right
2-left
3-slow
4-fast
5-foreward
6-backward
7-open
8-close
9-stop
i want it to do this function i use h-bridge l29 driver
Hi. Not sure what you expect in terms of help but let’s give it a try and start with the basic steps:
1) Get a mic and configure it
2) Install sopare and resolve the dependencies
3) Check your mic input levels via ./sopare.py -l -v and adjust the config settings accordingly
4) Train your 9 commands, each word at least 3 times via ./sopare.py -t YOUR_VOICE_COMMAND
5) Compile the dictionary: ./sopare.py -c
6) Test if the words are recognized and adjust the config settings for good results (see the blog post about precision and accuracy)
7) Get some experience by checking the commands under different conditions and with background noise. Also what happens if you give the commands from far away or different angles. Adapt and configure based on your practical knowledge. You may need to do a GOTO 4 or even consider a different mic and GOTO 1 😉
8) Copy the sopare print plugin and write your very own h-bridge l29 plugin by checking for the command and then turn the GPIO pins low/high according to the action. I recommend to add some timeout logic.
Hi
According to the reference above-
If i detect ‘forward’,i should define
if readable_result == ‘forward’:
Turn on GPIO HIGH
delay
Turn off GPIO LOW.
please correct me if i am wrong.
Regards
Hello
It would be great,if you explain how to control RPI.GPIO with the keyword train.
Can you show with an example to control LED through train Voice command,like after training the keyword if ‘OFF’ is detected it will switch off the led light
regards
Hi,
not sure if you saw the robotic arm control source code:
https://github.com/bishoph/Misc/blob/master/robotic_arm_control.py
To control GPIO works the same. Here is a simple plugin example with “on” and “off” (not tested!):
Have fun!
How can I run a bash command like “pilight-send -p elro_800_switch -s 21 -u 1 –on” instead of changing GPIO states?
Hi, here is a very basic plugin example which executes a Bash-Script. The Bash-Script should contain your command and must have the appropriate permissions:
I recommend to get at least some basic Python/Shell skills to be able to adapt and customize to meet your requirements:
https://stackoverflow.com/questions/7032212/how-to-run-application-with-parameters-in-python
https://linuxconfig.org/bash-scripting-tutorial
Happy voice controlling 🙂
Good evening,
I’ve just started testing with Sopare as I am searching for a solution for a offline speech recognition for home automation.
I had no problems installing version 1.3.0. Everything seems to work fine just as long as dict.json is empty. I could train and create the first dictionary entries with no error mesages:
[code]
~/sopare $ ./sopare.py -t TEST
sopare 1.3.0
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_hw.c:1713:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_hw.c:1713:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_dmix.c:1052:(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
JackShmReadWritePtr::~JackShmReadWritePtr – Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr – Init not done for -1, skipping unlock
start endless recording
Buffering not alive, stop recording
stop endless recording
~/sopare $ ./sopare.py -c
sopare 1.3.0
recreating dictionary from raw input files…
[/code]
From this point on, the -t or -l option result in endless “stream closed” error messages:
[code]
:~/sopare $ ./sopare.py -l
sopare 1.3.0
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_hw.c:1713:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_hw.c:1713:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_dmix.c:1052:(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
JackShmReadWritePtr::~JackShmReadWritePtr – Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr – Init not done for -1, skipping unlock
start endless recording
stream read error [Errno -9981] Input overflowed
stream read error [Errno -9988] Stream closed
stream read error [Errno -9988] Stream closed
stream read error [Errno -9988] Stream closed
stream read error [Errno -9988] Stream closed
…
[/code]
Any help on this would be highly appreciated. 🙂
BR,
– Mirko –
Hi Mirko,
first it seems that you need to clean up your alsa.conf file to avoid the warnings. In regards to the PyAudio issue “Errno -9981”: you can just ignore the warning. Lots of Raspberry Pi users around the world are facing this issue and it has no to minimal impact when using SOPARE. The warning means that your system is not able to keep up with the recording.
I searched around “Errno -9988” (which is also a PyAudio issue BTW) and it could be that you sample rate is a problem here. You could try to change the sample rate “SAMPLE_RATE” in the config.py and try if the issue disappears. As this is very environment specific there is not much I can do here 🙂
Hi,
what’s a “stream read error [Errno -9988] Stream closed”?
I get tons of those…
btw, I have seen you answered already above, but I cannot find config.py…. do you mean respi-config? or a configuraiton file for PyAudio? or of sopare? Recording works fine with arecord at 44100, mono. where shall I set this as a default? thanks
The file you want to edit is ./sopare/config.py
Hi,
in the latest testing branch I’ve added a sound test. Could you please use the latest version (>= 1.3.8) and post the output as you should get either recommendations for your sound environment or at least some additional information to figure out whats going on.
If you are using git switch to the testing branch with the following commands:
“git pull/fetch”
“git checkout testing”
and run
“python test/test_audio.py”
In my test with different microphones the above error often comes from a “wrong” sample rate.
Hi bisoph,
first of all thanks a lot for your effort here on this project. I really appreciate this. I’m still trying to get it to work, since I’m having the same issues as the guy above.
Btw. I don’t have any alsa.conf on my system. (find / -iname alsa.conf) What I did is to make my USB Sound Card the primary device. For this i created /lib/modprobe.d/audio.conf and put the following snippet in that file:
# Load USB audio before the internal soundcard
options snd_usb_audio index=0
options snd_bcm2835 index=1
# Make sure the sound cards are ordered the correct way in ALSA
options snd slots=snd_usb_audio,snd_bcm2835
Here’s the output of the testing branch.
———————————————————————————–
python test/test_audio.py
test_audio init…
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
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
JackShmReadWritePtr::~JackShmReadWritePtr – Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr – Init not done for -1, skipping unlock
##### Default input device info #####
defaultSampleRate: 48000.0
defaultLowOutputLatency: 0.0213333333333
defaultLowInputLatency: 0.0213333333333
maxInputChannels: 128
structVersion: 2
hostApi: 0
index: 8
defaultHighOutputLatency: 0.0213333333333
maxOutputChannels: 128
name: default
defaultHighInputLatency: 0.0213333333333
#####################################
testing different SAMPLE_RATEs … this may take a while!
testing different CHUNK sizes … this may take a while!
Excellent. Got all 5000 chunks.
Excellent. Got all 10000 chunks.
Excellent. Got all 20000 chunks.
Excellent. Got all 40000 chunks.
Excellent. Got all 80000 chunks.
Excellent. Got all 5000 chunks.
Excellent. Got all 10000 chunks.
Excellent. Got all 20000 chunks.
Excellent. Got all 40000 chunks.
Excellent. Got all 80000 chunks.
Excellent. Got all 5000 chunks.
Excellent. Got all 10000 chunks.
Excellent. Got all 20000 chunks.
Excellent. Got all 40000 chunks.
Error: [Errno -9981] Input overflowed
Excellent. Got all 5000 chunks.
Excellent. Got all 10000 chunks.
Excellent. Got all 20000 chunks.
Excellent. Got all 40000 chunks.
Excellent. Got all 80000 chunks.
Excellent. Got all 5000 chunks.
Excellent. Got all 10000 chunks.
Excellent. Got all 20000 chunks.
Excellent. Got all 40000 chunks.
Excellent. Got all 80000 chunks.
Excellent. Got all 5000 chunks.
Excellent. Got all 10000 chunks.
Excellent. Got all 20000 chunks.
Excellent. Got all 40000 chunks.
Excellent. Got all 80000 chunks.
Excellent. Got all 5000 chunks.
Excellent. Got all 10000 chunks.
Excellent. Got all 20000 chunks.
Excellent. Got all 40000 chunks.
Excellent. Got all 80000 chunks.
Excellent. Got all 5000 chunks.
Error: [Errno -9981] Input overflowed
Error: [Errno -9981] Input overflowed
Error: [Errno -9981] Input overflowed
Error: [Errno -9981] Input overflowed
Your sopare/config.py recommendations:
SAMPLE_RATE = 48000
CHUNK = 500
THRESHOLD = 9600
———————————————————————————–
I’ll fix the settings now and give you guys an update later on.
Cheers
Ok. I commented out now the priorization of the usb card. Im getting now different results with the audio test.
Your sopare/config.py recommendations:
———————————————————
SAMPLE_RATE = 48000
CHUNK = 500
THRESHOLD = 100
———————————————————
I set the values to the config file and tried it again. Sadly I stll get the same output as before.
———————————————————-
./sopare.py -l -v
sopare 1.3.8
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.front.0:CARD=0’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM front
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.surround51.0:CARD=0’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.surround51.0:CARD=0’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.surround40.0:CARD=0’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround40
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.surround51.0:CARD=0’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround41
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.surround51.0:CARD=0’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround50
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.surround51.0:CARD=0’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround51
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.surround71.0:CARD=0’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround71
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM iec958
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition ‘cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2’
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
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
JackShmReadWritePtr::~JackShmReadWritePtr – Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr – Init not done for -1, skipping unlock
No handlers could be found for logger “sopare.recorder”
INFO:root:checking for plugins…
DEBUG:root:loading and initialzing plugins/print
INFO:sopare.recorder:start endless recording
WARNING:sopare.recorder:stream read error [Errno -9981] Input overflowed
INFO:sopare.worker:worker queue runner started
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
INFO:sopare.buffering:buffering queue runner
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
WARNING:sopare.recorder:stream read error [Errno -9988] Stream closed
…..
^CProcess buffering queue:
Process worker for filtered data:
Traceback (most recent call last):
File “/usr/lib/python2.7/multiprocessing/process.py”, line 258, in _bootstrap
Traceback (most recent call last):
File “/usr/lib/python2.7/multiprocessing/process.py”, line 258, in _bootstrap
self.run()
Traceback (most recent call last):
File “./sopare.py”, line 162, in
main(sys.argv[1:])
File “./sopare.py”, line 104, in main
self.run()
recorder.recorder(hatched)
File “/home/pi/Programs/test/sopare/sopare/recorder.py”, line 60, in __init__
File “/home/pi/Programs/test/sopare/sopare/worker.py”, line 90, in run
File “/home/pi/Programs/test/sopare/sopare/buffering.py”, line 41, in run
buf = self.queue.get()
self.recording()
File “/home/pi/Programs/test/sopare/sopare/recorder.py”, line 104, in recording
self.logger.warning(“stream read error “+str(e))
File “/usr/lib/python2.7/logging/__init__.py”, line 1179, in warning
obj = self.queue.get()
File “/usr/lib/python2.7/multiprocessing/queues.py”, line 117, in get
File “/usr/lib/python2.7/multiprocessing/queues.py”, line 117, in get
res = self._recv()
self._log(WARNING, msg, args, **kwargs)
File “/usr/lib/python2.7/logging/__init__.py”, line 1286, in _log
KeyboardInterrupt
res = self._recv()
KeyboardInterrupt
self.handle(record)
File “/usr/lib/python2.7/logging/__init__.py”, line 1296, in handle
self.callHandlers(record)
File “/usr/lib/python2.7/logging/__init__.py”, line 1336, in callHandlers
hdlr.handle(record)
File “/usr/lib/python2.7/logging/__init__.py”, line 759, in handle
self.emit(record)
File “/usr/lib/python2.7/logging/__init__.py”, line 882, in emit
stream.write(fs % msg)
KeyboardInterrupt
———————————————————————————————
Hi.
Strange that you are using ALSA sound but there is no alsa.conf…it seems to me that your issue is that the sound card is not used or recognized (no idea why the audio_test chooses the “right one” while SOPARE doesn’t. Furthermore the whole debug output from the used interface is missing in your output):
“Unable to find definition cards.bcm2835”
My suggestion is to fix your sound config and continue:
https://alsa.opensrc.org/MultipleCards
Side note: please use 512 as value for the CHUNK, I need to fix this in the testing branch 😉
btw. Im using this device for audio:
https://www.amazon.de/UGREEN-Soundkarte-Kopfh%C3%B6rer-Mikrofonanschluss-kompatibel/dp/B01N905VOY/ref=sr_1_1?ie=UTF8&qid=1510416044&sr=8-1&keywords=usb+audio+card+raspberry&dpID=41zp99SXYrL&preST=_SY300_QL70_&dpSrc=srch
some info:
lsusb
Bus 001 Device 005: ID 0d8c:0014 C-Media Electronics, Inc
———————————–
dmesg (snippet)
[ 1781.992929] usb 1-1.5: new full-speed USB device number 5 using dwc_otg
[ 1782.131851] usb 1-1.5: New USB device found, idVendor=0d8c, idProduct=0014
[ 1782.131876] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1782.131886] usb 1-1.5: Product: USB Audio Device
[ 1782.131896] usb 1-1.5: Manufacturer: C-Media Electronics Inc.
[ 1782.195866] input: C-Media Electronics Inc. USB Audio Device as /devices/platform/soc/20980000.usb/usb1/1-1/1-1.5/1-1.5:1.3/0003:0D8C:0014.0002/input/input1
[ 1782.263947] hid-generic 0003:0D8C:0014.0002: input,hidraw0: USB HID v1.00 Device [C-Media Electronics Inc. USB Audio Device] on usb-20980000.usb-1.5/input3
———————————–
arecord -l
**** Liste der Hardware-Geräte (CAPTURE) ****
Karte 1: Device [USB Audio Device], Gerät 0: USB Audio [USB Audio]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
I recorded audio without any issues with arecord (arecord -f S16_LE -r 48000 -D hw:1,0 -d 10 test.wav)
Realy would like to get this to work. If you need any additional info please do not hesitate and ask for it. I’ll provide them asap.
Cheers
SOPARE uses the default card as configured somewhere in the deep of the system – as you can see in the output:
“name: default”
The default points to “hw:0,0” AFAIR.
Your arecord command was executed with “hw:1,0” which means SOPARE uses a different interface/hardware. From the distance I would say that you need to set the default to “hw:1,0” but what I don’t understand is the fact that the audio test seems to work and SOPARE does not and that’s why I can’t give you clear instructions, it’s illogical or some information are missing.
Hi bishoph,
the issue is that sopare tries to use card 0. Actually there is no card 0 anymore in my system since I blacklisted the onboard bcm2835.
/etc/modprobe.d/alsa-blacklist.conf
blacklist snd_bcm2835
then rebooted. aplay and arecord shown only this device, but as device 1. when using arecord for recording it was complaining. Therefore I changed the following to make the usb card to device 0
/etc/modprobe.d/alsa-base.conf
options snd-usb-audio index=0
output of arecord and aplay is now fine, even the recording works like a charme with the usb device.
Please check here: https://pastebin.com/DJMPVbUN
Cheers
D3M
Btw. I forget to tell you what OS is running and some other facts.
OS: Raspbian Stretch (newest)
Raspberry: Revision : 0010 (Model B+)
If you maybe need the audio card for testing, I would be pleased to send you one or give you a donation.
Cheers
Hi,
unfortunately your audio hardware would just work fine on my setup as your config is messed up – as far as I can tell. On top of this, SOPARE uses pyaudio and requires a working audio setup. I searched a bit and hopefully you get some insights and help reading this:
https://raspberrypi.stackexchange.com/questions/39928/unable-to-set-default-input-and-output-audio-device-on-raspberry-jessie
Hi,
I don’t think so. Since it’s a fresh plain installation of Raspbian Stretch. Nothing has been changed. Just the packets were updated as usual when you setup a new system. Also the tools like 433Utils, raspberry-pi-remote and wiringPi have absolutelly no impact on the audio configuration.
In spite of that I tested the link you gave me with exactly the same result as before.
As you can see in the pastebin link I pasted, alsa is working just fine for record and play with device 0
Has this been tested with Raspbian Stretch before?
SOPARE is pretty much detached from any underlying system or infrastructure. This means if you match the requirements and configure your environment properly SOPARE works like a charm 😉
Oh, and yes: SOPARE is running and was developed under Wheezy, Jessie and Stretch 🙂
I replaced the Model B+ with a RPi2 Model B and used the same SD-Card as in the B+.
It works. <3
I also check the B+ for faulty components. It's fine. So actually no idea what went wrong here. Thanks for your time bishoph 🙂
But I'm sure I'll have other questions soon. 😉 I also document the steps I'm doing for others who want to do the same.
Cheers
That explains a lot. As written in the readme: “SOPARE…requires a multi core processor architecture” and the Model B simple does not match this requirement 😉 – I must admit that the error messages are pretty unrelated and misleading. If possible I’ll add an architecture test to the current audio test case.
Happy voice controlling 🙂
hi i’m doing a project using rpi3 that would detect sounds from motorcycle. can I used SOPARE for my project? please help..
Hi. You can give it a try. Make sure that you have clear sounds for training 🙂
Hallo
Erst einmal wirklich ein sehr cooles Projekt.
könntest du noch die init vom smart mirror projekt und denn smart mirror code verlinken ?
Hi, danke 🙂
Hier der Link zum SOPARE start/stop init.d script:
https://github.com/bishoph/Misc/blob/master/sopare_service
Hello!
I experienced with copare on raspberri pi 3 b . Everything went well.
question:
will this work for orang pi pc plus ?
If you resolve the dependencies there this should work 🙂
Hello!
I tried the orange pi ps plus. with an external sound card everything works. speed up. not on all firmware works.
Hi! Thanks for the software! Can I train using previously recorded files? How do I do that? I have .wav files I’d like to use for training. Can I use .wav files for testing to? Instead of live mic.
Thanks!
kd5uwl
Hi. Wave files can’t be used but raw files created from and with SOPARE can be used. Maybe you find this interesting:
https://github.com/bishoph/sopare/issues/34
Hi, I want to use SOPARE for a robot to identify when a bird sing on a plantation. Do you know if I can use SOPARE in this project? Is there a microphone that can pick up sound at longer distances?
If you don’t try it you will never know for sure as environmental sounds, bird loudness and lots of other factors are unknown but important variables to answer your question. In terms of microphone I presented some of the microphones that I’m currently using (all indoor though):
https://www.bishoph.org/sopare-basic-usage-voice-controlling-a-magic-mirror/
Hi,
first up, great work so far! Thank you for your engagement!
I was wondering, how you voice control different lights for instance in diferent rooms. As the microphones mentioned are all connected via USB, this limits the placement of the microphone. Has anyone successfully tryed a wireless microphone (bluetooth / Wifi) in a setup with sopare?
Thanks and br,
giuliana
Thanks!
My architecture is complex and contains multiple Raspberry PIs with different instances. It’s a network of machines with different purposes. Input devices (like SOPARE) and action devices for management and doing the heavy lifting.
In terms of microphones: As SOPARE uses ALSA you can use everything that is supported by ALSA.
Cheers!
hello sir how can we use the a hotword to trigger the sopare? like its should run continuously , when the hotword is detected it should further listen to the commands…until then it should’t listen to anything except the hotword.
And everytime it should do this . please help me on this!
SOPARE always compares input to learned sounds. If you want a hotword first you can write a custom plugin accordingly. There is a code example for the robotic arm which should be helpful:
https://github.com/bishoph/Misc/blob/master/robotic_arm_control.py
hi
i train some word & i want to use them in my project (smart home)
how to use this trained word on my project?!
i mean .. i have a python file which my project is in this file,i want to add sopare as a realtime recognition to my project????
You need a connection between SOPARE and your program like a socket, network, shared memory, direct invocation – you see there are plenty of options available…
Hi,
I’m trying to have Tkinter (on a touchscreen as GUI) working with Sopare for a college project. Tkinter seems to stop (pause) sopare running in the background. Is there a way for them to function together.
Thanks in advance,
Ciarán
As I don’t know TKinter nor your project nor the boundaries here comes a generic advice: Decouple the backend and the GUI and frame an architecture where the UI receives results/events from the SOPARE plugin in a non blocking way. I’ve used this approach to control the magic mirror with SOPARE and it works just fine 😉
How to interface with MQTT ?
As I wanted to try that myself (but didn’t have the time to do so), I bookmarked paho-mqtt. Find a simple MQTT client skript to publish data here:
https://www.dinotools.de/2015/04/12/mqtt-mit-python-nutzen/
fwiw the paho-mqtt docs: https://pypi.org/project/paho-mqtt/#usage-and-api