Play sound locally at Pi Gateway on event

Started by Stark, December 12, 2015, 01:41:21 AM

Stark

The purpose of this would be to get notifications without the need for the browser to be open. An event sound would be played via speakers attached to the line out socket of the Pi. It could be used to provide alarms or general information on the network delivered audibly. "bing bong...Motion detected in Zone 1" etc.

Currently my programming is limited to bash and python so was thinking of calling a script in event to play the sounds. Does anyone have advice on how this would be best implemented?



HeneryH

On AdaFruit's Pi page there are several sound cards.  Take a look at https://www.adafruit.com/search?q=sound&b=1

I was looking at some of the boards with pre-recorded sound clips that can be triggered.

Felix

Short of having a speaker that can play actual sounds, I'd like to mention that with the newly released MightyHat there is the option to have a piezo buzzer attached that can trigger sounds. The sample sketch I posted can play 1 or 2 short beeps when the serial token "BEEP" or "BEEP2" are sent to the MightyHat from the Pi side. Obviously you can implement other types of tones, but a piezo buzzer is not a true speaker :)

Stark

Thanks for the hardware info. I couldn't resist the MightyHat  8) so have placed an order. Locals beeps would be good alert.

Was thinking though that the Pi on the gateway is more than capable of complex sounds and with an amplified speaker suitably loud.

So I will tinker with the gateway scripts to see if they can call say an .mp3, instead of the current SMS, email event options. Then have a network that can talk to me.

Can only do python and bash so need to implement the node.js bit of code. Will report back if/on success!

Stark

Solved with relative ease by installing the play-sound package via npm. Saved me messing around with separate scripting.

In metrics.js added this include:
var player = require('play-sound')(opts = {});


Then created new event with this in metrics.js:
player.play('foo.mp3', function(err){});


Had to change the default audio output on the pi to the headphone jack (that is where my powered speaker is) and mplayer may be a dependency.

Now have "bing bong" (or any mp3 for that matter) from the Pi Gateway on an event.

syrinxtech

@Stark,

Thanks for the info.  My friend and I were just saying how nice it would be to play the sounds from the PI instead of having to integrate a hardware buzzer into every sensor.

I found more info on "play-sound" here:

https://www.npmjs.com/package/play-sound

duane1

Interestingly enough, I was in the same situation.  I ended up using an old cell phone and now it is one of my favorite features for my garage door and mail notifications.  You might have a look at my post here in the Pi Gateway forum titled "Repurpose an old cell phone to play sounds (ie "speak") for the Gateway" https://lowpowerlab.com/forum/index.php/topic,1583.0.html

The cell phone just needs wifi; no cellular service needed.  Pretty easy to set up with two or three Apps from the Google Play Store, so I believe it will meet all your requirements.  BTW, you can change Tasker to just do beeps or play a MP3 or several other actions.   In addition to easy to implement, inexpensive, and professional looking, the one characteristic I really like is the ability to put one or more of these anywhere in my house.

- - - Duane