eveldaweavel
Posts: 1
Joined: Thu Oct 11, 2018 11:40 am

Select audio playback device programmatically

Thu Oct 11, 2018 11:51 am

I'm using Raspbian Jessie and have a Google Assistant working using an input microphone and a speaker attached to the 3.5 socket. I also have a Bluetooth speaker which has been paired.

My question hopefully is quite simple (tried getting the answer from other articles but can't seem to figure out what to try):

On the desktop I can right-click on the volume control and pick my Bluetooth speaker and then my adapted Google assistant code can launch cvlc to play music on that speaker (the assistant voice still comes out of the 3.5 socket speaker) and it all works. I want to know how to do the right-click volume control selection from either the command line or even better python itself so that I can write code to tell my assistant to connect to the speaker and then play the song.

Most articles I read talk about switching from Analog to HDMI. But my choice here is to flick between Analog and one of a listed set of Bluetooth speakers which I've separately paired previously.

Quite new to Python and still a Pi novice, any help or pointers would be great.

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Select audio playback device programmatically

Thu Oct 11, 2018 1:25 pm

if you do "cvlc --longhelp" you will find the option to select audiodevice as a parameter to clvc

Code: Select all

      --alsa-audio-device 
      {default,null,pulse,sysdefault:CARD=PCH,front:CARD=PCH,DEV=0,surround21:CARD=PCH,
       DEV=0,surround40:CARD=PCH,DEV=0,surround41:CARD=PCH,DEV=0,surround50:CARD=PCH,   
      DEV=0,surround51:CARD=PCH,DEV=0,surround71:CARD=PCH,DEV=0,hdmi:CARD=PCH,DEV=0,hdmi:CARD=PCH,  
      DEV=1,hdmi:CARD=PCH,DEV=2,hdmi:CARD=PCH,DEV=3,hdmi:CARD=PCH,DEV=4,dmix:CARD=PCH,DEV=0,dmix:CARD=PCH, 
      DEV=3,dmix:CARD=PCH,DEV=7,dmix:CARD=PCH,DEV=8,dmix:CARD=PCH,DEV=9,dmix:CARD=PCH,DEV=10,dsnoop:CARD=PCH,
      DEV=0,dsnoop:CARD=PCH,DEV=3,dsnoop:CARD=PCH,DEV=7,dsnoop:CARD=PCH,DEV=8,dsnoop:CARD=PCH,DEV=9,dsnoop:CARD=PCH,
      -+++++ many more..
The whole bunch of possible values is taken from my laptop, I get similar list of ALSA devices if I run "aplay -L". So you should get a smaller list on the Pi.
So the idea is to find the correct value for your BT speaker and use that as an option, that should override the "default" setting.

Return to “Media centres”