play soundmessage with BT

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
johnnie
Posts: 37
Joined: Wednesday 10 December 2014 21:08
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

play soundmessage with BT

Post by johnnie »

Hi guys, hopefully somebody can point me in the right direction.

I've installed an BT dongle with the help off: https://www.domoticz.com/wiki/BTAudio, and this working perfect, thnks!

When I launch the command from cli, it's working like a charm:

Code: Select all

mplayer -ao alsa:device=bluetooth /media/alarm_ingeschakeld.mp3 -softvol -volume 30 -af resample=16000:0:0
Then I've integrated it in a bash script named: alarmaanmp3. This script contains:

Code: Select all

#!/bin/sh
mplayer -ao alsa:device=bluetooth /media/alarm_ingeschakeld.mp3 -softvol -volume 30 -af resample=16000:0:0
When I run this from cli, it's also working:

Code: Select all

/home/pi/domoticz/scripts/alarmaanmp3
Now comes the part I got stuck, I've made a dummy swith and put the command in the "on" part of it (did the same for "off", but this has the same results):
messagealarm.JPG
messagealarm.JPG (37.25 KiB) Viewed 2122 times
In the log I see the script got activated, but no sound.

After this I've changed to LUA and made the script, named: script_device_alarmmessages.lua.
This script contains the following code:

Code: Select all

commandArray = {}
  if (otherdevices['AlarmActive'] == 'On') then
    os.execute('/home/pi/domoticz/scripts/alarmaanmp3')
    print('Alarm message -aan- verstuurd naar BT-speaker')
  end
return commandArray
I can see the print output in the log, but also here no sound.........

Hopefully somebody can help me with this puzzle.....

btw: I'm running Version: 2.3530, Build Hash: 9eef872, Compile Date: 2015-11-01 11:41:18
Raspi 3B+; Razberry zwave; zigbee; lots and lots of sensors
User avatar
nayr
Posts: 354
Joined: Tuesday 11 November 2014 18:42
Target OS: Linux
Domoticz version: github
Location: Denver, CO - USA
Contact:

Re: play soundmessage with BT

Post by nayr »

try giving it the full path to mplayer, run 'whereis mplayer' to find its location.

I take it your scrpt is executable? chmod +x /home/pi/domoticz/scripts/alarmaanmp3

you might try using #!/bin/bash instead of sh, I am finding alot of little arm boxes that come with a default shell that sucks at scripting.
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
johnnie
Posts: 37
Joined: Wednesday 10 December 2014 21:08
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: play soundmessage with BT

Post by johnnie »

Hi nayr,

Thnks for you're prompt response, script was indeed executable but checked it just to make sure.
Found mplayer and placed full path in the script, also changed it to bash, now I've got:

Code: Select all

#!/bin/bash

/usr/bin/mplayer -ao alsa:device=bluetooth /media/alarm_ingeschakeld.mp3 -softvol -volume 30 -af resample=16000:0:0
Still no luck.

A friend of mine maringo, also on this forum, thinks it got something to do with "rights". As mentioned earlier I've completed the setup from wiki under the user "pi". Is this oke, or had I done it under "root"?
maringo also suggested to run: "sudo mplayer" instead of "/usr/bin/mplayer".
But when i do this i get the folowing output:

Code: Select all

MPlayer svn r34540 (Raspbian), built with gcc-4.6 (C) 2000-2012 MPlayer Team

Playing /media/alarm_uitgeschakeld.mp3.
libavformat version 53.21.1 (external)
Mismatching header version 53.19.0
Audio only file format detected.
Load subtitles in /media/
==========================================================================
Requested audio codec family [mpg123] (afm=mpg123) not available.
Enable it at compilation.
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 16000 Hz, 1 ch, floatle, 129.4 kbit/25.27% (ratio: 16175->64000)
Selected audio codec: [ffmp3float] afm: ffmpeg (FFmpeg MPEG layer-3 audio)
==========================================================================
[AO_ALSA] alsa-lib: pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM bluetooth
[AO_ALSA] Playback open error: No such file or directory
Failed to initialize audio driver 'alsa:device=bluetooth'
Could not open/initialize audio device -> no sound.
Audio: no sound
Video: no video


Exiting... (End of file)
Raspi 3B+; Razberry zwave; zigbee; lots and lots of sensors
johnnie
Posts: 37
Joined: Wednesday 10 December 2014 21:08
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: play soundmessage with BT

Post by johnnie »

Find the solution with the help of maringo, what dit the trick?

First I created a root password with the help of: "sudo passwd root" procedure and logged in under root with the newly created password.
Then I created the file .asoundrc under the directory root containing:

Code: Select all

## Redirect all sound via Bluetooth
pcm.bluetooth {
        type bluetooth
        device AA:BB:CC:10:20:30 # change this MAC address to your speakers address
        profile "auto"
}
Then I've put sudo in front of the comment in the scripts I've created before. They are now (btw I've created one for "off" and one for "on"):

Code: Select all

#!/bin/bash

sudo /usr/bin/mplayer -ao alsa:device=bluetooth /media/alarm_ingeschakeld.mp3 -softvol -volume 90 -af resample=16000:0:0
Then rebooted the pi and yes it's now working with the dummy switch!

Thank you all, and hopefully somebody else can benefit from this thread as well.
Raspi 3B+; Razberry zwave; zigbee; lots and lots of sensors
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest