I have a *Samsung Galaxy S21-U* running *Android 14* and *Termux `0.118.1`* (retrieved from *F-Droid* on 2024.08.22) with *TigerVNC `1.10.1-41`*. TigerVNC and associated required packages retrieved via *apt* in termux: I followed [these steps](https://wiki.termux.com/wiki/Graphical_Environment) to bring up an *[xfce4](https://www.xfce.org/) desktop environment* via tigervnc. Clear instructions for getting sound output are harder to find. 1. The following solutions successfully played MP3 files over USB-C speakers: - [The command `play-audio` from this answer](https://android.stackexchange.com/a/242118/246519) (`mpg123` and `play` produce no output, but see [2] below); - [These instructions on reddit for the `mpv` command](https://old.reddit.com/r/termux/comments/men125/can_termux_play_audio/); - I cannot get output over the phone speakers from either of the above. 2. [The VNC subset of this answer](https://android.stackexchange.com/a/205629/246519) does not work for me - A virtual pulseaudio sink `auto_null.monitor` exists. - The commands `play` and `mpg123` seem to attach to this sink. - With the above inputs attached, the sink `auto_null.monitor` switches state from `SUSPENDED` to `RUNNING`. - With audio playing, the xfce4 volume control panel shows the volume fluctuating. - No sound is emitted over *either* the phone or USB-C speakers. ### Further research [This reddit thread](https://old.reddit.com/r/termux/comments/19edqx4/sound_in_x11/) contains some links. - There is a [comment](https://old.reddit.com/r/termux/comments/19edqx4/sound_in_x11/kjc4p4k/) which others say *does not* work. For me, specifically, the error from those commands is `User-configured server at 127.0.0.1, refusing to start/autospawn`. I gather this is connected to the existing configuration set to achieve **[1]** and **[2]** above, but am not sure about the safe/correct steps to redress it. - There is a [link to LinuxDroidMaster's Termux-Desktops github](https://github.com/LinuxDroidMaster/Termux-Desktops). The approach I'm using is consistant with what they call a [termux native desktop](https://github.com/LinuxDroidMaster/Termux-Desktops/blob/main/Documentation/native/termux_native.md). I couldn't find mention of sound beyond a passing `pkg install pulseaudio` line, but let me know if there's more there. - There is a [link to these instructions](https://docs.andronix.app/troubleshoot/sound), which seem to assume the *proot* installation approach has been followed. It seems to download a `.sh` file, but its content appears to be binary and I do not know how to extract it into a human-readable form to understand what it is doing. [This reddit user is strugging with a chroot termux setup](https://old.reddit.com/r/termux/comments/bpa8jz/pulseaudio_streaming_client/) - Their [posted solution](https://old.reddit.com/r/termux/comments/bpa8jz/pulseaudio_streaming_client/eo06cs4/) may contain important clues even though I am not using a chroot setup. I get the same `User-configured server at 127.0.0.1, refusing to start/autospawn` error when I enter their commands, but presumably I need to go back and undo something in the setup for failed solutions **[1]** and **[2]]** to tidy things up. [Another reddit thread](https://old.reddit.com/r/termux/comments/1e5hk90/termux_play_sound_on_handy_speaker_while_running/) - [The only reply](https://old.reddit.com/r/termux/comments/1e5hk90/termux_play_sound_on_handy_speaker_while_running/ldmqsld/) suggests using `termux-media-player play` from the `termux-api` package. This produces no sound for me, from either the phon or USBC speaker, when run from either the termux terminal or the xfce4 VNC session. Pursuing the `User-configured server at 127.0.0.1, refusing to start/autospawn` error, - I ran `apt remove pulseaudio --purge`, noted the packages this would remove in the console output of said command, and then reinstalled all these packages along with pulseaudio. - This cleared user edits to configuration files in `~/../usr/etc/pulse/`. I browsed for other suspicious `*rc*` and `*profile*` file names that might contain leftover configuration and found none. - I opened a fresh shell to clean out any `export VARNAM=FOO` cruft. - `pulseaudio --start` runs. - I typed `pulseaudio -k` and `export PULSE_SERVER=127.0.0.1` - Now `pulseaudio --start` prints the (presumably desired) `refusing to start/autospawn` error. - I returned to termux and ran `pactl load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1` - At this point, */u/allanrps* reported > *You should now be able to return to the chroot environment and play audio. The clients will connect to the pulse server running in termux and you will have sound!* > But, no sound is heard (although pulseaudio controls register audio being sent). ### Edit 1 2024.08.23 I suspect that: - Even when given permissions to play audio, the Termux app does not have access to the phone's speakers (unless perhaps on rooted devices with chroot?). It can only natively export sound over USB-C audio devices. - Most of the tutorials for the VNC desktop environments use pulseaudio, and the instructions above *are not* for routing pulseaudio output to external USB-C speakers. - The commands `play-audio` and `mpv` do something else to access USB-C speakers via termux (bypassing pulseaudio), which is why they work. - There is probably a way to get apps talking to pulseaudio in the xfce4 session to play to USB-C speakers as well, but exact methods are TBD. - In principle there is no reason a pulseaudio server with access to the phone speakers could not be incorporated into the termux app. Indeed, I imagine there may be forks or newer versions that do this. But, it is not (AFAICT) implemented in the F-Droid version. - For playback through phone speakers using termux on a non-rooted device, one needs a third Android app to serve a network pulseaudio sink, and connect termux to this as if it were a remote machine. I need to ensure that the pulseaudio client settings in termux are set correctly to match the pulseaudio server app started on Android. I will attempt this with **PulseAudio Rtp Receiver** version `1.0.6` . These are the default server settings for **PulseAudio Rtp Receiver** version 1.0.6 installed from F-Droid on 2024.08.23: ``` IP: 224.0.0.56 Port: 4010 MTU: 320 Max Latency (ms): 300 Channel Count: 2 Channel Mask: 0 SampleRate: 48000 framesPerBurst: 192 ``` That default IP `224.0.0.56` is probably nonsense. I changed it to `127.0.0.1` in the *PulseAudio Rtp Receiver* GUI and restarted the server. Per [this reddit comment](https://old.reddit.com/r/termux/comments/svfmq5/help_is_there_any_possible_way_to_transmit_all/hxftlb4/), I tried running ``` export PULSE_SERVER=224.0.0.1:4010 ``` (with and without the port), but it did not work. Neither did the `pactl load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1` command from [**[2]**](https://old.reddit.com/r/termux/comments/bpa8jz/pulseaudio_streaming_client/eo06cs4/). I got `Could not open device: error 5` when subsequently using the `play` command for all of the above. Based on the [first comment reply here](https://forums.fedoraforum.org/showthread.php?313108-pulseaudio-rtp-port-number) I added the following lines to `/data/data/com.termux/files/usr/etc/pulse/default.pa`: ``` load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=48000 sink_properties="device.description='RTP Multicast Sink'" load-module module-rtp-send source=rtp.monitor destination_ip=127.0.0.1 port=4010 loop=1 ``` I started a fresh shell and ran ``` pulseaudio -k pulseaudio --start play ...... ``` With some success, I can now see *PulseAudio Rtp Receiver* receiving data! Still, no sound. As it turns out, *PulseAudio Rtp Receiver* does not have permissions to access speakers, has never requested it, and has no way to trigger a request for this permission. Well, its FOSS. Getting closer! ### Question I want to see if I can get the pulseaudio command `play` to emit over the phone speakers. Has anyone achieved this?