WebAudio CLI Client

Apologies if in the wrong topic, but thought this is a good place to start.

Has anyone put together a simple CLI WebAudio client for playing multimedia? I imagine it would be relatively easy to create a small Java App that registers as a webaudio client, receives the events, and plays audio using local sound subsystems, but not sure if anyone has attempted this yet. If not, could someone point me to places in the code to get started? I’m aware of the event endpoints here, but would appreciate any other tips anyone could give me to get familiar with the relevant code.

Background

I have tried all the standard multimedia options… Kodi is pretty touchy (some installs I get nulls when trying to play audio on them, even though all the configurations seem to be the same as those where the audio is working); Squeezebox doesn’t work all that well. The playlist in the squeezebox server gets “stuck” and won’t play the notifications consistently on the clients (also the 20 second limit on the stream is annoying). If either of these worked flawlessly, I wouldn’t mind, but both of these options are also a lot heavier than what I need, given the lack of reliability in each of them.

This leads me to webaudio which is 100% reliable. No it isn’t synchronized across clients, but I’m not looking for Whole House Audio either, just a reliable way to play sounds / notifications and TTS alerts. Since webaudio is very reliable, I figure I can make a super low-footprint client that just listens to the correct API calls and plays something on the working sound subsystem.

If creating a standalone webaudio client doesn’t sound like the right answer to you, I’m all ears on options.

Thanks for the suggestions!

1 Like

Hello Brandon
I just use playSound in a rule.

rule "mqttmessagechanged"
when
    Item alertboxmsg changed
then
    if (alertboxmsg.state == "") return;
    if (alertboxmsg.state == "text message received"){
        if (now.getHourOfDay() >= 06 && now.getHourOfDay() < 23){
            playSound("textmessage1.mp3")
        }
    }
end

I’ve had some real problems trying to get OpenHAB to play sounds but above works thru a tablet which has habpanel running on it. (and with webaudio set as default in my system configuration, I guess the tablet provides a sink) I also have used a blue tooth dongle and speaker but didn’t have luck getting OpenHAB to play sounds thru it yet. I’ve also got the pulse audio binding to work on my system but have yet to get it to make sounds yet… here is a thread about the pulse audio binding I started

here is a thread about using the blue tooth and pulse audio couldn’t get mine to work

edit to add
I use alexa for tts because I don’t care who is snooping on me and she goes ‘Andy… the phone is ringing’ it is stupid easy to get to work. The binding is kind of iffy howhever, possible memory leak though slows my system but works.

Thanks for the reply. Yeah, the webaudio works fine with HabPanel or PaperUI. I don’t have tablets around… I haven’t found a really good way to mount an old tablet to the wall without exposed power wiring… and hiding the wiring is a requirement for my home. :wink:

I guess I am really looking for a headless speaker to play those notifications / sounds. I supposed I could just open a browser on an Raspberry Pi or something when the system boots up and that would do the trick too. That starts getting into the heavy category, though, and I’d like to keep it as thin as possible.

I’ll take a look at PulseAudio. I’ve never been great at configuring pulse… always seems like I need to be a Pulse expert/developer to really be able to do anything right with it… it’s incredibly difficult to configure for me. Maybe it is time to do some learning about that. It would satisfy the need of what I’m looking for…

I also use Alexa for the TTS and it works great, but I can’t use it to play arbitrary sounds. Would prefer to not have several speakers in each location to satisfy each function…

Thanks again for the tips, I’ll look into your suggestions.

do not feel alone in this my friend… pulse audio was / is making me nuts, it still does not work for what I want it to do, the binding is configured and working but OpenHAB will not play sounds to it. My problem comes from running a very stripped down Debian and drivers for brand new Dell onboard audio no worky (correction: I don’t know where to get drivers to get it to work)
I’ve considered buying a $150 sonos play1 and using the sonos binding which says each device becomes a sink in OpenHAB

Whilst this reply won’t answer your original question…

I use Chromecasts (Google Home and Google Home Mini) around the house for notifications. They’re relatively cheap, mains powered and playing media is what they’re intended for.

Hi

If this is a direction you’re looking in, have you considered a Google Chromecast Audio with a set of cheap speakers?

And use the ChromeCast binding so that each one becomes a separate Audio Sink, for any content.

TTS, notifications, music streams etc

Google discontinued the Chromecast Audio so they might be hard to come by going forward.

so now that we have considered all the possible alternatives, I’m curious about your original idea

Do you mean by a ‘CLI client’ a command line client? Did you consider making a binding or just a solution using a script? Are you a java developer?
Anyhow, because now that I seem to have gotten bash scripts to run from within OpenHAB, I think I could do something along these lines with scripts and curious what you come up with

The swines !!!

It looks like they are continuing to support them, but focusing on the full video playback versions.

Stripping out the audio from a HDMI is an option, but what a faff.

Anyway, what about this as a thought.

Is it possible to create a script that opens a UDP port on a machine and awaits a short string from openHAB2?

Then pushes a compiled URL into a command line audio player?

For example, if the UDP packets simply contained “doorbell” a URL might be

http://{oh_ip}:8080/static/sounds/doorbell.mp3

Where a soft symlink in /etc/openhab2/html/sounds points to /etc/openhab2/sounds

1 Like

Sorry about the lateness of this reply. Been traveling and didn’t see the replies.

@MDAR, yes I think that could be done and is a simpler option to what I was proposing. I would prefer to have a fully implemented audio sink that is a CLI player (or the link) so that standard calls work in rules etc without anything special. There are a lot of “hacky” (?) options… my personal favorite has been to set up a text item that is linked to an MQTT topic with the URL to the sound… Then anything that can monitor MQTT can grab the URL and play the sound… Was just hoping for something a little more integrated.

@All, Does anyone have any hints on where to look or documentation on the audio sink protocol. It looks like it is a simple REST API where you can register a callback URL, but before I start digging through source code, I was wondering if anyone could point out a starting place…

Brandon
that is pretty close to what I do now but with a rule and playSound. But… it took a lot of work to get playSound to work and it was OS stuff not OH stuff mostly. To me, sound is important for things like doorbells or notifications or a lot of things which an audible alert is warranted. Getting that in OpenHAB does seem way to hard. A sound binding that standardizes and make things more straight forward, I for one would welcome

There can be no such binding. There are as many ways to play a sound on a device as there are devices. Sonoss? Chromecast? Kodi? They all of their own bindings that allow you to play sounds. Want to play a sound on the machine hosting OH or on a tablet running HABPanel? There is the audio sinks build into the core for that. There can not be and will not be a generic binding to play an arbitrary sound on an arbitrary speaker. Such a binding would be as big and complex as OH itself, assuming one could ever do something like that.

Most people who use audio either use audio sinks, Chromecast, or Sonoss.

Understood. Initially, I wasn’t sure what was possible, but through this thread I got some clarity that my best option would be to implement a binding that is an audio sink with another piece of software on the other end that is more extensible/reliable than the other options. However, the more I think about it, the less I am confident that the effort is worth it. Not a hugely impossible effort but certainly one that is redundant. Instead, I might pursue my MQTT idea and skip playSound altogether. That or just open up a webbrowser to one of the UIs for webaudio. None of the audio sink options that I have seen are really great as a general purpose speaker for my use case (running headless Kodi is too heavy, having browser up to play audio is clunky, Squeezebox is inconsistent and limits playback to 30ish seconds for notifications, Alexa doesn’t play arbitrary audio clips, etc).
Anyway, now I know this use case is very specific to me and I will figure out a solution to my question.

Thanks again for all the help from everyone who responded!

In that case…

Grab a cheap ChromeCast Audio before they disappear from the shops :slight_smile: