-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raspotify - not connecting / not playing sound #314
Comments
A bunch of ALSA errors, that tells me that something is misconfigured or not configured at all.
|
@dtcooper This is were a wiki would come in handy. ALSA configuration can be a bit of dark art. |
Hi @JasonLG1979, Thanks for the reply.
|
Probably. |
Headless or with a desktop?
Basically what I'm asking is if your Pi is going to be a dedicated Spotify connect device? If raspotify/librespot is the absolutely going to be the only thing outputting sound? If so we can optimize the configuration for raspotify/librespot and we don't have to care about sharing the audio output.
Are you testing those services as a user or as system daemons? |
|
Will the output just be speech? |
That would explain why they work and raspotify doesn't. If you don't plan on using them there's no need to test them. But if you are it's going to be a bit of a dance to configure them so they gracefully yield to each other. Otherwise if you try to use more than one at a time you may get audio glitches caused by CPU spikes. It may not be a problem for a Pi 4 though, I don't know? The only Pi I have to play with at the moment is a Pi Zero but the Pi 4 is exponentially more powerful. |
Untested but I imagine you could just test them as root.
Then test whatever:
Then exit back to the pi user:
|
@JasonLG1979 I’ll give it a shot. May be worth a fresh install of Raspotify looks like |
@JasonLG1979 the Alexa output will just be speech, correct. I would love to have them both running at the same time since this project is for a Magic Mirror, but I’m not sure how feasible that is with all these alsa issues. |
It shouldn't be hard. If the output is just speech then it really doesn't matter much about the sound quality of the speech. Meaning we can optimize the output for raspotify. Speech is pretty narrow bandwidth compared to music. Resampling it to what raspotify puts out (16bit 44.1 k) even if needed isn't going to affect it in an audible way. If the Alexa bit has hooks we can even make it so raspotify is temporarily muted while Alexa speaks by giving raspotify a separate software volume control. Basically Alexa fires a hook script before it speaks that mutes raspotify and then when it's done speaking it fire another script that unmutes raspotify. |
That would be awesome. The Alexa module does have hooks, I know that because I’m trying to use an addressable LED strip to indicate its “listening” and “speaking” states. However, the Alexa files are all .cpp and I’m pretty new to this so I don’t know how to integrate python scripts into those files. I also use an audio-reactive application to sync up the LED strips when music is playing from the Pi. My ideal state is having the LED visualization while music is playing, but if the wake word model of Alexa is activated, it mutes Spotify and switches to Alexa AVS as well as switches the LED strip to the Alexa visual indicator. |
I was hoping to keep it simple with a bash script since all we'd be doing is muting and unmuting volume. But if you can hook a python script you can just use subprocess to fire off the commands.
That should be possible. I can help with the ALSA plumbing but I don't use alexa and I don't have any of the hardware, so the rest you may ultimately be on your own, sorry. |
I would start with a fresh install and then we can step though getting a good ALSA config. Then you can install alexa and raspotify. |
OK this will get you 2 separate inputs and volumes (one for spotify and one for alexa) and a master volume and default input. Simplified (not showing all the resampling and software mixing bits) it looks like this: Everything is resampled to 16 bit 44100 which is what raspotify/librespot outputs anyway so in the case of raspotify/librespot no resampling will actually be done. I don't know what your input looks like so we may have to tweak it if it's on the same device? The device names are the same as the control names (spotify and alexa) so any config where you need to specify a device and/or a control they would be named the same. The master volume is named PCM because that's the convention for the name of the master volume control of a device. Most programs if you do not or can not specify a volume control will use the PCM control. Librespot does not keep track of outside changes to the volume if you use ALSA volume control so in your case until they fix that I would use the builtin software volume control and only use the "spotify" ALSA volume control for muting or dropping the volume when alexa speaks. To get raspotify to use the spotify output add
|
There will be about 1 sec of audio latency because of the buffer so anything used to control LED's may need to take that into account depending on how it's implemented to keep the audio and LED's in sync. |
You can test each output with:
It will be loud (the default volume I believe is 80% ?) so turn the volume down on whatever your sound card is connected to. If whatever your sound card is connected to does not have a volume control you can use the |
This is awesome work. I've been out of town for the last few days, but I'll be back tomorrow so I'll definitely give this a test. Do I need to create this in a new file? (asound.conf). Because I have created an ".asoundrc" file that has a similar JSON-type look for the audio outputs. It only specifies system audio though, not specific application audios. I'm wondering if I should just delete that and use this? |
I also have a USB microphone (card 1, device 1) - is this something I should specify in asound.conf? |
Yes create
If alexa is the only thing that will be using the mic and you can directly specify the mic somewhere in the alexa audio config you shouldn't have to worry about it. Just let alexa have exclusive access to the mic. Otherwise we can make the virtual |
You don't have to route everything though program specific virtual devices. If not specified a program should use |
Is this going to be different depending on which card/device the audio outputs are on? |
That's not even needed most of the time. It's just saying channel 0 from dmix goes to channel 0 on the sound card and channel 1 goes to channel 1 on the sound card. Most stereo cards don't have a problem but some 5.1 and 7.1 drivers screw up channel mapping. |
You could switch it and the left channel would come out of the right speaker and the right channel would come out of the left speaker. |
If you have a 5.1 or 7.1 card we can spread out 2 channels to fill them. Basically left would get duplicated to all of the left channels and right to all of the right channels and then the center and sub channels would be mono (50% right + 50% left). there wouldn't be any surround sound effects but at least you'd be using all your channels. If you wanted to get fancy though you could probably measure the distance from each speaker to your listening position and calculate the needed delay to make sure everything hits you in phase at your listening position. But that's probably overkill. |
I tried both audio outputs and got this error message each time: Playback device is spotify |
Ok. You said your playback card is 0 so let's try to find the device number, and make sure your card supports 16bit 44.1k.
Of if that doesn't work try this:
The output I want to see should look something like this:
It will tell us what your sound card is capable of. It will also tell us the device number. (the device number being the one that works) |
It's most likely one of 3 things:
Changing format and sampling rate isn't a huge deal though. But if you have to resample you'll want to install and enable a decent resampling lib. The default sounds like garbage and resampling is going to use a little more CPU. |
Playing WAVE '/usr/share/sounds/alsa/Front_Right.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono Here's the output of "aplay -Dhw:0,0 --dump-hw-params /usr/share/sounds/alsa/Front_Right.wav" |
Mine's some Chinese knock off,lol!!! |
@JasonLG1979 how can I see what apps are using the mic? I've turned off the audio reactive python code, but it still seems to be hogging the mic for some reason. |
With a single mic though you're going to have trouble with Alexa hearing you when you speak when there's music playing or any other background noise. You might want to look into an array mic.
|
@JasonLG1979, yeah I've realized that limitation.. I'll probably upgrade eventually to a good mic. Here's what lsof tells me:
Not sure what these are... |
Well it's a python3 program? Not very helpful,lol!!! It's run as root so maybe a system service of some kind? You can kill it and see what happens:
|
I personally would have not started with the desktop version I would have started headless and then configured the audio and then installed and configured raspotify and whatever other audio bits you wanted and then installed alexa and then what ever UI you needed for the magic mirror stuff. You're going to be fighting with the desktop environment for control of the audio devices the whole way otherwise. |
It also makes it a lot easier to troubleshoot if you work from the bottom up instead of the top down. |
Yeah may be worth a clean install on a headless setup. I’ll update once I’m
back at the Pi again. Thanks again for walking me through all this!
…On Sat, Oct 31, 2020 at 7:20 PM Jason Gray ***@***.***> wrote:
I personally would have not started with the desktop version I would have
started headless and then configured the audio and then installed and
configured raspotify and whatever other audio bits you wanted and then
installed alexa and then what ever UI you needed for the magic mirror
stuff. You're going to be fighting with the desktop environment for control
of the audio devices the whole way otherwise.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#314 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AROJEBF25P7IHAJW3I7ZNK3SNSST5ANCNFSM4S4Z3WIA>
.
|
No problem, this stuff is my jam,lol!!! I'm learning stuff along the way too!!! |
In the mean time I have an extra SD card so I can work though everything up to installing and configuring raspotify and bluetooth if you want and work on a new |
Wow that would be extremely helpful. I would appreciate it very much, but don’t feel obligated to of course. The three audio applications I’m trying to configure together are Raspotify, the Alexa AVS service, and the DancyPi-Audio-Reactive LEDs. The latter two use both the mic and the speaker while Raspotify only uses the speaker. That should be it in terms of overall summary of the configuration. The speaker is default card 0 and the mic is card 1. Thanks again man. Looking forward to working on it!! |
I’ll make a diagram for it when I’m home. |
I'm guessing DancyPi-Audio-Reactive LEDs is what was hogging your mic then. Looking at the source code it just wants to use the "default" device so we can just do what I said earlier. The install script looks like it will just clobber an existing |
I'd say install DancyPi-Audio-Reactive LEDs 1st thing that way if doesn't screw up our
That totally will not due at all... |
In your case LED controls that worked of the output would be better then working off the mic. Something like a copy of the output to a pipe file, and then have your python script watch the file and process data as it comes? |
That would be great as it would free up the mic to only be used for Alexa. No idea how to implement that though. Maybe there’s another repository somewhere that uses output rather than mic feedback. |
Found this thread on how to record audio output: https://superuser.com/questions/1194750/how-to-record-the-audio-output-on-raspbian Perhaps, this can be used with the |
If you can figure out how to get DancyPi-Audio-Reactive LEDs to listen to another input besides default you could just copy the output from default with the I can only offer guesses as I don't have the hardware to test with. |
Another approach could be to split the output so it goes to your USB DAC and the analog out. AFAIK the analog out is a PWM maybe even the same one that DancyPi-Audio-Reactive LEDs already drives? |
Yeah, let me reach out on their issues log and see if there's any way to not use the mic output. Analog out? How does that work? |
Also this worked like a charm. Tested it from 15-20 feet away and it was good. |
Got me,lol??? I'm not very versed in the raspberry pi audio hardware. I never use it. It sounds like garbage,lol!!! Anyway, this will get you a duplex'd default device with an output volume control named PCM and a mic volume with up to 20dB of boost named Capture, a spotify output device, bluetooth output device, and a duplex'd alexa device all with their own output volume. All outputs (playback) will accept whatever as far as bit depth and sampling rate but anything not S16_LE 48k will be resampled.
All the controls are done in software so you'll have to speaker-test/arecord all of them before they show up in alsamixer but after you'll have something that looks like this: |
In my mind ideally the mythical LED controls would listen to the default output. I'm not sure how you can do that? |
@JasonLG1979 Awesome!! I'll try this out in a bit. Currently trying to see how to integrate Python scripts into the .cpp files for Alexa. Yes, agreed. That'll have to be something I research a little bit more to see if anyone was able to do that. |
.ccp is C++ |
I haven't read the docs but in my mind if you wanted to use python I'd start by using flask to create a REST api to control your device and then hook the skills into that. |
@JasonLG1979 ahh gotcha. I was thinking to write the Python scripts in some shell scripts and then just run those using system() command in C++. |
Hi all, one issue I'm having is Raspotify not playing any sound when it does connect. Here is what I pulled from the log, it looks like this is where the issue arises:
Oct 23 12:01:00 raspberrypi librespot[3057]: [2020-10-23T17:01:00Z INFO librespot_playback::player] Loading with Spotify URI spotify:track:1McVhmCk8l07LIIdlIpqTF
Oct 23 12:01:00 raspberrypi librespot[3057]: [2020-10-23T17:01:00Z INFO librespot_playback::player] (188766 ms) loaded
Oct 23 12:01:00 raspberrypi librespot[3057]: ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
Oct 23 12:01:00 raspberrypi librespot[3057]: [2020-10-23T17:01:00Z ERROR librespot_playback::audio_backend::alsa] Alsa error PCM open ALSA function 'snd_pcm_open' failed with error 'ENOENT: No such file or directory'
Oct 23 12:01:00 raspberrypi librespot[3057]: [2020-10-23T17:01:00Z ERROR librespot_playback::player] Could not start audio: Alsa error: PCM open failed
Oct 23 12:01:00 raspberrypi librespot[3057]: ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
Oct 23 12:01:00 raspberrypi librespot[3057]: [2020-10-23T17:01:00Z ERROR librespot_playback::audio_backend::alsa] Alsa error PCM open ALSA function 'snd_pcm_open' failed with error 'ENOENT: No such file or directory'
Oct 23 12:01:00 raspberrypi librespot[3057]: [2020-10-23T17:01:00Z ERROR librespot_playback::player] Could not start audio: Alsa error: PCM open failed
Oct 23 12:01:00 raspberrypi librespot[3057]: ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
Oct 23 12:01:00 raspberrypi librespot[3057]: [2020-10-23T17:01:00Z ERROR librespot_playback::audio_backend::alsa] Alsa error PCM open ALSA function 'snd_pcm_open' failed with error 'ENOENT: No such file or directory'
Oct 23 12:01:00 raspberrypi librespot[3057]: [2020-10-23T17:01:00Z ERROR librespot_playback::player] Could not start audio: Alsa error: PCM open failed
Oct 23 12:01:00 raspberrypi librespot[3057]: thread '' panicked at 'called
Option::unwrap()
on aNone
value', playback/src/audio_backend/alsa.rs:103:19Anyone have any idea what this could be?
The text was updated successfully, but these errors were encountered: