第44月第14天 webrtc vad检测

1.

void TestVAD(char* pAudioFile,char* pResFile,int nSample,int nMode)
{
    VadInst* pVad = NULL;
    if (WebRtcVad_Create(&pVad))
    {
        perror("WebRtcVad_Create failed!");
        return;
    }
 
    if (WebRtcVad_Init(pVad))
    {
        perror("WebRtcVad_Init failed!");
        return;
    }
 
    if (WebRtcVad_set_mode(pVad, nMode))
    {
        perror("WebRtcVad_set_mode failed!");
        return;
    }
 
    FILE* fp = NULL;
    FILE* fpR = NULL;
    fp = fopen(pAudioFile, "rb");
    fpR = fopen(pResFile, "wb");
    fseek(fp, 0, SEEK_END);
    unsigned int nLen = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    short shBufferIn[160] = { 0 };
    while (1)
    {
        if (160 != fread(shBufferIn, 2, 160, fp))
            break;
        int nRet = WebRtcVad_Process(pVad, 16000, shBufferIn, 160);
        printf("%d", nRet);
        if (1 == nRet)
        {
            fwrite(shBufferIn, 2, 160, fpR);
        }
    }
 
    fclose(fpR);
    fclose(fp);
    WebRtcVad_Free(pVad);
}

https://blog.csdn.net/qq_30948113/article/details/68928549

 

posted @ 2020-05-14 11:23  lianhuaren  阅读(353)  评论(0编辑  收藏  举报