1、简介
Voice Activity Detector, 即语音动态检测;静音检测对于实时通话有着很重要的作用,什么是静默检测?顾名思义就是检测语音的状态,静默状态还是激活状态,这里存在一个问题,就是多长时间的静默状态才当作语音的结束,以及大的语音能量以及多长时间的状态持续才当作语音激活的开始,通常这个需要一个经验值。
2、静音检测的应用:
1、节省带宽:
用来检测发送端是否有人在讲话,来决定是否发送语音数据,当检测到用户没有讲话,即静音状态时,发送端可以不发送语音报文,只发送静音指示报文,从而降低语音报文占用的带宽。如下所示,正常的语音包负载占据160字节(G711U编码);
而静音帧只有几个字节,如下所示:
这种情况把VAD阈值设置的要低一些,否则会影响音频的质量,如果阈值过高的话,有可能在开始讲话的时候会丢失几个字,需要注意;
3、展示收发话状态:
检测语音流是否有声音,来展示收发话状态 ,如果感觉不准的话,可以累积一秒的音频包,然后算比例再进行决策,比如在一秒内超过80%的数据包都是静音包,则可以视为无人说话状态,否则,反之,实测效果还是比较准;
以下是我基于webrtc写的一个代码调用示例:
#define FRAMESIZE 160
int main(int argc, char** argv)
{
FILE *fpInput = NULL, *fpOutput = NULL;
VadInst * handle = NULL;
int status;
int fs = 8000;
short audioFrame[FRAMESIZE];
handle = NULL;
status = WebRtcVad_Create(&handle);
if (status != 0)
{
printf("Create is error \n");
return -1;
}
status = WebRtcVad_Init(handle);
if (status != 0)
{
printf("Init is error\n");
return -1;
}
fpInput = fopen("original_8k.raw", "rb");
fpOutput = fopen("result.txt", "wb");
if (fpInput == NULL)
{
printf("open file failure\n");
return -1;
}
status = WebRtcVad_set_mode(handle, 2);
if (status != 0)
{
printf("set mode is error\n");
return -1;
}
while (!feof(fpInput))
{
fread(audioFrame, sizeof(short), FRAMESIZE, fpInput);
status = WebRtcVad_Process(handle, fs, audioFrame, FRAMESIZE);
if (status == -1)
{
printf("WebRtcVad_Process is error\n");
return -1;
}
else if (status == 1)
{
printf("Active Voice\n");
}
else
{
printf("Non-active Voice\n");
}
fprintf(fpOutput, "%2d", status);
}
fclose(fpInput);
fclose(fpOutput);
status = WebRtcVad_Free(handle);
if (status != 0)
{
printf("Free is failure\n");
return -1;
}
printf("Finished \n");
getchar();
return 0;
}
项目地址:https://download.csdn.net/download/unique_no1/83209937
里面包含测试程序和可执行文件,windows平台和linux平台的我都已经编译好了,大家可以测试看下效果,接口调用也比较简单,欢迎沟通、交流。
tel:18108010758
vx:unique_no_1
-------------------------------------------------------------------------------------------------------------------------------