正在显示
1 个修改的文件
包含
15 行增加
和
7 行删除
| @@ -107,8 +107,10 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl { | @@ -107,8 +107,10 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl { | ||
| 107 | int32_t num_frames = f.size() / feat_dim; | 107 | int32_t num_frames = f.size() / feat_dim; |
| 108 | 108 | ||
| 109 | if (num_frames > max_num_frames) { | 109 | if (num_frames > max_num_frames) { |
| 110 | - SHERPA_ONNX_LOGE("Only waves less than 30 seconds are supported."); | ||
| 111 | - exit(-1); | 110 | + SHERPA_ONNX_LOGE( |
| 111 | + "Only waves less than 30 seconds are supported. We process only the " | ||
| 112 | + "first 30 seconds and discard the remaining data"); | ||
| 113 | + num_frames = max_num_frames; | ||
| 112 | } | 114 | } |
| 113 | 115 | ||
| 114 | NormalizeFeatures(f.data(), num_frames, feat_dim); | 116 | NormalizeFeatures(f.data(), num_frames, feat_dim); |
| @@ -124,13 +126,19 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl { | @@ -124,13 +126,19 @@ class OfflineRecognizerWhisperImpl : public OfflineRecognizerImpl { | ||
| 124 | (max_num_frames - num_frames) * feat_dim * sizeof(float)); | 126 | (max_num_frames - num_frames) * feat_dim * sizeof(float)); |
| 125 | mel = Transpose12(model_->Allocator(), &mel); | 127 | mel = Transpose12(model_->Allocator(), &mel); |
| 126 | 128 | ||
| 127 | - auto cross_kv = model_->ForwardEncoder(std::move(mel)); | 129 | + try { |
| 130 | + auto cross_kv = model_->ForwardEncoder(std::move(mel)); | ||
| 128 | 131 | ||
| 129 | - auto results = | ||
| 130 | - decoder_->Decode(std::move(cross_kv.first), std::move(cross_kv.second)); | 132 | + auto results = decoder_->Decode(std::move(cross_kv.first), |
| 133 | + std::move(cross_kv.second)); | ||
| 131 | 134 | ||
| 132 | - auto r = Convert(results[0], symbol_table_); | ||
| 133 | - s->SetResult(r); | 135 | + auto r = Convert(results[0], symbol_table_); |
| 136 | + s->SetResult(r); | ||
| 137 | + } catch (const Ort::Exception &ex) { | ||
| 138 | + SHERPA_ONNX_LOGE("\n\nCaught exception:\n\n%s\n\nReturn an empty result", | ||
| 139 | + ex.what()); | ||
| 140 | + return; | ||
| 141 | + } | ||
| 134 | } | 142 | } |
| 135 | 143 | ||
| 136 | private: | 144 | private: |
-
请 注册 或 登录 后发表评论