/* * Silence Removal in Speech Signal * * Created on: Sep 7, 2016 * Author: Agustín J. González * It assumes mono audio file of 16-bit PCM samples, little-endian format, sampled at 8 KHz */ #include #include // ifstream , ofstream using namespace std; int main (int argc, char * argv[]) { float threshold; ifstream audioInFile; ofstream audioOutFile; int packetSize; short *buff, *zeroBuff; if (argc < 5) { printf("Usage: %s \n", argv[0]); exit(-1); } threshold = atof(argv[1]); // First argument is a threshold for sensibility packetSize = atoi(argv[2]); audioInFile.open (argv[3], ios::in | ios::binary); // input audio file audioOutFile.open (argv[4], ios::out | ios::binary); //output audio file buff = new short[packetSize]; zeroBuff = new short[packetSize]; while (!audioInFile.eof()) { float energy=0; int sampleRead; audioInFile.read((char *)buff, sizeof(short)*packetSize); sampleRead= audioInFile.gcount()/sizeof(short); for (int i=0; i threshold) audioOutFile.write((char*)buff, sizeof(short)*sampleRead); else audioOutFile.write((char*)zeroBuff, sizeof(short)*sampleRead); } audioInFile.close(); audioOutFile.close(); }