Termux-app: How to start a microphone server in Termux on Android?

Created on 29 Jan 2020  路  5Comments  路  Source: termux/termux-app

Feature description
Is there anyway to use Android microphone and stream mic sound over network via Termux? I know there are many apps in Google Play Store for this task, but I'm interested if it is possible with Termux.

Reference implementation
Wireless MIC: https://play.google.com/store/apps/details?id=com.shenyaocn.android.WirelessMIC

Most helpful comment

For anyone who is still trying to make this work and came here from search engines.

This setup might be bit easier than @TackleIt 's solution.

I added following lines in my $PREFIX/etc/pulse/default.pa file, to enable mic (sles source) and to add one virtual speaker.

load-module module-sles-source
load-module module-null-sink sink_name=virtspk sink_properties=device.description=Virtual_Speaker

Then I used sox to play input from mic to the virtual speaker, to install sox pkg install sox

# start pulseaudio daemon
pulseaudio -D
# record from mic and play it on virtspk
rec -p | PULSE_SINK=virtspk play -p

In clients, I used virtspk.monitor as source to get the microphone working from the phone.

pactl load-module module-tunnel-source "server=IP_ADDRESS source=virtspk.monitor source_name=termux_mic"

There is something missing in module-sles-source that results in this error, if you try to use OpenSL_ES_source as source in clients

E: [pulseaudio] source.c: Assertion 'pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0' failed at /home/builder/.termux-build/pulseaudio/src/src/pulsecore/source.c:1155, function pa_usec_t pa_source_get_latency(pa_source *)(). Aborting.

All 5 comments

Termux:API has the termux-microphone-record command but doesn't seem possible to make that stream over network. There needs to be a termux-microphone-stream command or something to make this possible.

PulseAudio has module-sles-source which receives audio stream from microphone. Termux:API is not right thing for this.

PulseAudio has module-sles-source which receives audio stream from microphone. Termux:API is not right thing for this.

I have tried that but it seems very dodgy. I can't get it to work most of the time. It keeps not picking up any sound. An improvement is needed.

Late but if anyone is interested in a work around. It is possible that, you continuously record few second clips using termux-microphone-record then stream that via a python socket server to a receiver. The receiving side (using python) will have to adjust the rate of capture and just make a stream using pyaudio library directly (so that the stream doesn't repeat previous words. There is obviously a delay, for my case it was around record time + 2secs and sometimes there is error when the file is opened at improper time (though rare if you copy the file after completion to a different name)

For anyone who is still trying to make this work and came here from search engines.

This setup might be bit easier than @TackleIt 's solution.

I added following lines in my $PREFIX/etc/pulse/default.pa file, to enable mic (sles source) and to add one virtual speaker.

load-module module-sles-source
load-module module-null-sink sink_name=virtspk sink_properties=device.description=Virtual_Speaker

Then I used sox to play input from mic to the virtual speaker, to install sox pkg install sox

# start pulseaudio daemon
pulseaudio -D
# record from mic and play it on virtspk
rec -p | PULSE_SINK=virtspk play -p

In clients, I used virtspk.monitor as source to get the microphone working from the phone.

pactl load-module module-tunnel-source "server=IP_ADDRESS source=virtspk.monitor source_name=termux_mic"

There is something missing in module-sles-source that results in this error, if you try to use OpenSL_ES_source as source in clients

E: [pulseaudio] source.c: Assertion 'pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_GET_LATENCY, &usec, 0, NULL) == 0' failed at /home/builder/.termux-build/pulseaudio/src/src/pulsecore/source.c:1155, function pa_usec_t pa_source_get_latency(pa_source *)(). Aborting.
Was this page helpful?
0 / 5 - 0 ratings