Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print informative error messages for sherpa-onnx-alsa on errors. #486

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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