termux / termux-api

Termux add-on app which exposes device functionality as API to command line programs.
https://f-droid.org/en/packages/com.termux.api/
2.09k stars 432 forks source link

API Command Request: Audio stream #55

Open xloem opened 7 years ago

arkanoid87 commented 6 years ago

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

zababurinsv commented 3 years ago

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

ismaeldamiao commented 3 years ago

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

xloem commented 3 years ago

Is this information accurate for termux on android?

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

ismaeldamiao commented 3 years ago

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 commented 3 years ago

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

xloem commented 1 year ago

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.

sudomain commented 1 month ago

@ismaeldamiao can pulseaudio, Sox, or another tool be used to stream the microphone audio from a Bluetooth headset?

TomJo2000 commented 1 month ago

termux-microphone-record from the termux-tools package oughta do the job.

sudomain commented 1 month ago

termux-microphone-record from the termux-tools package oughta do the job

That seems to always use the on-device/phone microphone rather than a Bluetooth microphone

ismaeldamiao commented 1 month ago

@sudomain I'm not sure, but in general you only need to identify the correct hardware (module) to listen in pulseaudio. I suggests you to read pulseaudio documentation to learn how to select the correct module, I notice that the method on termux can be distinct from in ubuntu or something else that can appears in tutorials.