Create a silent mp3 from the command line

后端 未结 4 892
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 19:37

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

4条回答
  •  野的像风
    2021-02-01 20:04

    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
    

提交回复
热议问题