Create a silent mp3 from the command line

19,555

Solution 1

Disclaimer: This is a unix-oriented approach (although sox is cross-platform and should get it done on windows only as well).

  • You'll need sox - "the [cross-platform] Swiss Army knife of sound processing programs".

  • This wrapper perl script, helps you generate any seconds of silence: http://www.boutell.com/scripts/silence.html

    $ perl silence.pl 3 silence.wav
    

silence.pl is quite short, so I include it here, since it's public domains:

#!/usr/bin/perl

$seconds = $ARGV[0];
$file = $ARGV[1];
if ((!$seconds) || ($file eq "")) {
        die "Usage: silence seconds newfilename.wav\n";
}

open(OUT, ">/tmp/$$.dat");
print OUT "; SampleRate 8000\n";
$samples = $seconds * 8000;
for ($i = 0; ($i < $samples); $i++) {
        print OUT $i / 8000, "\t0\n";
}
close(OUT);

# Note: I threw away some arguments, which appear in the original
# script, and which did not worked (on OS X at least)
system("sox /tmp/$$.dat -c 2 -r 44100 -e signed-integer $file");
unlink("/tmp/$$.dat");

Then just lame it:

$ lame silence.wav silence.mp3

Solution 2

You can use this command.

ffmpeg -f lavfi -i anullsrc=r=44100:cl=mono -t <seconds> -q:a 9 -acodec libmp3lame out.mp3

Change <seconds> to a number indicating the number of seconds of silence you require (for example, 60 will create a minute).

Solution 3

Avoid the nuisance of creating a wav header, and let lame handle a raw file:

dd if=/dev/zero bs=1M count=? | lame -r - - > silence.mp3

setting ?=2 gives a 11 second file (@ standard 44KhZ, etc... parameters).

Note: this was tested on Unix; I understand there are dd and lame for windows, too.

Solution 4

sox -n -r 44100 -c 2 silence.wav trim 0.0 3.0 - this will create a 3sec stereo silence file. Here n for null file handler, r is the sample rate and c is the number of channels.

Then just lame it:

$ lame silence.wav silence.mp3

Share:
19,555
Stephen
Author by

Stephen

Updated on June 03, 2022

Comments

  • Stephen
    Stephen almost 2 years

    I am trying to create a silent / empty mp3 file of (x) seconds using the command line. Quite a simple task I thought!

    It seems LAME is able to do something like this, but I am unable to find anything that leads to achieving this.

    Has anyone been able to do something like this?