Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pulseaudio] Use sinks for output #1895

Closed
mtzro2003 opened this issue Feb 15, 2017 · 21 comments · Fixed by #10423
Closed

[pulseaudio] Use sinks for output #1895

mtzro2003 opened this issue Feb 15, 2017 · 21 comments · Fixed by #10423
Labels
enhancement An enhancement or new feature for an existing add-on

Comments

@mtzro2003
Copy link

Hi!

As far as I see, the binding can only be used to set volume of the sinks... You cannot output sound to a pulseaudio sink.
Could it be extended to register the sinks in openHAB to allow to play notifications?
Would it be feasible?
The binding right now uses module-cli-protocol-tcp and this cli has a play-file command, but I don't know if this can be used to output sound from openHAB.
Maybe change the binding to use another module like module-simple-protocol-tcp or something else that allows to play sound from openHAB like audio notifications or voice prompts?

@davidgraeff davidgraeff added the enhancement An enhancement or new feature for an existing add-on label Mar 18, 2019
@vKnmnn
Copy link
Contributor

vKnmnn commented Oct 16, 2020

in theory we should be able to install pulseaudio libraries on the openhab server and stream audio to remote pulseaudio sinks with the module-native-protocol-tcp.
we would then only need to be able to switch these streams around with the binding.

@vKnmnn
Copy link
Contributor

vKnmnn commented Oct 16, 2020

The play-file command, i imagine, could work if you put your sound files on a NFS which is mounted on the same location on all your pulseaudio sink devices

dalgwen pushed a commit to dalgwen/openhab-addons that referenced this issue Mar 27, 2021
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration
dalgwen pushed a commit to dalgwen/openhab-addons that referenced this issue Mar 30, 2021
This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab to a pulse audio server on the network.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration

Closes openhab#1895

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
@dalgwen
Copy link
Contributor

dalgwen commented Mar 30, 2021

Hello,
I made a PR wich handle this use case (see above). I didn't use the native protocol, but the simple protocol (sending raw audio to a port linked to a sink). Because it was much more... simpler.

So you have to use the pulseaudio module-simple-protocol-tcp server side, which will, once loaded, listen on a port and forward everything to the sink you have configured when loading the module.
pactl load-module module-simple-protocol-tcp sink= port=4711

The binding use the existing Thing "Audio Sink" and extends it by allowing it to connect to this port and broadcast raw audio.

dalgwen pushed a commit to dalgwen/openhab-addons that referenced this issue Apr 2, 2021
This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab to a pulse audio server on the network.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration

Closes openhab#1895

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Signed-off-by: dalgwen <nope@nope.net>
dalgwen pushed a commit to dalgwen/openhab-addons that referenced this issue Apr 2, 2021
This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab to a pulse audio server on the network.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration.

Closes openhab#1895

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
fwolter pushed a commit that referenced this issue Apr 9, 2021
* [pulseaudio] Add pulseaudio sink as openhab audio sink (#1895)

This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab to a pulse audio server on the network.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration.

Closes #1895

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after review

And getting rid of some other compilation warnings
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Fix some registration errors  and allow the binding to load the simple module remotely

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after reviews

initialize audiosink in a thread with scheduler.submit
clear some warning related code.

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Better interruptexception handling

* Fix two small concurrency bugs

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

Co-authored-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
@vKnmnn
Copy link
Contributor

vKnmnn commented May 4, 2021

@dalgwen have you looked at icedtea (libpulse-java)? with that it should be possible to use the native pulseaudio protocol without implementing too much stuff yourself

@dalgwen
Copy link
Contributor

dalgwen commented May 4, 2021

Hello,

libpulse-java seems to serve different purpose. It is a JNI wrapper, allowing java program to output sound transparently to the local (not completely sure about this?) pulseaudio server. It has several drawbacks over the solution I choosed :

  • necessity to know the pulseaudio API to use it properly (I'm not even sure it is made for the kind of objective we want here ?)
  • not sure if it can be used for remote sound
  • not available for OpenHAB on Windows ?
  • lack of documentation (? in fact I could not find any example ?)

The solution I choosed is, in fact, the lazy one. And I'm completely fine with that :-D !
(and last but not least, it's done and it's working)

Anyway, thanks for taking time to think about it, it is always good to think about alternative.

@vKnmnn
Copy link
Contributor

vKnmnn commented May 5, 2021

Thank you for clarifying.

This library (icedtea is indeed bigger than just the pulseaudio java part) can be used to play networked sound.

For example, to use sound from openhab-docker, you will need to install pulseaudio and libpulse-java to the container and link a few files in just the right places for java to pick it up and you can have the java-sound output to the pulseaudio server (transparently) on the docker host (or elsewhere, depending on client.conf).

This means, that the pulseaudio apis are already implemented in libpulse-java. The implementation of the sound sink would be very similar to the current javasound

The way i remember it, you can have an instance of a pulse server with a remote IP. i failed wrapping my head around the whole thing with the static classes in there... java isn’t my strong suit. Plus, as you mention, the documentation is 'somewhat lacking' and pulseaudio isn’t available for windows.

Anyway: Thank you for this patch!

@dalgwen
Copy link
Contributor

dalgwen commented May 5, 2021

OK, I see, thank you for the additional informations. You put a lot more thinking than me in this !
By reading you, I may have taken this path, and as I see it now, it could have been prettier than just sending raw PCM bytes to a socket. And maybe the libpulse-java could have handled the MP3 support I had to take in another library ?

On the other side, I like the simple-protocol for the simplicity : It allows a fast 100% java solution, with no installation, no input or configuration from the user perspective needed. One of the last commit I made add the ability to search/load the simple protocol module remotely by itself, no need to load the module manually in configuration file or command line (unlike what I said in my first comment here).

Are you the original contributor of this binding ? If so (and even if not), thank you !

themillhousegroup pushed a commit to themillhousegroup/openhab2-addons that referenced this issue May 10, 2021
…openhab#10423)

* [pulseaudio] Add pulseaudio sink as openhab audio sink (openhab#1895)

This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab to a pulse audio server on the network.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration.

Closes openhab#1895

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after review

And getting rid of some other compilation warnings
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Fix some registration errors  and allow the binding to load the simple module remotely

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after reviews

initialize audiosink in a thread with scheduler.submit
clear some warning related code.

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Better interruptexception handling

* Fix two small concurrency bugs

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

Co-authored-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Signed-off-by: John Marshall <john.marshall.au@gmail.com>
@ScanxTaz
Copy link

Thank you for clarifying.

This library (icedtea is indeed bigger than just the pulseaudio java part) can be used to play networked sound.

For example, to use sound from openhab-docker, you will need to install pulseaudio and libpulse-java to the container and link a few files in just the right places for java to pick it up and you can have the java-sound output to the pulseaudio server (transparently) on the docker host (or elsewhere, depending on client.conf).

This means, that the pulseaudio apis are already implemented in libpulse-java. The implementation of the sound sink would be very similar to the current javasound

The way i remember it, you can have an instance of a pulse server with a remote IP. i failed wrapping my head around the whole thing with the static classes in there... java isn’t my strong suit. Plus, as you mention, the documentation is 'somewhat lacking' and pulseaudio isn’t available for windows.

Anyway: Thank you for this patch!

Hey, thanks for this very useful information, I was also thinking about installing pulseaudion in the Docker container, in order to be loosely coupled from the "real sink", installed on a "pi" somewhere on the network.

Could we maybe elaborate a bit here about this ? I see that you are telling that installing the two pulseaudio and libpulse-java libraries would be enough, but is this really the case ? I mean, I guess that in the container, we have to physically set the "/etc/pulse/client.conf" file to redirect the pulseaudio client to the server and connect to the sink, but is this well the journey to follow ?

Thanks for your lights, really appreciated !

@vKnmnn
Copy link
Contributor

vKnmnn commented May 23, 2021

@ScanxTaz Most of this is documented in this issue

But i just checked, and there’s nothing about icedtea, so i added that. It’s a forum post.

  • make /dev/snd and /etc/pulse/client.conf available in container (you will have to see if it works without /dev/snd and client.conf pointing to your pi)
  • install pulseaudio and libpulse-java (icedtea) in container
  • configure host pulse to allow connections
  • make java consider icedtea as sound provider (as far as i remember, that’s the default in the container already)

@dalgwen
Copy link
Contributor

dalgwen commented May 23, 2021

@ScanxTaz I don't understand your use case.
Do you want to play something from within openhab to a pulse audio server somewhere on the network ?
If so, you don't need to install anything on the openhab machine (beside the pulseaudio binding), This is the purpose of this PR.

@ScanxTaz
Copy link

ScanxTaz commented May 25, 2021 via email

@dalgwen
Copy link
Contributor

dalgwen commented May 25, 2021

  1. Install this test release for the pulse audio binding OR wait for the official openhab 3.1.0 release and install the binding normally. Disclaimer : this is a test release, and I didn't have any feedback from other tester. It works for me ;)
  2. As per the documentation, you need a running pulseaudio server with the module module-cli-protocol-tcp loaded. This is where you want the sound to be played. You DON'T NEED to have pulse audio on the openhab machine. In fact, your openhab instance could even be on a Windows machine.
    In my case, my openhab is a PC server and I play sound on a raspberry pi (with pulse audio installedon it) over the network.
  3. Create a pulse audio "bridge" in openhab to connect to your pulse audio server (see documentation)
  4. Create or use the auto detection feature to add an "audio sink" thing (see documentation)
  5. Activate the functionnality "Create an Audio Sink with simple-protocol-tcp" in the newly created thing configuration
  6. Use the openhab play sound functionnality. You should be able to choose the pulse audio sink as a destination. (note : I only tested mp3 and wav file.)

Feedback welcome :)

@ScanxTaz
Copy link

ScanxTaz commented May 25, 2021 via email

@dalgwen
Copy link
Contributor

dalgwen commented May 25, 2021

Yes, sorry, I put the wrong link.
I made a JAR release here.

Note : you may have to recreate the thing for the UI to display the new sink activation parameter

@ScanxTaz
Copy link

ScanxTaz commented May 25, 2021 via email

@ScanxTaz
Copy link

ScanxTaz commented May 25, 2021 via email

@ScanxTaz
Copy link

ScanxTaz commented May 25, 2021 via email

@ScanxTaz
Copy link

ScanxTaz commented May 25, 2021 via email

@dalgwen
Copy link
Contributor

dalgwen commented May 25, 2021

If you configured your old bridge / thing by an .item file, you can't edit (or delete) them from within the UI. You must edit (delete) the file. It could explain part of your issue ?

Also, it's better if you uninstall the old binding before manually installing the snapshot I made, I'm not familiar with the behavior of openhab when two versions cohabits.

I suggest we continue this conversation on the topic binding, as it appears to be a more broad subject than this PR (which was just to add audio sink capability to the binding, and I think we are not yet at this point).

(And last but not least, you could have more help than only mine ;-) !)

@ScanxTaz
Copy link

ScanxTaz commented May 25, 2021 via email

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/pulse-audio-binding/74265/28

computergeek1507 pushed a commit to computergeek1507/openhab-addons that referenced this issue Jul 13, 2021
…openhab#10423)

* [pulseaudio] Add pulseaudio sink as openhab audio sink (openhab#1895)

This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab to a pulse audio server on the network.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration.

Closes openhab#1895

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after review

And getting rid of some other compilation warnings
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Fix some registration errors  and allow the binding to load the simple module remotely

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after reviews

initialize audiosink in a thread with scheduler.submit
clear some warning related code.

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Better interruptexception handling

* Fix two small concurrency bugs

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

Co-authored-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
thinkingstone pushed a commit to thinkingstone/openhab-addons that referenced this issue Nov 7, 2021
…openhab#10423)

* [pulseaudio] Add pulseaudio sink as openhab audio sink (openhab#1895)

This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab to a pulse audio server on the network.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration.

Closes openhab#1895

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after review

And getting rid of some other compilation warnings
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Fix some registration errors  and allow the binding to load the simple module remotely

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after reviews

initialize audiosink in a thread with scheduler.submit
clear some warning related code.

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Better interruptexception handling

* Fix two small concurrency bugs

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

Co-authored-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this issue May 5, 2022
…openhab#10423)

* [pulseaudio] Add pulseaudio sink as openhab audio sink (openhab#1895)

This add to the pulseaudio binding the capability to use "pulseaudio sink" as an "openhab sink" to output sound from openhab to a pulse audio server on the network.
You need to load module-simple-protocol-tcp sink in addition to the usual module-cli-protocol-tcp, and enable the sink in the thing configuration.

Closes openhab#1895

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after review

And getting rid of some other compilation warnings
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Fix some registration errors  and allow the binding to load the simple module remotely

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

* Small corrections after reviews

initialize audiosink in a thread with scheduler.submit
clear some warning related code.

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
Better interruptexception handling

* Fix two small concurrency bugs

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>

Co-authored-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
markus7017 pushed a commit to markus7017/openhab-addons that referenced this issue Aug 12, 2023
Signed-off-by: justin <justin.georgi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants