vad main

该程序是用C++编写的,利用WebRtcVad库进行语音活动检测(VAD)。它读取输入音频文件,应用VAD算法,然后将结果写入输出文件。设置的VAD模式为2,对8000Hz采样率的音频进行处理。如果在任何步骤中出现错误,程序会终止并打印错误信息。
摘要由CSDN通过智能技术生成

 

#include <stdio.h>

#include"webrtc_vad.h"

#define  FRAMELENGTH 160

main(int argc, char* argv[])

{

    FILE *fpInputf,*fpOutput;

    VadInst *handle;

    int status;

    int fs=8000;

    short audioFrame[FRAMELENGTH];

    handle=NULL;

    status=WebRtcVad_Create(&handle);

    if(status!=0)

    {  

        printf("Init is error\n");

        exit(0);

    }

    status=WebRtcVad_Init(handle);

    if(status!=0)

    {  

        printf("Init is error\n");

        exit(0);

    }

    printf("Input file is %s\n",argv[1]);

    printf("Output file is %s\n",argv[2]);

    fpInputf=fopen(argv[1],"rb");

    if(fpInputf==NULL)

    {

        printf("There is no input file\n");

        exit(0);

    }

    fpOutput=fopen(argv[2],"w");    

 

    status=WebRtcVad_set_mode(handle,2);

    if(status!=0)

    {  

        printf("Set mode is error\n");

        exit(0);

    }

    while(!feof(fpInputf))

    {

        fread(audioFrame,sizeof(short),FRAMELENGTH,fpInputf);

        status=WebRtcVad_Process(handle,fs,audioFrame,FRAMELENGTH);

        if(status==-1)

        {  

            printf("WebRtcVad_Process is error\n");

            exit(0);

        }

        fprintf(fpOutput,"%d\n",status);

    }

    fclose(fpInputf);

    fclose(fpOutput);

    status=WebRtcVad_Free(handle);

    if(status!=0)

    {  

        printf("Free is error\n");

        exit(0);

    }

    printf("finished \n");

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值