Closed artistro08 closed 9 years ago
You can try using http://alsa.opensrc.org/How_to_use_softvol_to_control_the_master_volume for a virtual mixer in alsa
softvol works in bash (speaker-test) but in pyalsaaudio doesn't seem to work. Tried to change volume with webpage and with alsamixer. Strangely volume is changed in alsamixer when changed in webpage. Can't use softvol device with -D. Using -m also doesn't work. What really strange is that I can change the volume with slightly modified playwav.py (example for pyalsa) but when I use exactly the same parameters it's not working with sp-connect. I think it has to do with docker but not sure. Is there an easy way to use spotify-connect without docker or chroot?
Using the spotify app I can control the volume of the DAC. However it goes silent at about 80% or so. Is there a way to tune this so that you can control the volume better?
so is the volume quiet or really silent at 80%? Maybe first you can try to compare by opening alsamixer in shell and then change volume in app. If the levels are identical, you could change the source code to your needs, but sounds strange that it's silent at 80%.
@maumi if you have a rpi2 (or armv7 device) you can use the hardfloat libspotify_embedded, rpi1 you have to use a chroot or docker @DieterKoblenz it's quiet at 0%-80%?
@Fornoth yes, from 0 - ~80 its empty. In alsa I can change the volume without a problem to the level I want but on the spotify app this is difficult because I have to work in the 20% range.
I've checked again and if I turn up the volume on my amp it is not completely silent at 80, it stops at 51 or so, and then it is completely silent.
Habe you tried to open alsamixer in shell and then change volume in spotify APP or web Browser to 50% and look if it's also at 50%? If it's at 0% it should be a scaling Problem in your case and easy fixable in code for you.
I tried using softvol. for some reason Connect is changing the vol on the default RPi card. I keep specifying the device to use and it keeps controlling the volume on the default card. If i do "speaker-test -Dsoftvol -c 2 -twav" it plays on the right mixer.
@DieterKoblenz so your volume problem is solved? @artistro08 have you tried to overwrite the default device with softvol?
No, I'm still trying to find a way to change the way spotify handles the volume. To make it clear, I would like spotify's (0-100) scale to control alsa's (50-100) volume.
Not sure if thats even possible
you could try to change line 151 in console_callbacks.py it is now: mixer.setvolume(int(volume / 655.35)) to: mixer.setvolume(int(50 + (volume / 655.35) / 2 ))
untested, but should do what you want to achieve.
@maumi Yes I did. I'm thinking if i disabled the onboard sound card it'll work
here's what happened when I used softvol:
root@Maiku:/app# cd /app && python main.py --username artistro08 --password <password> --name Maiku --bitrate 320
Traceback (most recent call last):
File "main.py", line 9, in <module>
from connect import Connect
File "/app/connect.py", line 8, in <module>
from console_callbacks import audio_arg_parser, mixer, error_callback, connection_callbacks, debug_callbacks, playback_callbacks, playback_setup
File "/app/console_callbacks.py", line 16, in <module>
audio_arg_parser.add_argument('--mixer', '-m', help='alsa mixer name for volume control', default=alsa.mixers()[0])
alsaaudio.ALSAAudioError: No such file or directory
I'm really no expert with alsa but seems that your device has no mixers. Have you tried speaker-test with default device and changing volume while running? After a reboot it seems that the file with softvol js only loaded when you use the alsa device, so you need to start speaker-test once before starting spotify. You can easily see if mixer is loaded by calling alsamixer and look if mixers are present. Another thing: do you have a pi2 and get it running without chroot and docker? If yes, could you help me a little with that
I do have a Pi2. also, the device did have a mixer enabled. it wouldn't recognize that. As far as getting it running without chroot and docker, I upgraded to Jessie and installed the libraries i needed i to run via pip. then I put the libspotify-embedded-shared.so in the libs directory and ran accordingly
thanks, got it working :-) I took the wrong library (Rocki). Now I finally have softvol with spotify-connect. If you are interested in what I did: my .asoundrc is very simple, pcm.softvol { type softvol slave { pcm "default" } control { name "Master" card 0 } }
So I don't override the default sound output. Next important step is to get the correct version of alsaaudio. you need to get a version from up to 0.8, so pip install pyalsaaudio>=0.8 Otherwise the argument device in PCM won't work. Finally, you need to change the line in console_callbacks.py from card = args.device) to device = args.device). When you now start your main.py (only get it working with this, not with docker or chroot) with -d softvol it should work. Hope could help someone.
You sir are a genius! got it working with a little more advanced config since i disabled the on-board sound card.
/etc/asound.conf:
pcm.!default {
type plug
slave.pcm "softvol"
}
pcm.softvol {
type softvol
slave {
pcm "plughw:1"
}
control {
name "Master"
card 1
}
}
ctl.!default {
type hw
card 1
}
works like a charm! gonna run this along with shairport :)
thanks ;) glad to hear it's working. maybe you could help me out a little. I also use shairport-sync and spotify together. But because spotify steals the audio device I kill spotify when shairport wants to play. Before I could easily do it with docker (docker start/stop) but now I tried to run spotify with daemontools. But I couldn't kill it this way. So quick and dirty for now: start it with script and kill it with sudo killall -TERM python But I know it's far away from a good way to handle it.
I've actually figured out a workaround for it. there's a session control that allows you to run commands before and after shairport-sync starts. it should be in the config file under /etc/shairport-sync.conf. i have scripts setup to kill spotify-connect when airplay is running and start it after its done.
I've doing the same. Got it working now. I think issue can be closed now.
@artistro08 I would like to run it without chroot or docker When I launch main.py, I still have got a error ending by " File "/usr/lib/python2.7/dist-packages/cffi/vengine_cpy.py", line 149, in load_library raise ffiplatform.VerificationError(error) cffi.ffiplatform.VerificationError: importing '/root/connect/pycache/_cffi__x8b237976x2c265354.arm-linux-gnueabihf.so': libspotify_embedded_shared.so: cannot open shared object file: No such file or directory" Which file do you use to make it work? Thank you!
@balbuze Should only work on pi2. You need to copy libspotify from armhf (spotify Ressources) to /usr/lib/ And you need to CD into The folder with main.py
What he said. its just dependencies is the main reason why it wont run right off the back.
I'll add an option soon for volume scaling
awesome! can't wait.
Maybe you also could change code like in my comment. But this will break running Version with updated code. Needs to rerun pip then with alsaaudio>=0.8 but only with this change you can select soft devices.
This is a great conversation, helped me a lot to set my RPI1B+ with both Shairport and Spotify connect (even killing the process when the other takes over). However I cannot get the softvol device to be operational.. Have you got a blog or some detailed instructions to see what I can be missing? Thanks!
You mean you couldn't change the volume with spotify?
Exactly @maumi. By the way the -D parameter didn't stick (if I add it I get an error). Everything else is in there, I think. I am running on a Hifiberry DAC+ output, but I set it as device 0 (disabled the onboard sound). I see the playback_volume (event?) is reported back to the process but there is no change in the output. As I'm using an old remoteless amp that would be a blessing to manage volume via software.
Afaik hifiberry dac has no softvol and only hardware volume.
@maumi you gave me a great tip. I went to their site and the instructions at https://support.hifiberry.com/hc/en-us/articles/205377202-Adding-software-volume-control are meant for softvol with the Hifiberry.. I tried them and speaker-test recognizes the "hifiberry" device but I can find no way to active it in spotify-connect-web.. Seems like I'm almost there..
The problem seems to be that a change is necessary in mpd.conf for this to work.. And afaik spotify- connect-web does not use mpd at all. So dead end for now.
Should work when it's working with speaker test and if you could change volume in alsamixer. Take a look in other issues like #37 to see how to set hifiberry in spotify.
That was another good tip, but I think the issue is .. That I cannot get to change the code below in console_callbacks.py.
If I change card
for device
(what does make sense as the softvol setting is not really a CARD), the process will fail out immediately. As reported, the new device works ok in speakertest but couldn't find it with F6 in alsamixer. Maybe related?
device = alsa.PCM(
alsa.PCM_PLAYBACK,
card = args.device)
You need to read the issue 37 in detail. You need a newer version of alsa! 0.8 Have you tried alsamixer -c1 ?
I read it and the only things I found different were the ones below. Thanks for your help and sorry for my bad linux!
sudo pip3 install pyalsaaudio>=0.8
(it apparently upgraded ok)sudo apt-get --only-upgrade install python-alsaaudio
but it says it's at 0.7.1 and no newer version exist (on armhf)
Maybe I have to upgrade some other alsa package?I meant console_callbacks.py Why do you use python3? Why not python2? Sudo pip install instead of pip3
I see. At some point the pip
command didn't work and I must have installed the python3 version. Anyway, I could easily uninstall python3 version of pyalssaudio (0.8.2), just in case.
Trying sudo pip install pyalsaaudio>=0.8
didn't work. What did work was pip install --upgrade pyalsaaudio
. Now I'm on 0.8.2 for python2 afaik (pip list
says so). Then, rebooted.
speaker-test -Dhifiberry
works ok.aplay -L
shows hifiberry as a device with no detailsalsamixer -Dhifiberry
won't work, it indicates "invalid CTL"pi@raspberrypi:~ $ /home/pi/spotify-connect-web.sh --name rpiConnect1 --username XXX --password XXXX --bitrate 320 --device hifiberry
Traceback (most recent call last):
File "main.py", line 9, in <module>
from connect import Connect
File "/usr/src/app/connect.py", line 8, in <module>
from console_callbacks import audio_arg_parser, mixer, error_callback, connection_callbacks, debug_callbacks, playback_callbacks, playback_setup
File "/usr/src/app/console_callbacks.py", line 21, in <module>
device = args.device)
TypeError: 'device' is an invalid keyword argument for this function
I'm no expert with chroot. But I think it's sth. like a pre-build system. So the version of pyalsaaudio is taken, which was used when built. Try to use docker, but you then need to change requirements.txt pyalsaaudio>=0.8
I see what you mean @maumi I'll either reinstall this portion or the whole SD card. Thanks a lot.
Hey Guys, I read this thread and it helped me out configuring my RPiZero with spotify-connect-web and pHAT DAC. For those who cant use softvol (from maumi's post) ... try copying your asound.conf to the APP directory (chroot-folder/usr/src/app) of spotify-connect-web-chroot. Then starting it with --playback_device softvol works like charm for me.
@blubhimself i have the same hardware but i always get the error ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM softvol
Please post your asound.conf thx!
Are you using The chroot version, habe copied asound in chroot and --playback-device as Parameter?
@tatoosh my asound.conf looks like this
pcm.softvol { type softvol slave { pcm "default" } control { name "Master" card 0 } }
Than copy asound.conf in your spotify-connect-web-chroot/etc folder and start the server using --playback_device softvol
copy asound.conf in your spotify-connect-web-chroot/etc
Thx @blubhimself - it worked now, you helped me a lot.
I wrote a plugin for Volumio2 (https://volumio.org) that installs in one click spotify connect -web on RPI1, RP2 or RPI3 and Sparky (and probably other armv6 and armv7 devices). It use standard version or chroot version depending your device through a detection. You just have to enter your credentials. It works now pretty well. But in the chroot version with software mixer I get no sound... I followed this thread, but I can't make it work. When I change volume in Spotify, I see the volume changing in alsamixer... Any idea ? If you want to test the plugin : https://github.com/balbuze/volumio-plugins/tree/master/plugins/music_service/volspotconnect
@Fornoth Has this been finally implemented or are we still to follow these procedures to get software volume? Thanks,
Rafa.
@RafaPolit sorry for the really late reply, but this is something you'll have to do at the ALSA level, because I have no plans of implementing it. Although if somebody send in a pull request for it, I would be fine with that
this is more of a question. will software side volume be used in future releases? Just asking. My current DAC doesn't support alsamixer's gui. so this would be dope if you could