Cleaning voice recordings from command line?
Take a look at sox
Quoting man sox
:
SoX - Sound eXchange, the Swiss Army knife of audio manipulation
[...]
SoX is a command-line audio processing tool, particularly suited to
making quick, simple edits and to batch processing. If you need an
interactive, graphical audio editor, use audacity(1).
So, it should be a nice fit as a companion command line alternative to audaciy!
Regarding the actual task of cleaning recordings, take a look at the filter noisered
for which equals the noise reduction filter Audacity:
man sox | less -p 'noisered \['
[...]
noisered [profile-file [amount]]
Reduce noise in the audio signal by profiling and filtering.
This effect is moderately effective at removing consistent
background noise such as hiss or hum. To use it, first run
SoX with the noiseprof effect on a section of audio that
ideally would contain silence but in fact contains noise -
such sections are typically found at the beginning or the
end of a recording. noiseprof will write out a noise pro‐
file to profile-file, or to stdout if no profile-file or if
`-' is given. E.g.
sox speech.wav -n trim 0 1.5 noiseprof speech.noise-profil
To actually remove the noise, run SoX again, this time with
the noisered effect; noisered will reduce noise according to
a noise profile (which was generated by noiseprof), from
profile-file, or from stdin if no profile-file or if `-' is
given. E.g.
sox speech.wav cleaned.wav noisered speech.noise-profile 0
How much noise should be removed is specified by amount-a
number between 0 and 1 with a default of 0.5. Higher num‐
bers will remove more noise but present a greater likelihood
of removing wanted components of the audio signal. Before
replacing an original recording with a noise-reduced ver‐
sion, experiment with different amount values to find the
optimal one for your audio; use headphones to check that you
are happy with the results, paying particular attention to
quieter sections of the audio.
On most systems, the two stages - profiling and reduction -
can be combined using a pipe, e.g.
sox noisy.wav -n trim 0 1 noiseprof | play noisy.wav noise
[...]
The accepted answer doesn't give a practical example(see first comment to it) so I am trying to give one here.
On Ubuntu with apt you should install sox
and audio formats support
sox
First install sox
and support for formats (including mp3):
sudo apt install sox libsox-fmt-*
Then before you run your command on the file/files first you need to build a profile, make a sample of noise, this is the most important part you have to select the best time when the noise takes place, make sure you don't have voice (or the music/signal you try to keep) in this sample:
ffmpeg -i source.mp3 -ss 00:00:18 -t 00:00:20 noisesample.wav
Now make a profile out of that source:
sox noisesample.wav -n noiseprof noise_profile_file
And finally run the noise reduction on the file:
sox source.mp3 output.mp3 noisered noise_profile_file 0.31
Where noise_profile_file
is the profile and 0.30
is the value. Values goes best somewhere between 0.20 and 0.30, over 0.3 is very aggressive, under 0.20 is kind of soft and works well for very noisy audios.
Try and play with that and if you find other setting tricks and please comment with the findings and tuning settings.
how to batch process them
If the noise is similar you can use the same profile for all the mp3 files
ls -r -1 *.mp3 | xargs -L1 -I{} sox {} {}_noise_reduced.mp3 noisered noise_profile_file 0.31
or if there is a folder structure:
tree -fai . | grep -P ".mp3$" | xargs -L1 -I{} sox {} {}_noise_reduced.mp3 noisered noise_profile_file 0.31