diff --git a/sherpa-onnx/csrc/alsa.cc b/sherpa-onnx/csrc/alsa.cc index 3001a4d9..0370bbe0 100644 --- a/sherpa-onnx/csrc/alsa.cc +++ b/sherpa-onnx/csrc/alsa.cc @@ -144,6 +144,24 @@ const std::vector &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 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_); diff --git a/sherpa-onnx/csrc/sherpa-onnx-alsa.cc b/sherpa-onnx/csrc/sherpa-onnx-alsa.cc index d839dee4..3301353a 100644 --- a/sherpa-onnx/csrc/sherpa-onnx-alsa.cc +++ b/sherpa-onnx/csrc/sherpa-onnx-alsa.cc @@ -104,7 +104,7 @@ as the device_name. int32_t segment_index = 0; while (!stop) { - const std::vector samples = alsa.Read(chunk); + const std::vector &samples = alsa.Read(chunk); stream->AcceptWaveform(expected_sample_rate, samples.data(), samples.size());