Skip to content

Commit

Permalink
Support reading waves from NAudio. (#914)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored May 24, 2024
1 parent e7b7348 commit cf83412
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sherpa-onnx/csrc/wave-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ std::vector<float> ReadWaveImpl(std::istream &is, int32_t *sampling_rate,
return {};
}

if (header.subchunk1_size == 18) {
// this is for NAudio. It puts extra bytes after bits_per_sample
// See
// https://github.com/naudio/NAudio/blob/master/NAudio.Core/Wave/WaveFormats/WaveFormat.cs#L223

is.seekg(36, std::istream::beg);

int16_t extra_size = -1;
is.read(reinterpret_cast<char *>(&extra_size), sizeof(int16_t));
if (extra_size != 0) {
SHERPA_ONNX_LOGE(
"Extra size should be 0 for wave from NAudio. Current extra size "
"%d\n",
extra_size);
*is_ok = false;
return {};
}

is.read(reinterpret_cast<char *>(&header.subchunk2_id),
sizeof(header.subchunk2_id));
is.read(reinterpret_cast<char *>(&header.subchunk2_size),
sizeof(header.subchunk2_size));
}

header.SeekToDataChunk(is);
if (!is) {
*is_ok = false;
Expand Down

0 comments on commit cf83412

Please sign in to comment.