In this tutorial, I will cover how to install and setup SoX on android devices using Termux.
Termux is a free “Android terminal emulator and Linux environment app that works directly with no rooting or setup required”.
Basically it is a command line interface for your Android device and works like a small linux distribution. It even includes a package management system. And if you get something like an OTG-dongle you can even connect a keyboard and/or a class compliant sound interface.
The first think you need to do is install termux on your phone. It can be installed either via PlayStore or F-Droid.
Before continuing, it may be a good idea to make sure Termux has the proper storage permissions.
According to the termux wiki:
“It is necessary to grant storage permission for Termux on Android 6 and higher. Use ‘Settings>Apps>Termux>Permissions>Storage’ and set to true.”
To install a package, first update the information available about the package repos
And then install SoX by executing
pkg install sox
Hopefully, you now have sox installed on your Android device.
You can verify this using the
which command, if it returns nothing, something is wrong, if it returns a path, you should be good.
To use your Android device’s internal microphone, you need to tweak a few things.
By default, Sox uses the pulseaudio driver to get sound in and out of Termux but the audio input is not activated by default.
Let’s fix this.
First, kill pulseaudio if you have it running.
Then, restart pulseaudio and load the “module-sles-source” module.
-D flag will daemonise/background pulseaudio.
pulseaudio -L "module-sles-source" -D
That’s it, now you can record sound using sox.
Let’s test it by recording 5 seconds of audio, you should see the “meter” on the right react when you make noise.
rec yay.wav trim 00:00 00:05
And then play it back
This tutorial is part of series of tutorials: