psaylor / sox-audio

A NodeJS interface to SoX audio utilities
MIT License
70 stars 22 forks source link

Intercom from my phone #17

Open tunerooster opened 3 years ago

tunerooster commented 3 years ago

I have node.js installed and running on Android in termux. Though, ultimately I want this to run in javascript in the chrome browser. I have the following working via the termux command line:

pulseaudio -k 2 >/dev/null
LD_LIBRARY_PATH= pulseaudio -L "module-sles-source" -D  > /dev/null 2>&1
rec -V1 -q -b 16 -c 1 -e signed-integer -r 16000 -t wav - vol 25dB silence 1 0.1 3% 1 2.0 10% pad 1 1 |
  curl -s --data-binary @- http://frontdoor-camera/cgi-bin/speaker.sh -o /dev/null

This records (using sox) from the phone's mic until it hears silence, then pipes the resulting .wav stream to an IP cammera where it is played (spoken) through the camer's speaker (eg, at the front door).

This is intended to happen when a button is pressed in Home Assistant (eg, in the chrome browser). Since browsers cannot run shell commands, and because I want it to be as responsive as possible, I would like to accomplish the same thing in javascript.

I am hopeful that sox-audio is the correct/best module to use for this. If not, suggestions are welcome, please.

Can anyone help me understand how to do this (what additional packages to use, and maybe some example code)?