# WebAudio CLI Client

**URL:** <https://community.openhab.org/t/webaudio-cli-client/77968>\
**Category:** Beginners\
**Tags:** webaudio\
**Created:** [July 13, 2019, 2:24pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968 "2019-07-13T14:24:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![blr](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/eb8c5e/32.png) [@blr](https://community.openhab.org/u/blr)\
**Post date:** [July 13, 2019, 2:24pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/1 "2019-07-13T14:24:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Andrew\_Rowe](https://community.openhab.org/user_avatar/community.openhab.org/andrew_rowe/32/37075_2.png) [@Andrew\_Rowe](https://community.openhab.org/u/Andrew_Rowe)\
**Post date:** [July 13, 2019, 5:52pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/2 "2019-07-13T17:52:40Z")

</div>

Hello Brandon  
I just use playSound in a rule.

```auto
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

> [@Pulse Audio binding](https://community.openhab.org/t/pulse-audio-binding/74265):
>
> Stupid question… Does anyone use the Pulse Audio binding? Can someone help me get it working in OpenHAB? Platform desktop pc running Deb 9 A forum seach for ‘pulseaudio’ returns 33 threads, I’ve read all 33 from the :[pulseaudio add-ons doc](https://www.openhab.org/addons/bindings/pulseaudio/#pulseaudio-binding) You need a running pulseaudio server whith module module-cli-protocol-tcp loaded and accessible by the server which runs your openHAB instance. running pactl list sinks short yeilds a list with my audio sinks so I’m guessing module-cli-protocol-tcp is…

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

> [@Play sound over standard java sinks via pulseaudio to bluetooth device](https://community.openhab.org/t/play-sound-over-standard-java-sinks-via-pulseaudio-to-bluetooth-device/22107):
>
> Hi, I would love to play sounds to my bluetooth speaker. As I managed to do so with Raspian, I struggled so far with Openhab. E.g. the console command smarthome:audio play enhancedjavasound doorbell.mp3 just directs to the standard Raspberry Pi audio outputs, while the linux console command mpg321 doorbell.mp3 just works fine. Since neither the Squeezebox nor the Pulseaudio binding seem to be so far valid audio sinks for OpenHAB2, I was hoping that there is a way to re-direkt the standard …

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.

---

<div class="post-metadata">

**Author:** ![blr](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/eb8c5e/32.png) [@blr](https://community.openhab.org/u/blr)\
**Post date:** [July 13, 2019, 6:09pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/3 "2019-07-13T18:09:37Z")

</div>

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. 😉

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.

---

<div class="post-metadata">

**Author:** ![Andrew\_Rowe](https://community.openhab.org/user_avatar/community.openhab.org/andrew_rowe/32/37075_2.png) [@Andrew\_Rowe](https://community.openhab.org/u/Andrew_Rowe)\
**Post date:** [July 13, 2019, 6:41pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/4 "2019-07-13T18:41:58Z")

</div>

> [@blr](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![danielwalters86](https://community.openhab.org/user_avatar/community.openhab.org/danielwalters86/32/37745_2.png) [@danielwalters86](https://community.openhab.org/u/danielwalters86)\
**Post date:** [July 13, 2019, 7:28pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/5 "2019-07-13T19:28:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MDAR](https://community.openhab.org/user_avatar/community.openhab.org/mdar/32/57900_2.png) [@MDAR](https://community.openhab.org/u/MDAR)\
**Post date:** [July 13, 2019, 7:34pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/6 "2019-07-13T19:34:03Z")

</div>

> [@blr](#):
>
> looking for a headless speaker to play those notifications / sounds.

Hi

If this is a direction you’re looking in, have you considered a [Google Chromecast Audio](https://www.google.com/search?q=chromecast+audio&tbm=shop) with a set of cheap speakers?

And use the [ChromeCast binding](https://www.openhab.org/addons/bindings/chromecast/) so that each one becomes a separate Audio Sink, for any content.

TTS, notifications, music streams etc

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [July 14, 2019, 2:29am UTC](https://community.openhab.org/t/webaudio-cli-client/77968/7 "2019-07-14T02:29:21Z")

</div>

> [@MDAR](#):
>
> considered a [Google Chromecast Audio](https://www.google.com/search?q=chromecast+audio&tbm=shop) with a set of cheap speakers

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

---

<div class="post-metadata">

**Author:** ![Andrew\_Rowe](https://community.openhab.org/user_avatar/community.openhab.org/andrew_rowe/32/37075_2.png) [@Andrew\_Rowe](https://community.openhab.org/u/Andrew_Rowe)\
**Post date:** [July 14, 2019, 3:08am UTC](https://community.openhab.org/t/webaudio-cli-client/77968/8 "2019-07-14T03:08:53Z")

</div>

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

> [@blr](#):
>
> 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

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

---

<div class="post-metadata">

**Author:** ![MDAR](https://community.openhab.org/user_avatar/community.openhab.org/mdar/32/57900_2.png) [@MDAR](https://community.openhab.org/u/MDAR)\
**Post date:** [July 14, 2019, 2:10pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/9 "2019-07-14T14:10:21Z")

</div>

> [@rlkoshak](#):
>
> Google discontinued the Chromecast Audio

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?](https://opensource.com/life/16/8/3-command-line-music-players-linux)

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

---

<div class="post-metadata">

**Author:** ![blr](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/eb8c5e/32.png) [@blr](https://community.openhab.org/u/blr)\
**Post date:** [August 4, 2019, 7:11pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/10 "2019-08-04T19:11:57Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Andrew\_Rowe](https://community.openhab.org/user_avatar/community.openhab.org/andrew_rowe/32/37075_2.png) [@Andrew\_Rowe](https://community.openhab.org/u/Andrew_Rowe)\
**Post date:** [August 4, 2019, 10:36pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/11 "2019-08-04T22:36:35Z")

</div>

> [@blr](#):
>
> 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…

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

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [August 5, 2019, 3:29pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/12 "2019-08-05T15:29:14Z")

</div>

> [@Andrew\_Rowe](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![blr](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/eb8c5e/32.png) [@blr](https://community.openhab.org/u/blr)\
**Post date:** [August 5, 2019, 4:58pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/13 "2019-08-05T16:58:53Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![MDAR](https://community.openhab.org/user_avatar/community.openhab.org/mdar/32/57900_2.png) [@MDAR](https://community.openhab.org/u/MDAR)\
**Post date:** [August 5, 2019, 5:00pm UTC](https://community.openhab.org/t/webaudio-cli-client/77968/14 "2019-08-05T17:00:18Z")

</div>

In that case…

Grab a cheap ChromeCast Audio before they disappear from the shops 🙂
