dancyPi-audio-reactive-led: Exiting arecord in shell script?
So I’m utilizing dancyPi in sync with Raspotify / Librespot. Librespot has hooks so I’m using the follow script:
#!/bin/bash
if [ "$PLAYER_EVENT" = "start" ]; then
sudo python3 home/pi/dancyPi-audio-reactive-led/python/visualization.py scroll
elif [ "$PLAYER_EVENT" = "stop" ]; then
sudo python3 home/pi/dancyPi-audio-reactive-led/python/off.py
else
:
fi
However, I did not realize that the “off.py” script did not kill the mic recording. What would be the best way of freeing up the mic after Spotify stops?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 72 (6 by maintainers)
@naztronaut They introduced pulseaudio as default on the desktop version of Raspberry Pi OS so that’s going to throw a wrench in anything you do audio wise from now on. Pulseaudio is great 99.9% of the time for normal use cases but for stuff like this it complicates things.
I’m not bad at python. One of these days money permitting I’d like to get some of the LED’s and other necessary hardware and combine them with a couple 3 or 4 inch full range drivers a Raspberry Pi 4 and a HIFIBERRY AMP2 hat and maybe a small screen and build a small-ish semi-smart boombox for my son. He’s 12 and is starting to show an interest in actually listening to real music. If/when that happens I’m sure we can iron out a few kinks and probably create a few,lol!!!
@JasonLG1979 - awesome! Thanks for the modifications to
asound.conf
- definitely will try it out and probably merge it into a branch for others to use.Loving the collaboration in this thread! I learned a lot just reading through the conversation.
I kinda want to get some of these LEDs for my self now to add some bling to my stereo,lol!!! I’d just have to figure out what pins my dac hat uses so I could make sure to use different ones to control the LEDs. I’m fair at python so I could help with the coding bit. It would also be cool to be able to control 2 sets of LEDs for a stereo effect.
You have to add
snd-aloop
to a new line in /etc/modules and then reboot.It should be. Try this one I wrapped the default capture in a plug so it shouldn’t matter what an app asks for as far as sample rate format or channel count. Read the file and follow the instructions in the comments you may need to change the card numbers to make it work. You can test it by playing some audio and using
arecord -d10 -fdat -twav test.wav
and then playback the test withaplay test.wav
it should be a recording of what was played while it was recorded:I’d create a systemd unit file to run the python scripts as system services. Stopping the service should kill the script. Something like this might do the trick:
And then your event script becomes:
You’ll ofc have to test it and probably tweak it to make it actually work correctly. The above is just an idea.