0

I am working on a Python script that lets Raspberry Pi 4 play audio announcements (mp3 format) at specified times. I am using the Python OS library to send the play audio commands to system.

The aplay -l command gives the list of the available audio devices, mine shows HDMI and analog (does not show Bluetooth speakers).

Then I pick the one I want (analog in my case), and specify the output this way:

AUDIODEV=hw:0,0 play audio.mp3

The question is: is there a way to send output to the paired Bluetooth speaker? I do not want to change the default audio device to Bluetooth. Ideally, I want the default to still be HDMI but only send these commands to Bluetooth speaker.

Any suggestions on how to achieve that?

Greenonline
  • 2,740
  • 4
  • 23
  • 36
Bahi8482
  • 111
  • 4
  • Two good references for doing this is https://raspberrypi.stackexchange.com/a/116843/121848 and https://gist.github.com/actuino/9548329d1bba6663a63886067af5e4cb – ukBaz Apr 06 '22 at 07:08
  • @ukBaz thank you. My goal is to find a bluetooth device name to use with AUDIODEV=. I will study the resources you sent and update my post if I find a solution. – Bahi8482 Apr 06 '22 at 10:29
  • Are you running pulseaudio server? – ukBaz Apr 06 '22 at 10:45
  • @ukBaz yes. I am actually new to rpi (2 months) but I believe that my current rpi OS uses pulseaudio not ALSA. – Bahi8482 Apr 06 '22 at 18:50

1 Answers1

1

This worked for me:

sox -v 1.5 example.mp3 -t pulseaudio bluez_sink.00_00_00_00_00_00.a2dp_sink #this will play the file into the bluetooth speaker (replace the name after pulseaudio with the output from 'pacmd list-sinks | grep -e 'name:' -e 'index' -e 'Speakers' ).

These steps worked for me to connect pi (zero and 4) with BT speaker: https://gist.github.com/actuino/9548329d1bba6663a63886067af5e4cb#pair-and-connect

Bahi8482
  • 111
  • 4