termux-api icon indicating copy to clipboard operation
termux-api copied to clipboard

API Command Request: Audio stream

Open xloem opened this issue 8 years ago • 11 comments

xloem avatar Jan 16 '17 13:01 xloem

I'm interested too. Any news on a command line app using opensl es (or aaudio) to stream android mic?

arkanoid87 avatar May 02 '18 14:05 arkanoid87

Hi. I will have create audio stream on my samsung. How can i get audio stream in node js with termux api ?

zababurinsv avatar Jul 11 '20 09:07 zababurinsv

Stream Microphone is easy.

First install sox and pulseaudio (and ssh if the stream in remotely) with:

apt install sox pulseaudio openssh

The termux on android with microphone is the SERVER.

Allow pulse audio listen the microphone putting load-module module-sles-source in $PREFIX/etc/pulse/default.pa. Restant pulseaudio:

pulseaudio -k
pulseaudio --start

To stream microphone use:

sox -d -V0 -c1 -r48000 -t s32 -

You can pipe this. For example, to pipe as a microphone of your pc use:

sox -d -V0 -c1 -r48000 -t s32 - | ssh -p CLIENT_SSH_PORT CLIENT_USER@CLIENT_IP 'cat > /tmp/virtmic'

And listen the file /tmp/virtmic as a vistual microphone in your pc, the CLIENT, as pactl load-module module-pipe-source source_name=virtmic file=/tmp/virtmic format=s32 rate=48000 channels=1

ismaeldamiao avatar Jun 18 '21 13:06 ismaeldamiao

Is this information accurate for termux on android?

I did just also find https://github.com/termux/termux-packages/issues/806#issuecomment-284189870

xloem avatar Jun 18 '21 16:06 xloem

I have tested on mt redmi 6 and it's work. Actually I'm using android as microphone for my pc desktop.

screenfetch 
       ╲ ▁▂▂▂▁ ╱        
       ▄███████▄        
      ▄██ ███ ██▄        
     ▄███████████▄       OS: Android 9
  ▄█ ▄▄▄▄▄▄▄▄▄▄▄▄▄ █▄    Device: Redmi 6 (cereus)
  ██ █████████████ ██    ROM: SW_S98507AE1_V009_M13_XM_C3D_USR
  ██ █████████████ ██    Baseband: unknown
  ██ █████████████ ██    Kernel: armv7l Linux 4.9.117+
  ██ █████████████ ██    Uptime: 
     █████████████       CPU: MT6762V/CB
      ███████████        GPU: MT6762V/CB
       ██     ██         RAM: 2451MiB / 3842MiB
       ██     ██  

ismaeldamiao avatar Jun 18 '21 22:06 ismaeldamiao

I written a gist: https://gist.github.com/ismaeldamiao/bf5c28ae9ffe83c542695840f912d75e

ismaeldamiao avatar Jun 19 '21 03:06 ismaeldamiao

The gist uses https://en.wikipedia.org/wiki/OpenSL_ES which is in general far better than going through the termux and java layers. I didn't know android provided hardware audio access.

xloem avatar Aug 10 '22 12:08 xloem