naztronaut / dancyPi-audio-reactive-led

Real-time WS2812b LED strip music visualization using Python and the ESP8266 or Raspberry Pi.
https://www.easyprogramming.net/raspberrypi/audio_reactive_holiday_leds.php
MIT License
247 stars 86 forks source link

Microphone not detected when quitting visualization.py #26

Open nielsotto opened 4 years ago

nielsotto commented 4 years ago

Hi When running the visualization.py with an effect, and then hitting ctrl+z to quit, I cannot run the visualization again. Gives me this error Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 924 ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device' ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory ALSA lib conf.c:5036:(snd_config_expand) Args evaluate error: No such file or directory ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM bluealsa ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device' ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory ALSA lib conf.c:5036:(snd_config_expand) Args evaluate error: No such file or directory ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM bluealsa 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 Traceback (most recent call last): File "visualization.py", line 368, in <module> microphone.start_stream(microphone_update) File "/home/pi/dancyPi-audio-reactive-led/python/microphone.py", line 14, in start_stream frames_per_buffer=frames_per_buffer) File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 441, in __init__ self._stream = pa.open(**arguments) OSError: [Errno -9996] Invalid input device (no default output device)

If I take out the USB soundcard and plug it back in, I'm then able to run the command and start the lights again.

Not that I have any idea what it could be, maybe there could be a function re-adding the sound device when running the visualization? I'm running on the Raspberry Pi 4 with power from a USB in my computer. Side note: If I don't put a resistor between the Pi and the LED strip, the first two LED's will blink white non-stop.

naztronaut commented 4 years ago

You should quit the script with ctrl+c instead. Ctrl+z doesn't stop the script, it exists and I think it keeps it running as a process in the background and may become unresponsive. From the looks of it, it makes your sound device unresponsive. Let me know if ctrl+c works better.

The need for a resistor could be a power issue. Are you using a standard WS2812b strip? I haven't run into that issue and haven't seen anyone else mention that either.

nielsotto commented 4 years ago

ctrl+c works. Thanks! That's me being new to this. I notice the LED stays on when shutting down. Could the off.py script run when shutting visualization.py off?

Sorry, I'm using the WS2813. Should be an updated model. No idea if the electronics are different

naztronaut commented 4 years ago

Glad that works! Everyone has to start somewhere, I used to kill my scripts with ctrl+z when I first started :)

The off.py piece is possible to do by capturing the ctrl+c signal.

I'm making some modifications to release for a December video (christmas/winter break theme) so I'll see if I can add that functionality, no promises though.

And it looks like for WS2813 LEDs, they require you to use a resister and capacitor/ Found this discussion about it: https://www.eevblog.com/forum/beginners/calculating-resistance-needed-for-w2813-led-strip/

This is just from a quick Google search. I'm not familiar with that strip but if you search for solutions and find something, let me know. It may be helpful for others who run into the same issue.