| #include "vad_onnx.h" |
| #include <iostream> |
| #include <sndfile.h> |
| #include <vector> |
| #include <map> |
| #include <fstream> |
| #include <string> |
|
|
| int main(int argc, char* argv[]) { |
| if (argc < 3) { |
| std::cerr << "Usage: " << argv[0] << " <model_absolute_path> <audio_list_absolute_path>" << std::endl; |
| return 1; |
| } |
|
|
| |
| std::string model_path = argv[1]; |
| std::string audio_list_path = argv[2]; |
|
|
| |
| std::ifstream audio_list_file(audio_list_path); |
| if (!audio_list_file.is_open()) { |
| std::cerr << "Error: Unable to open audio list file: " << audio_list_path << std::endl; |
| return 1; |
| } |
|
|
| try { |
| VadOnnx vad_model = VadOnnx(model_path); |
|
|
| |
| std::string wav_path; |
| while (std::getline(audio_list_file, wav_path)) { |
| if (wav_path.empty()) { |
| continue; |
| } |
| vad_model.reset_states(); |
|
|
| std::cout << wav_path << std::endl; |
|
|
| |
| SF_INFO sf_info; |
| SNDFILE* file = sf_open(wav_path.c_str(), SFM_READ, &sf_info); |
| if (!file) { |
| std::cerr << "Error: Unable to open audio file: " << wav_path << std::endl; |
| continue; |
| } |
|
|
| int samplerate = sf_info.samplerate; |
| int channels = sf_info.channels; |
| int frames = sf_info.frames; |
|
|
| std::vector<float> audio_buffer(4096 * channels); |
|
|
| try { |
| |
| int read_frames = 0; |
| while ((read_frames = sf_readf_float(file, audio_buffer.data(), 4096)) > 0) { |
| |
| audio_buffer.resize(read_frames * channels); |
|
|
| |
| std::map<std::string, double> result_map = vad_model.vad_dectect(audio_buffer, false); |
|
|
| |
| if (!result_map.empty()) { |
| for (const auto& pair : result_map) { |
| std::cout << pair.first << ", " << pair.second << std::endl; |
| } |
| } |
| } |
|
|
| sf_close(file); |
|
|
| } catch (const std::exception& ex) { |
| std::cerr << "Error processing file " << wav_path << ": " << ex.what() << std::endl; |
| sf_close(file); |
| } |
| } |
|
|
| audio_list_file.close(); |
|
|
| } catch (const std::exception& ex) { |
| std::cerr << "Error: " << ex.what() << std::endl; |
| return 1; |
| } |
|
|
| return 0; |
| } |