<p><ahref="http://sox.sourceforge.net/">SoX</a> is a command-line utility for audio processing, e.g. convert file format, convert sample rate, remix, trim, pad, normalize, etc.</p>
<p><ahref="https://www.ffmpeg.org/">ffmpeg</a> is a framework to convert among different audio and video file formats. Use <code>ffmpeg</code> if you want to convert WAV to MP3.</p>
"[SoX](http://sox.sourceforge.net/) is a command-line utility for audio processing, e.g. convert file format, convert sample rate, remix, trim, pad, normalize, etc."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To install, for Mac:\n",
"\n",
" brew install sox"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"To play or record audio from the command line:"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
" rec test.wav\n",
" \n",
" play test.wav"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Resample to 22050 Hz:\n",
"\n",
" sox in.wav -r 22050 out.wav"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Normalize gain, e.g. to avoid clipping:\n",
"\n",
" sox in.wav --norm out.wav"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Down-mix all input channels to mono:\n",
"\n",
" sox in.wav out.wav remix -"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert to 16-bit signed integer:\n",
"\n",
" sox in.wav -b 16 -e signed-integer out.wav"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Trim the audio file starting at 1 min 15 sec and ending at 1 min 45 sec:\n",
"\n",
" sox in.wav out.wav trim 1:15 =1:45\n",
" sox in.wav out.wav trim 1:15 0:30\n",
" sox in.wav out.wav trim 75 30"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pad 1 second of silence to the beginning and 2 seconds of silence to the end:\n",
"\n",
" sox in.wav out.wav pad 1 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ffmpeg"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[ffmpeg](https://www.ffmpeg.org/) is a framework to convert among different audio and video file formats. Use `ffmpeg` if you want to convert WAV to MP3."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To install on MacOS:\n",
"\n",
" brew install ffmpeg"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert a WAV file to MP3:\n",
"\n",
" ffmpeg -i in.wav out.mp3 "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Down-mix all input channels to mono with a bitrate of 128k:\n",
"[SoX](http://sox.sourceforge.net/) is a command-line utility for audio processing, e.g. convert file format, convert sample rate, remix, trim, pad, normalize, etc."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To install, for Mac:\n",
"\n",
" brew install sox"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"source": [
"To play or record audio from the command line:"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
" rec test.wav\n",
" \n",
" play test.wav"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Resample to 22050 Hz:\n",
"\n",
" sox in.wav -r 22050 out.wav"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Normalize gain, e.g. to avoid clipping:\n",
"\n",
" sox in.wav --norm out.wav"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Down-mix all input channels to mono:\n",
"\n",
" sox in.wav out.wav remix -"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert to 16-bit signed integer:\n",
"\n",
" sox in.wav -b 16 -e signed-integer out.wav"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Trim the audio file starting at 1 min 15 sec and ending at 1 min 45 sec:\n",
"\n",
" sox in.wav out.wav trim 1:15 =1:45\n",
" sox in.wav out.wav trim 1:15 0:30\n",
" sox in.wav out.wav trim 75 30"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pad 1 second of silence to the beginning and 2 seconds of silence to the end:\n",
"\n",
" sox in.wav out.wav pad 1 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ffmpeg"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[ffmpeg](https://www.ffmpeg.org/) is a framework to convert among different audio and video file formats. Use `ffmpeg` if you want to convert WAV to MP3."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To install on MacOS:\n",
"\n",
" brew install ffmpeg"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert a WAV file to MP3:\n",
"\n",
" ffmpeg -i in.wav out.mp3 "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Down-mix all input channels to mono with a bitrate of 128k:\n",
"\n",
" ffmpeg -i in.wav -ac 1 -ab 128k out.mp3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To do the above command for all wav files in a directory:\n",
"\n",
" for i in wav/*; do ffmpeg -y -i \"$i\" -ac 1 -ab 128k mp3/`basename \"$i\" .wav`.mp3; done\n"