如何通过编程将静音插入音频文件? [英] How to insert silence into an audio file with programming?

查看:95
本文介绍了如何通过编程将静音插入音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小时的不同音频文件,我想在所有这些文件中插入具有相同预定义位置和长度的静音.是否有任何软件可以完成这项工作?否则,我应该分别编辑音频文件,这将花费很多时间.

I have different audio files those are one hour long and I want to insert silence with a same predefined positions and length into all of these files. Is there any software which is capable of doing this job? Otherwise I should edit audio files separately which will take a lot of time.

推荐答案

如果通过插入静音"是指以静默方式填充文件,从而更改音轨的持续时间,那么我将使用SoX:

If by "inserting silence" you mean to pad the file with silence, and thereby changing the duration of the track, I'd use SoX:

# example file
sox -n -r 44100 -b 16 before.wav synth 20 brownnoise

# pads with 5 seconds of silence at the 2 seconds mark    
sox before.wav after-pad.wav pad 5@2

如果通过插入沉默"来静音文件的一部分,从而使持续时间保持不变,那么我将使用FFmpeg:

If by "inserting silence" you mean to mute a section of the file, and thereby keeping duration the same, I'd use FFmpeg:

# example file
ffmpeg -f lavfi -i "anoisesrc=d=20:c=brown:r=44100:a=0.5" before.wav

# sets volume to zero between the 2 and 5 second marks
ffmpeg -i before.wav -af "volume=enable='between(t,2,5)':volume=0" after-mute.wav

要批处理文件,请移至包含要处理的文件的文件夹(假定为WAV)并运行其中一个

To batch process files, move to a folder containing the files you want to process (assumes WAV) and run either

files="*.wav"
for f in $files
do
  sox "$f" "${f%.*}-pad.wav" pad 5@2
done

files="*.wav"
for f in $files
do
  ffmpeg -i "$f" -af "volume=enable='between(t,2,7)':volume=0" "${f%.*}-mute.wav"
done

这篇关于如何通过编程将静音插入音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆