如何检测音频文件结尾处的静音? [英] How to detect the silence at the end of an audio file?

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

问题描述

我正在尝试检测音频文件结尾处的静音.
我在 ffmpeg 库方面取得了一些进展.在这里,我使用 silencedetect 列出了音频文件中的所有静音.

I am trying to detect silence at the end of an audio file.
I have made some progress with ffmpeg library. Here I used silencedetect to list all the silences in an audio file.

ffmpeg -i audio.wav -af silencedetect=n=-50dB:d=0.5 -f null - 2> /home/aliakber/log.txt

以下是命令的输出:

-音频文件的开头和结尾处保持静音-

[silencedetect @ 0x1043060] silence_start: 0.484979
[silencedetect @ 0x1043060] silence_end: 1.36898 | silence_duration: 0.884
[silencedetect @ 0x1043060] silence_start: 2.57298
[silencedetect @ 0x1043060] silence_end: 3.48098 | silence_duration: 0.908
[silencedetect @ 0x1043060] silence_start: 4.75698
size=N/A time=00:00:05.56 bitrate=N/A

-音频文件的开头和结尾处保持静音-

[silencedetect @ 0x106fd60] silence_start: 0.353333
[silencedetect @ 0x106fd60] silence_end: 1.25867 | silence_duration: 0.905333
[silencedetect @ 0x106fd60] silence_start: 2.46533
[silencedetect @ 0x106fd60] silence_end: 3.37067 | silence_duration: 0.905333
size=N/A time=00:00:04.61 bitrate=N/A

但是我想要更灵活的东西,以便我可以操纵输出并根据结果执行进一步的任务.
我想得到类似 true false 的输出.如果音频文件的末尾存在一定的静默时间,则它将返回 true false ,否则.

But I want something more flexible so that I can manipulate the output and do further task depending on the result.
I want to get the output something like true or false. If there is a certain period of silence exists at the end of the audio file it will return true and false otherwise.

有人可以建议我实现这一目标的简单方法吗?

Can someone suggest me an easy way to achieve this?

推荐答案

尝试一下:

ffmpeg -i audio.wav -af silencedetect=n=-50dB:d=0.5 -f null - 2>&1 | grep -Eo "silence_(start|end)" | tail -n 1 | grep "start" | wc -l

输出:

  • 1-末尾无声
  • 0-最后没有沉默
  • 1 - there is silence at the end
  • 0 - there is no silence at the end

说明: 正如我在沉默案例中看到的那样,日志末尾没有silence_end.

Explanation: As I see in the silence case there is no silence_end at the end of log.

  1. 2>&1-将stderr重定向到stdin
  2. grep -Eo "silence_(start|end)"-过滤日志并仅保留日志中的silence_startsilence_end.每个都换行.
  3. tail -n 1-获取最后一行. (如果是这样,那么现在我们有3种状态:'silence_start''silence_end'<empty>)
  4. grep "start"-仅在包含start 的情况下保留行(2种情况:'silence_start'<empty>)
  5. wc -l-获取行数. ((在'silence_start'中为1,在<empty>中为0)
  1. 2>&1 - redirect stderr to stdin
  2. grep -Eo "silence_(start|end)" - filter log and keep only silence_start and silence_end from log. Each by new line.
  3. tail -n 1 - get last line. (if it is. So now we there are 3 cases of state: 'silence_start', 'silence_end', <empty>)
  4. grep "start" - keep line only if it contains start (2 cases: 'silence_start', <empty>)
  5. wc -l - get number of lines. (1 in 'silence_start' and 0 in <empty> case)

这篇关于如何检测音频文件结尾处的静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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