Skip to content

Commit

Permalink
Print informative error messages for sherpa-onnx-alsa on errors. (k2-…
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Dec 15, 2023
1 parent 33c03f7 commit ad72e7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions sherpa-onnx/csrc/alsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ const std::vector<float> &Alsa::Read(int32_t num_samples) {

// count is in frames. Each frame contains actual_channel_count_ samples
int32_t count = snd_pcm_readi(capture_handle_, samples_.data(), num_samples);
if (count == -EPIPE) {
static int32_t n = 0;
if (++n > 5) {
fprintf(
stderr,
"Too many overruns. It is very likely that the RTF on your board is "
"larger than 1. Please use ./bin/sherpa-onnx to compute the RTF.\n");
exit(-1);
}
fprintf(stderr, "XRUN.\n");
snd_pcm_prepare(capture_handle_);

static std::vector<float> tmp;
return tmp;
} else if (count < 0) {
fprintf(stderr, "Can't read PCM device: %s\n", snd_strerror(count));
exit(-1);
}

samples_.resize(count * actual_channel_count_);

Expand Down
2 changes: 1 addition & 1 deletion sherpa-onnx/csrc/sherpa-onnx-alsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ as the device_name.

int32_t segment_index = 0;
while (!stop) {
const std::vector<float> samples = alsa.Read(chunk);
const std::vector<float> &samples = alsa.Read(chunk);

stream->AcceptWaveform(expected_sample_rate, samples.data(),
samples.size());
Expand Down

0 comments on commit ad72e7a

Please sign in to comment.