如何以编程方式从 MP3 中消除静音? [英] How can I remove silence from an MP3 programmatically?

查看:36
本文介绍了如何以编程方式从 MP3 中消除静音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 MP3 文件有时会在结尾处静音.我想自动消除这种沉默.据我所知,这是完美"的静音(0 振幅),而不是背景噪音.内容长短不一,沉默不一.

I have MP3 files that sometimes have silence at the end. I would like to remove this silence automatically. From what I can tell, it is "perfect" silence (0 amplitude), not background noise. The length of the content and the silence varies.

我发现了一些关于裁剪到前 30 秒的其他问题,或者裁剪到 X 和 X+N 秒 使用 ffmpeg.我想我可以使用类似的方法,只要我有办法找到沉默开始的时间.我将如何以编程方式做到这一点?

I found some other questions about cropping to the first 30 seconds or cropping to X and X+N seconds using ffmpeg. I would think I could use a similar approach, as long as I have a way to find when the silence starts. How would I do that programatically?

例如,一种可能的解决方案是使用一个命令来找到沉默"的开始.我希望有这样的序列

For example, one possible solution would be to have a command that finds the beginning of the "silence". I'd expect a sequence like this

end=$(ffmpeg some-command-to-find-start-of-silence)
ffmpeg -t "$end" -acodec copy -i inputfile.mp3 outputfile.mp3

该解决方案不必必须使用 ffmpeg,但它确实需要在 Ubuntu 上可用.

The solution does not have to use ffmpeg, but it does need to be available on Ubuntu.

推荐答案

sox inputfile.mp3 outputfile.mp3 silence 1 0.1 0.1% reverse silence 1 0.1 0.1% reverse

这将从您的文件中修剪任何超过 0.1 秒的静音.如果您只关心修剪结尾,这可以简化为:

This will trim any silence longer than 0.1 second from your file. If you're only concerned about trimming the end, this can be simplified to:

sox inputfile.mp3 outputfile.mp3 reverse silence 1 0.1 0.1% reverse

可以在 这里.

A detailed look into how sox's silence works can be found here.

这篇关于如何以编程方式从 MP3 中消除静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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