Skip to content

Instantly share code, notes, and snippets.

@devoncrouse
Created May 7, 2013 17:02
Show Gist options
  • Star 65 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save devoncrouse/5534261 to your computer and use it in GitHub Desktop.
Save devoncrouse/5534261 to your computer and use it in GitHub Desktop.
Using Sox (http://sox.sourceforge.net) to remove background noise and/or silence from audio files (individually, or in batch).
# Create background noise profile from mp3
/usr/bin/sox noise.mp3 -n noiseprof noise.prof
# Remove noise from mp3 using profile
/usr/bin/sox input.mp3 output.mp3 noisered noise.prof 0.21
# Remove silence from mp3
/usr/bin/sox input.mp3 output.mp3 silence -l 1 0.3 5% -1 2.0 5%
# Remove noise and silence in a single command
/usr/bin/sox input.mp3 output.mp3 noisered noise.prof 0.21 silence -l 1 0.3 5% -1 2.0 5%
# Batch process files
/usr/bin/find . -type f -name "*.mp3" -mmin +30 -exec sox -S --multi-threaded -buffer 131072 {} /path/to/output/{} noisered noise.prof 0.21 silence -l 1 0.3 5% -1 2.0 5% \;
# Remove insignificant files
/usr/bin/find . -type f -name "*.mp3" -mmin +30 -size -500k -delete
@nodingneu
Copy link

How can I control the amount of noise that it is reduced by?

@nodingneu
Copy link

@davidwebca
Copy link

@theonlygusti It is by changing the number right after "noise.prof" (currently, in this example, it is 0.21). You can learn more about the sox command line here : http://sox.sourceforge.net/sox.html#EFFECTS.

@AIGyan
Copy link

AIGyan commented Feb 3, 2020

Thank you @devoncrouse and @david-treblig
This is working fine but adding echo in the audio file. Could you please advise, if you have encountered similar issue.

@oshindow
Copy link

oshindow commented Mar 30, 2022

@AIGyan Same issue. Have you solved it?
This issue maybe caused by the sample rate of the audio. The echo was gone when I upsample the audio from 16k to 48k.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment