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

How to start a microphone server in Termux on Android? #1448

Closed
MS-Jahan opened this issue Jan 29, 2020 · 6 comments
Closed

How to start a microphone server in Termux on Android? #1448

MS-Jahan opened this issue Jan 29, 2020 · 6 comments

Comments

@MS-Jahan
Copy link

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

@bpsib
Copy link

bpsib commented Mar 2, 2020

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.

@ghost ghost deleted a comment from mixnenu Apr 13, 2020
@ghost
Copy link

ghost commented Apr 21, 2020

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

@ghost ghost closed this as completed Apr 21, 2020
@bpsib
Copy link

bpsib commented May 19, 2020

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.

@TackleIt
Copy link

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)

@daitj
Copy link

daitj commented Oct 10, 2020

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.

@Krush206
Copy link

Krush206 commented Aug 26, 2021

@daitj's solution is incomplete and does not work for GNU/Linux clients, but I managed to get it working another way.

Server side (Termux):

printf '\nload-module module-sles-source\nload-module module-loopback latency_msec=1\nload-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;<local ip address range>/<netmask>\n' >> $PREFIX/etc/pulse/default.pa
pulseaudio -D

The null sink module will cause delayed streaming; do not load the null sink module.
sox can be replaced with the loopback module.

Client side (GNU/Linux):

pactl load-module module-tunnel-source server=<stream ip address>

@ghost ghost locked and limited conversation to collaborators Oct 17, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants