从命令行清理录音?

Ann*_*Fay 31 command-line audio

我之前使用过Audacity 来去除录音中的噪音,但是它的命令行使用非常有限。我有大约 100 个简短的讲座视频,我将在接下来的几个月内观看这些视频,并希望在观看前以一种简单的方法一次性或根据需要清理它们。

是否可以使用命令行工具或流行的语言库来执行此操作?

Edu*_*scu 22

接受的答案没有给出一个实际的例子(见第一个评论)所以我想在这里给出一个。在带有 apt 的 Ubuntu 上,您应该安装sox并支持音频格式

sox

首先安装sox并支持格式(包括mp3):

sudo apt install sox libsox-fmt-*
Run Code Online (Sandbox Code Playgroud)

然后在对文件/文件运行命令之前,您首先需要构建配置文件,制作噪音样本,这是最重要的部分,您必须选择噪音发生的最佳时间,确保您没有在此示例中有语音(或您尝试保留的音乐/信号):

ffmpeg -i source.mp3 -ss 00:00:18 -t 00:00:20 noisesample.wav
Run Code Online (Sandbox Code Playgroud)

现在根据该来源制作个人资料:

sox noisesample.wav -n noiseprof noise_profile_file
Run Code Online (Sandbox Code Playgroud)

最后对文件运行降噪:

sox source.mp3 output.mp3 noisered noise_profile_file 0.31
Run Code Online (Sandbox Code Playgroud)

哪里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
Run Code Online (Sandbox Code Playgroud)

或者如果有文件夹结构:

tree -fai . | grep -P ".mp3$" | xargs -L1 -I{} sox {}  {}_noise_reduced.mp3  noisered noise_profile_file 0.31
Run Code Online (Sandbox Code Playgroud)

  • @EduardFlorinescu 你的答案是正确的。我在每个录音的背景上都有一个静态噪音录音。我阅读了您的回答,并使用我的声音文件中的前 2 秒创建了一个配置文件,最后用它来消除录音中的噪音。非常感谢。 (2认同)

Vol*_*gel 19

看一眼 sox

引用man sox

SoX - Sound eXchange, the Swiss Army knife of audio manipulation
Run Code Online (Sandbox Code Playgroud)

[...]

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).
Run Code Online (Sandbox Code Playgroud)

因此,它应该非常适合作为 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
           [...]
Run Code Online (Sandbox Code Playgroud)

  • 不幸的是,我发现 sox 在联机帮助页中使用的描述非常难读 - 双关语。有没有更简单的方法,只用一个命令来处理降噪? (7认同)