From d46b7ec178b88ecfe6ad51796ad5cf4448cca2e3 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 12 Sep 2023 16:44:33 +0800 Subject: [PATCH] Catch exception from non-streaming paraformer. (#307) --- sherpa-onnx/csrc/offline-recognizer-paraformer-impl.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sherpa-onnx/csrc/offline-recognizer-paraformer-impl.h b/sherpa-onnx/csrc/offline-recognizer-paraformer-impl.h index 15f9830d3..9d7186124 100644 --- a/sherpa-onnx/csrc/offline-recognizer-paraformer-impl.h +++ b/sherpa-onnx/csrc/offline-recognizer-paraformer-impl.h @@ -184,7 +184,14 @@ class OfflineRecognizerParaformerImpl : public OfflineRecognizerImpl { // i.e., -23.025850929940457f Ort::Value x = PadSequence(model_->Allocator(), features_pointer, 0); - auto t = model_->Forward(std::move(x), std::move(x_length)); + std::pair t{nullptr, nullptr}; + try { + t = model_->Forward(std::move(x), std::move(x_length)); + } catch (const Ort::Exception &ex) { + SHERPA_ONNX_LOGE("\n\nCaught exception:\n\n%s\n\nReturn an empty result", + ex.what()); + return; + } auto results = decoder_->Decode(std::move(t.first), std::move(t.second));