PulseAudio as Sink is Playing back Way to Fast

I am trying to setup PulseAudio as an audio sink for TTS messages but now that I finally have it working the messages are playing way to fast. Like not even chipmunks but unrecognizably fast.

PulseAudio server is running on my windows 10 desktop, and my openHAB is an upto date version of openHAB 3 runnings as a service on another windows 10 machine.

I attempted to look for similar issues but only found post related to arch linux and they all suggest disabling the timer-based scheduling by add tsched=0 in /etc/pulse/default.pa:

/etc/pulse/default.pa
load-module module-udev-detect tsched=0

adding that line to my default.pa causes PulseAudio not to start and adding it to

### Use the static hardware detection module (for systems that lack udev/hal support)
load-module module-detect tsched=0

also cause it to fail to launch. Unfortunately the windows documentation for PulseAudio is next to none existent and oddly the faq doesn’t cover it. Any pointers would be much appreciated as I am really looking forward to using PulseAudio!

Hello,

I made the “audio sink” part of the pulseaudio binding.
I think it’s the same bug as this one.
I made a fix, but it is not merged yet (don’t know if it will make it before the official 3.2 release)
If you don’t want to wait for the fix to be in the official release, you could use the snapshot release I just publish for you.

I hope this will help you. If it is not, then could you please send me the wav/mp3 file produced by your TTS service ? I will try it on my environment.

Freaking amazing thank you! I had posted an issue a few days ago as well for the same thing so I linked it to that one and mentioned that the snapshot fixes it! P.S. I found a second bug at the same time related to a change in the default ports somewhere. I included links in that issue to the two files I found hardcoded ports in. One of them probably isn’t an issue cause I think I realized later it was just a display file or defaults but the other I’m pretty sure is causing the minor issues I explain in the post. [pulseaudio] The PulseAudio binding Has Hardcoded Ports that May not Match all Setups · Issue #11661 · openhab/openhab-addons · GitHub

If I understood the post correctly, this issue should be resolved in the OpenHAB 3.2.0 build.

However, I realize also with OpenHAB version 3.2.0 that playback is much to fast when providing audio output files to PulseAudio sinks that do not match the audio format expected for the respectiv sink.

So it appears that this bug is still present in OpenHAB 3.2.0. Further details here.

Hello again,

Could you please provide the sound you used ?
Does all sounds play fast, or just some ?
Is it linked to your RAOP sink, or is it with all kind of sink you tried ?
Did you let the binding load and manage the simple-protocol-tcp module on your pulseaudio server, or did you load it by yourself ? If so, could you provide the parameter you used ?

Hi Gwendal,

Thank you very much for looking into the issue that my MaryTTS voice output to PuseAudio RAOP sinks is still playing back ways to fast although I have OpenHAB 3.2.0 installed. Besides the reported issue that playing back audio files not matching the s16le 2ch 44100Hz specification fail to play at all.

The sounds that did not play at all are songs encoded as 256 kBit/s mp3 files that I purchased from the iTunes store. There is no fast playback, it is not played at all. So for copyright reasons I cannot publish them here. As I tried different songs leading to the same negative result, I hope that this classification is already sufficient to reproduce the issue. When I use the OpenHAB Karaf console to output such an mp3 file to a selected pulseaudio RAOP sink, I receive the following exception in the log file:

2022-04-03 11:25:46.865 [WARN ] [core.audio.internal.AudioManagerImpl] - Error playing 'org.openhab.core.audio.FileAudioStream@645e704c': Cannot send sound to the pulseaudio sink
org.openhab.core.audio.UnsupportedAudioFormatException: Cannot send sound to the pulseaudio sink
	at org.openhab.binding.pulseaudio.internal.PulseAudioAudioSink.process(PulseAudioAudioSink.java:164) ~[?:?]
	at org.openhab.core.audio.internal.AudioManagerImpl.play(AudioManagerImpl.java:140) [bundleFile:?]
	at org.openhab.core.audio.internal.AudioManagerImpl.playFile(AudioManagerImpl.java:180) [bundleFile:?]
	at org.openhab.core.audio.internal.AudioConsoleCommandExtension.playOnSink(AudioConsoleCommandExtension.java:171) [bundleFile:?]
	at org.openhab.core.audio.internal.AudioConsoleCommandExtension.play(AudioConsoleCommandExtension.java:143) [bundleFile:?]
	at org.openhab.core.audio.internal.AudioConsoleCommandExtension.execute(AudioConsoleCommandExtension.java:85) [bundleFile:?]
	at org.openhab.core.io.console.ConsoleInterpreter.execute(ConsoleInterpreter.java:55) [bundleFile:?]
	at org.openhab.core.io.console.karaf.internal.CommandWrapper.execute(CommandWrapper.java:78) [bundleFile:?]
	at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:68) [bundleFile:4.3.4]
	at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:86) [bundleFile:4.3.4]
	at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:599) [bundleFile:4.3.4]
	at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:526) [bundleFile:4.3.4]
	at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:415) [bundleFile:4.3.4]
	at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:416) [bundleFile:4.3.4]
	at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229) [bundleFile:4.3.4]
	at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59) [bundleFile:4.3.4]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.io.IOException: mark/reset not supported above 10000 bytes
	at org.openhab.binding.pulseaudio.internal.ConvertedInputStream$ResetableInputStream.reset(ConvertedInputStream.java:252) ~[?:?]
	at org.tritonus.share.sampled.file.TAudioFileReader.getAudioFileFormat(TAudioFileReader.java:195) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.ConvertedInputStream.getPCMStream(ConvertedInputStream.java:146) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.ConvertedInputStream.<init>(ConvertedInputStream.java:65) ~[?:?]
	at org.openhab.binding.pulseaudio.internal.PulseAudioAudioSink.process(PulseAudioAudioSink.java:125) ~[?:?]

I have installed the MaryTTS binding. I did not install anything else, simply pressed on “Install” in the PaperUI at the respective binding. When I try to output some words via the OpenHAB Karaf console, I get very fast voice output. Again, the voice is output to a PulseAudio RAOP sink. I do not see any output in the log files when playing back voice output.

Unfortunately, I do not know much about the pulseaudio driver and your binding to provide a valid answer to this question. Therefore, I will provide further details of my setup so that I hope you can extract the answers therefrom:

The server is a VM without assigned sound card. Debian 10 and OpenHAB 3.2.0 are installed via openhabian-config.

Starting from the default settings of the pulseaudio (I talk about the driver, not the binding), I applied the following changes to /etc/pulse/default.pa:

### Automatically load loopback sound driver
.ifexists module-loopback.so
load-module module-loopback
.endif

### Automatically load driver modules for auto discovery
.ifexists module-zeroconf-discover.so
load-module module-zeroconf-discover
.endif
.ifexists module-raop-discover.so
load-module module-raop-discover
.endif

### Allow access to pulseaudio via TCP port 4712
load-module module-esound-protocol-tcp auth-anonymous=1
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/16
load-module module-simple-protocol-tcp
load-module module-cli-protocol-tcp

My pulseaudio.things file contains:

Bridge pulseaudio:bridge:local "PulseAudio" [ host="127.0.0.1", port=4712 ] {
	  Things:
	  Thing sink          trivum1         "Trivum 1"           [name="raop_output.arm-7.local", activateSimpleProtocolSink=true, simpleProtocolSinkPort=4721]
	  Thing sink          trivum2         "Trivum 2"           [name="raop_output.arm-7.local.2", activateSimpleProtocolSink=true, simpleProtocolSinkPort=4722]
	  Thing sink          trivum3         "Trivum 3"           [name="raop_output.arm-7.local.3", activateSimpleProtocolSink=true, simpleProtocolSinkPort=4723]
	  Thing sink          trivum4         "Trivum 4"           [name="raop_output.arm-7.local.4", activateSimpleProtocolSink=true, simpleProtocolSinkPort=4724]
	  Thing sink          trivum5         "Trivum 5"           [name="raop_output.arm-7.local.5", activateSimpleProtocolSink=true, simpleProtocolSinkPort=4725]
	  Thing sink          trivum6         "Trivum 6"           [name="raop_output.arm-7.local.6", activateSimpleProtocolSink=true, simpleProtocolSinkPort=4726]
	  Thing sink          trivum7         "Trivum 7"           [name="raop_output.arm-7.local.7", activateSimpleProtocolSink=true, simpleProtocolSinkPort=4727]
	  Thing sink          trivum8         "Trivum 8"           [name="raop_output.arm-7.local.8", activateSimpleProtocolSink=true, simpleProtocolSinkPort=4728]
	  }

With these settings, I created pulseaudio items and so that I can successfully access the pulseaudio sinks in OpenHAB. The pulseaudio things are online and I can adjust the volume. The settings are correctly applied to the sinks when checking the volume via pactl -s localhost list sinks. I can also successfully output WAV files in s16le 2ch 44100Hz via the OpenHAB Karaf console to the respective PulseAudio RAOP sink.

Due to my setup on a VM without sound card installed, I cannot answer this question. As you already resolved this issue, I could imagine that my reported problem is only related to RAOP sinks in pulseaudio.

At present, I could only identify the pattern that high quality mp3 files (encoded at 256 kBit/s) did not play at all and raised an exception, see above. The issue with the fast playback up to now only concerns the voice output from MaryTTS.

Thanks for all these informations,

I fixed the error for the high bitrate MP3 in the release for your other issue.

For the error with MaryTTS, the cause is not the pulseaudio binding, but the MaryTTS addon.
With some voice (not every voice), the frequency was incorrectly written in the wav header.
I made a pull request, it should be included in the next release (3.3.0) and a snapshot release if you want to test it earlier.