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, bu
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
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).
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.
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