In this text I show how to use your android phone as microphone for your pc desktop using sox over ssh.
You need have a pulseaudio server running in your pc desktop.
Make a simple virtual microphone device using the following:
pactl load-module module-pipe-source source_name=virtmic file=/tmp/virtmic format=s32 rate=48000 channels=1All OK.
If you prefer, you can load the virtual mic in start of pulseaudio editing the file /etc/pulse/default.pa
(you need as root acess).
sudo su
echo "load-module module-pipe-source source_name=virtmic file=/tmp/virtmic format=s32 rate=48000 channels=1" >> /etc/pulse/default.pa
exitNow restart pulseaudio.
pulseaudio --kill
pulseaudio --startIn android you need have Termux installed.
Now you need sox (audio software) for stream your microphone, pulseaudio for authorize sox to use the microphone
and ssh to share the stream to the desktop, install it in termux typing:
apt update
apt install -y sox pulseaudio opensshIf you don't know use ssh, read about it in internet.
To allow that sox use microphone, type:
echo "load-module module-sles-source" >> $PREFIX/etc/pulse/default.paRestart pulseaudio.
pulseaudio --kill
pulseaudio --startNow, start the microphone stram with sox -c 1 -r48000 -d -t s32 - and can pipe to cat, for write
in the file /tmp/virtmic, in the desktop using ssh:
sox -c 1 -r48000 -d -t s32 - | ssh -p PC_SSH_PORT PC_USER@PC_IP 'cat > /tmp/virtmic'All OK.
The streamer can be rewritten as:
sox \
--channels 1 \
--rate 48000 \
--default-device \
--type s32 \
-Where:
--channels: 1 for mono, 2 for stereo.--rateis the sound frequency in Hz.- Note that the rate is the same in
module-pipe-sourceargument in the virtual microphone.
- Note that the rate is the same in
--default-deviceis the input device.--typeis the audio type (s32= signed 32-bit integer).- Note that the type is the same in
module-pipe-sourceargument in the virtual microphone.
- Note that the type is the same in
-is the output device, thestdin.
Before output device you can add effects from sox.
You can also add effects from pulseaudio editing $PREFIX/etc/pulse/default.pa.
For noise you can record 10 seconds for make a profile:
sox -c 1 -r 48000 -d -t s32 $PREFIX/tmp/noise.wav trim 0 10
sox -c 1 -r 48000 -t s32 $PREFIX/tmp/noise.wav -n noiseprof noise.profAnd use noisered noise.prof 0.1 effect before - in sox.
If you prefer, you can write a script for start and stop sound streamer.
Frist edit ~/.ssh/config for make a alias for your pc desktop.
In my case the alias is pc.
For make a notification you need installed termux-api application and termux-api package:
apt install -y termux-apiI put the code bellow in $PREFIX/bin/mic_streamer.
#!/bin/bash
# Make a notification for android microphone streaming
termux-notification \
--icon settings_voice \
--id 225 \
--ongoing \
--type default \
--priority high \
--title 'Microphone streamer' \
--content 'The microphone is sharing to desktop' \
--button1 'Stop' \
--button1-action "kill $$; termux-notification --icon settings_voice --id 225 --title 'Microphone streamer' --content 'The microphone streamer has stopped.'"
# Stream the microphone and pipe it for ssh and cat the pipe in the file of the virtual microphone module
sox \
--channels 1 \
--rate 48000 \
--default-device \
--type s32 \
- | ssh pc 'cat > /tmp/virtmic'
exit 0You can see all formats suported in documentation.