jmwang66
2023-05-09 8dab6d184a034ca86eafa644ea0d2100aadfe27d
funasr/runtime/onnxruntime/src/audio.cpp
@@ -11,6 +11,7 @@
using namespace std;
namespace funasr {
// see http://soundfile.sapp.org/doc/WaveFormat/
// Note: We assume little endian here
struct WaveHeader {
@@ -247,6 +248,15 @@
        return false;
    }
    
    if (!header.Validate()) {
        return false;
    }
    header.SeekToDataChunk(is);
    if (!is) {
        return false;
    }
    *sampling_rate = header.sample_rate;
    // header.subchunk2_size contains the number of bytes in the data.
    // As we assume each sample contains two bytes, so it is divided by 2 here
@@ -389,8 +399,10 @@
    FILE* fp;
    fp = fopen(filename, "rb");
    if (fp == nullptr)
   {
        LOG(ERROR) << "Failed to read " << filename;
        return false;
   }
    fseek(fp, 0, SEEK_END);
    uint32_t n_file_len = ftell(fp);
    fseek(fp, 0, SEEK_SET);
@@ -541,4 +553,6 @@
    std::vector<float> pcm_data(speech_data, speech_data+sp_len);
    vad_segments = vad_obj->Infer(pcm_data);
}
}
} // namespace funasr