Skip to content

Commit

Permalink
Catch exception from whisper (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Nov 5, 2023
1 parent d1a450b commit 606cb26
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions sherpa-onnx/csrc/offline-recognizer-whisper-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl {
int32_t num_frames = f.size() / feat_dim;

if (num_frames > max_num_frames) {
SHERPA_ONNX_LOGE("Only waves less than 30 seconds are supported.");
exit(-1);
SHERPA_ONNX_LOGE(
"Only waves less than 30 seconds are supported. We process only the "
"first 30 seconds and discard the remaining data");
num_frames = max_num_frames;
}

NormalizeFeatures(f.data(), num_frames, feat_dim);
Expand All @@ -124,13 +126,19 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl {
(max_num_frames - num_frames) * feat_dim * sizeof(float));
mel = Transpose12(model_->Allocator(), &mel);

auto cross_kv = model_->ForwardEncoder(std::move(mel));
try {
auto cross_kv = model_->ForwardEncoder(std::move(mel));

auto results =
decoder_->Decode(std::move(cross_kv.first), std::move(cross_kv.second));
auto results = decoder_->Decode(std::move(cross_kv.first),
std::move(cross_kv.second));

auto r = Convert(results[0], symbol_table_);
s->SetResult(r);
auto r = Convert(results[0], symbol_table_);
s->SetResult(r);
} catch (const Ort::Exception &ex) {
SHERPA_ONNX_LOGE("\n\nCaught exception:\n\n%s\n\nReturn an empty result",
ex.what());
return;
}
}

private:
Expand Down

0 comments on commit 606cb26

Please sign in to comment.