frankyoujian
Committed by GitHub

Reinitialize context state after Reset stream when using contexts (#257)

@@ -228,7 +228,15 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl { @@ -228,7 +228,15 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl {
228 // we keep the decoder_out 228 // we keep the decoder_out
229 decoder_->UpdateDecoderOut(&s->GetResult()); 229 decoder_->UpdateDecoderOut(&s->GetResult());
230 Ort::Value decoder_out = std::move(s->GetResult().decoder_out); 230 Ort::Value decoder_out = std::move(s->GetResult().decoder_out);
231 - s->SetResult(decoder_->GetEmptyResult()); 231 +
  232 + auto r = decoder_->GetEmptyResult();
  233 + if (config_.decoding_method == "modified_beam_search" &&
  234 + nullptr != s->GetContextGraph()) {
  235 + for (auto it = r.hyps.begin(); it != r.hyps.end(); ++it) {
  236 + it->second.context_state = s->GetContextGraph()->Root();
  237 + }
  238 + }
  239 + s->SetResult(r);
232 s->GetResult().decoder_out = std::move(decoder_out); 240 s->GetResult().decoder_out = std::move(decoder_out);
233 241
234 // Note: We only update counters. The underlying audio samples 242 // Note: We only update counters. The underlying audio samples