从命令行清除录音?


28

我以前曾使用Audacity去除录音中的噪音,但是它在命令行上的使用非常有限。我有大约100个简短的演讲视频,这些视频将在接下来的几个月中观看,并且希望有一种简便的方法可以立即或根据需要在观看之前将其全部清洁。

我可以使用命令行工具或流行语言库吗?

Answers:


17

看一眼 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
           [...]

7
不幸的是,我发现sox在手册页中使用的描述非常嘈杂,难以理解-双关语。有没有一种更简单的方法,仅一个命令就可以减轻噪音呢?
shevy

当然,没问题-只需用一个简单的句子写下要更改的内容-但要足够精确以使技术上清晰易懂...好的,那样就行不通了,因为您需要了解噪声是什么,以及噪声的哪些部分您想要消除的噪音,可以减少的噪音以及可以降低声音质量的方法,否则可以降低噪音。为了减少杂耍,您需要了解杂耍俱乐部-杂耍的声音种类,以及在半空中碰撞时如何进行平衡。然后,袜子是您的工具箱和急救箱!
Volker Siegel

12

可接受的答案没有给出实际的示例(请参阅对此的第一条评论),所以我尝试在此处给出一个示例。在具有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

1
如果是语音音频和独立的左右声道是不必要的,那么你就可以追加remix -缩混所有输入通道的单声道
杰克贝格

2
@EduardFlorinescu你的答案是正确的。我在每个录音的背景上都有一个静态噪音录音。我阅读了您的答案,并使用了声音文件中的前2秒钟来创建配置文件,最后使用它来消除录音中的噪音。非常感谢。
Abrar Hossain
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.