#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");
}