Path: blob/master/examples/cpp_libtorch_deprecated/main.cc
1895 views
#include <iostream>1#include "silero_torch.h"2#include "wav.h"34int main(int argc, char* argv[]) {56if(argc != 4){7std::cerr<<"Usage : "<<argv[0]<<" <wav.path> <SampleRate> <Threshold>"<<std::endl;8std::cerr<<"Usage : "<<argv[0]<<" sample.wav 16000 0.5"<<std::endl;9return 1;10}1112std::string wav_path = argv[1];13float sample_rate = std::stof(argv[2]);14float threshold = std::stof(argv[3]);151617//Load Model18std::string model_path = "../../src/silero_vad/data/silero_vad.jit";19silero::VadIterator vad(model_path);2021vad.threshold=threshold; //(Default:0.5)22vad.sample_rate=sample_rate; //16000Hz,8000Hz. (Default:16000)23vad.print_as_samples=true; //if true, it prints time-stamp with samples. otherwise, in seconds24//(Default:false)2526vad.SetVariables();2728// Read wav29wav::WavReader wav_reader(wav_path);30std::vector<float> input_wav(wav_reader.num_samples());3132for (int i = 0; i < wav_reader.num_samples(); i++)33{34input_wav[i] = static_cast<float>(*(wav_reader.data() + i));35}3637vad.SpeechProbs(input_wav);3839std::vector<silero::SpeechSegment> speeches = vad.GetSpeechTimestamps();40for(const auto& speech : speeches){41if(vad.print_as_samples){42std::cout<<"{'start': "<<static_cast<int>(speech.start)<<", 'end': "<<static_cast<int>(speech.end)<<"}"<<std::endl;43}44else{45std::cout<<"{'start': "<<speech.start<<", 'end': "<<speech.end<<"}"<<std::endl;46}47}484950return 0;51}5253545556