Hi,
I used the micarray_alsa_pipes.py demo and with alsaaudio I can read data:
Looks like "H?H?G?I?E?H?J?I?F?G?G?G?H?H?J?D…"
What is the next step to get the right “Sound” values?
python code:
import alsaaudio
mic = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device=‘mic_channel0’)
mic.setchannels(1)
mic.setrate(16000)
mic.setformat(alsaaudio.PCM_FORMAT_S16_LE)
mic.setperiodsize(160)
while True:
length, data = mic.read()
if length:
print data
i wrote a quick and dirty (just for fun) example to implement a recorder starting to record, when it detects some sound and keeps recording while not idle for 2 seconds - saving the result to test.wav. i know the range of an audio value is signed so the max(…) is not nice here, but it works quite well. the check againts 2000 is totally random chosen.
the script uses pyalsaaudio and needs the matrixio-malos serivce running.
Thanks! The examples are working!
Also spectrum.py after changing to the rigth device.
I’m happy to test the Matrix Voice now.
btw: matrixio-malos serivce was running but I had to start micarray_alsa_pipes.py to get it working…
I ran into the same issue, I try your code and I got this error :
indent preformatted text by 4 spaces
Traceback (most recent call last):
File “voice.py”, line 8, in
mic = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device=‘mic_channel8’)
TypeError: ‘device’ is an invalid keyword argument for this function
So I wonder if you can share your /etc/asound.conf file and if exist your ~/.asound.conf
no you only need to start the matrixio-malos.service it should create the pipes in the /tmp folder.
# malos service is needed:
sudo apt install matrixio-malos
# service should be started by default, but to be sure:
sudo systemctl start matrixio-malos.service
# check if the pipes are created
ls /tmp
as alternative you can create those pipes by running the cpp programm an let it keep running. with the installation of the malos.serivce, the alsa sound config should be set up properly. so no need define your own ~/.asound.conf
you can list the pcm devices available with running this in your python shell
import alsaaudio
alsaaudio.__file__ # <-- check if the correct mpdule is used
alsaaudio.pcms() # <-- list devices
this should return:
'/home/pi/.virtualenvs/matrix/local/lib/python2.7/site-packages/alsaaudio.so' <--my virtualenv install path
[u'null', u'sc', u'mic_channel0', u'mic_channel1', u'mic_channel2', u'mic_channel3', u'mic_channel4', u'mic_channel5', u'mic_channel6', u'mic_channel7', u'mic_channel8', u'default', u'sysdefault:CARD=ALSA', u'dmix:CARD=ALSA,DEV=0', u'dmix:CARD=ALSA,DEV=1', u'dsnoop:CARD=ALSA,DEV=0', u'dsnoop:CARD=ALSA,DEV=1', u'hw:CARD=ALSA,DEV=0', u'hw:CARD=ALSA,DEV=1', u'plughw:CARD=ALSA,DEV=0', u'plughw:CARD=ALSA,DEV=1', u'sysdefault:CARD=Dummy', u'dmix:CARD=Dummy,DEV=0', u'dsnoop:CARD=Dummy,DEV=0', u'hw:CARD=Dummy,DEV=0', u'plughw:CARD=Dummy,DEV=0']
that’s all i have done to get the example running on my creator and it works.
by the way i also updated my example script to use 20000 as condition for the recorder, because they increased the gain of the mics in their latest firmware release
I finally succeed. I remove everything I made before and create a virtual environnement and now it works.
I modified the modprob.d/alsa … file so I delete it and work instantly.
I remove all the matrix package reboot and reinstall only the one you mention.
sudo apt-get remove matrix-*
But now, I don’t know if it normal but after a while the script show that error (if its an error)
Traceback (most recent call last):
File "voice.py", line 26, in <module>
sound_detected = True if max(struct.unpack('<%dh' % length, data)) > 20000 else False
struct.error: bad char in struct format
is this happening before, or while recording, i could reproduce it one. it seems that the unpack format get’s generated wrong. eventually is the length value not a regular, or negative number, will test further.