我用过大胆消除噪音从之前的记录来看,但是它的命令行使用非常有限。我有大约 100 个简短的讲座视频,我将在接下来的几个月内观看这些视频,并且希望有一种简单的方法可以一次性清理它们,或者在观看之前根据需要清理它们。
是否有命令行工具或流行语言库可以用来执行此操作?
答案1
接受的答案没有给出一个实际的例子(请参阅第一条评论),所以我试图在这里给出一个例子。在带有 apt 的 Ubuntu 上,您应该安装sox
音频格式支持
sox
首次安装sox
以及对格式的支持(包括mp3):
sudo apt install sox libsox-fmt-*
然后,在对文件运行命令之前,您首先需要构建一个配置文件,制作噪音样本,这是最重要的部分,您必须选择噪音发生的最佳时间,确保您不会此示例中有语音(或您尝试保留的音乐/信号):
ffmpeg -i source.mp3 -ss 00:00:18 -t 00:00:20 noisesample.wav
现在根据该来源制作一个配置文件:
sox noisesample.wav -n noiseprof noise_profile_file
最后对文件运行降噪:
sox source.mp3 output.mp3 noisered noise_profile_file 0.31
noise_profile_file
轮廓在哪里,0.30
价值在哪里。值最好在 0.20 到 0.30 之间,超过 0.3 则非常激进,低于 0.20 则有点柔和,适用于非常嘈杂的音频。
尝试使用它,如果您发现其他设置技巧,请评论发现和调整设置。
如何批量处理它们
如果噪音相似,您可以对所有 mp3 文件使用相同的配置文件
ls -r -1 *.mp3 | xargs -L1 -I{} sox {} {}_noise_reduced.mp3 noisered noise_profile_file 0.31
或者如果有文件夹结构:
tree -fai . | grep -P ".mp3$" | xargs -L1 -I{} sox {} {}_noise_reduced.mp3 noisered noise_profile_file 0.31
答案2
看一眼sox
引用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).
因此,它应该非常适合作为 audaciy 的配套命令行替代品!
关于清理录音的实际任务,请看一下过滤器,noisered
其等于降噪滤波器 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
[...]
答案3
或者,您可以使用无人值守的方法。恕我直言,更好,因为用户声称有 30 小时的音频(可能有很多文件来寻找只有噪音而没有声音的部分)。
我的做法:
#!/bin/bash
for input_file in "$@"; do
file_name="${input_file%.*}"
# Convert file to ".wav" 48k (needed by rnnnoise)
ffmpeg -threads 2 -y -i "$input_file" -vn -ar 48000 "${file_name}.48k.wav"
# Actual denoise
denoiseit "${file_name}.48k.wav" "${file_name}.rnnoise.wav";
# Convert to ogg
ffmpeg -threads 2 -y -i "${file_name}.rnnoise.wav" "${file_name}.rnnoise.ogg"
# Remove wav temporary files
rm "${file_name}.48k.wav"
rm "${file_name}.rnnoise.wav"
done;
bash / shell 中的用法:
$ sh denoise.script.sh *.mp4
$ sh denoise.script.sh *.mp3
$ sh denoise.script.sh *.mkv
$ sh denoise.script.sh *.avi
希望能帮助到你。