我试图在音频文件的末尾检测静音.
我在ffmpeg库上取得了一些进展.在这里,我使用silencedetect列出音频文件中的所有静音.
ffmpeg -i audio.wav -af silencedetect=n=-50dB:d=0.5 -f null - 2> /home/aliakber/log.txt
Run Code Online (Sandbox Code Playgroud)
这是命令的输出:
- 音频文件的前端和末端静音 -
[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
Run Code Online (Sandbox Code Playgroud)
- 音频文件的前端和末端没有静音 -
[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
Run Code Online (Sandbox Code Playgroud)
但我想要更灵活的东西,以便我可以根据结果操纵输出并执行进一步的任务.
我想得到像真或假的输出.如果音频文件末尾存在一定的静音时间,则返回true,否则返回false.
有人能建议我一个简单的方法来实现这一目标吗?
试试这个:
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
Run Code Online (Sandbox Code Playgroud)
输出:
1 - 最后有沉默 0 - 最后没有沉默说明:正如我在沉默中看到的那样silence_end,日志结束时没有.
2>&1- 重定向stderr到stdingrep -Eo "silence_(start|end)"-过滤日志,只保留silence_start并silence_end从日志.每个新线.tail -n 1 - 得到最后一行.(如果是这样,现在我们有3种情况的状态:'silence_start','silence_end',<empty>)grep "start"- 仅在包含时保留行start (2种情况:'silence_start',<empty>)wc -l - 获得行数.(1在'silence_start'与0在<empty>情况)| 归档时间: |
|
| 查看次数: |
4845 次 |
| 最近记录: |