title: How can I remove silence from an MP3 programmatically?
body: <p>I have MP3 files that sometimes have silence at the end.  I would like to remove this silence automatically.  From what I can tell, it is "perfect" silence (0 amplitude), not background noise.  The length of the content and the silence varies.</p>
  
  <p>I found some other questions about <a href="https://stackoverflow.com/questions/43890/crop-mp3-to-first-30-seconds">cropping to the first 30 seconds</a> or <a href="https://stackoverflow.com/questions/1390731/how-to-crop-a-mp3-from-x-to-xn-using-ffmpeg">cropping to X and X+N seconds</a> using <code>ffmpeg</code>.  I would think I could use a similar approach, as long as I have a way to find when the silence starts.  How would I do that programatically?</p>
  
  <p>For example, one possible solution would be to have a command that finds the beginning of the "silence".  I'd expect a sequence like this</p>
  
  <pre><code>end=$(ffmpeg some-command-to-find-start-of-silence)
  ffmpeg -t "$end" -acodec copy -i inputfile.mp3 outputfile.mp3
  </code></pre>
  
  <p>The solution does <strong>not</strong> have to use <code>ffmpeg</code>, but it does need to be available on Ubuntu.</p>