decoder for open vocabulary keyword spotting (#505)
* various fixes to ContextGraph to support open vocabulary keywords decoder * Add keyword spotter runtime * Add binary * First version works * Minor fixes * update text2token * default values * Add jni for kws * add kws android project * Minor fixes * Remove unused interface * Minor fixes * Add workflow * handle extra info in texts * Minor fixes * Add more comments * Fix ci * fix cpp style * Add input box in android demo so that users can specify their keywords * Fix cpp style * Fix comments * Minor fixes * Minor fixes * minor fixes * Minor fixes * Minor fixes * Add CI * Fix code style * cpplint * Fix comments * Fix error
This commit is contained in:
@@ -51,6 +51,25 @@ class OnlineStream::Impl {
|
||||
|
||||
OnlineTransducerDecoderResult &GetResult() { return result_; }
|
||||
|
||||
void SetKeywordResult(const TransducerKeywordResult &r) {
|
||||
keyword_result_ = r;
|
||||
}
|
||||
TransducerKeywordResult &GetKeywordResult(bool remove_duplicates) {
|
||||
if (remove_duplicates) {
|
||||
if (!prev_keyword_result_.timestamps.empty() &&
|
||||
!keyword_result_.timestamps.empty() &&
|
||||
keyword_result_.timestamps[0] <=
|
||||
prev_keyword_result_.timestamps.back()) {
|
||||
return empty_keyword_result_;
|
||||
} else {
|
||||
prev_keyword_result_ = keyword_result_;
|
||||
}
|
||||
return keyword_result_;
|
||||
} else {
|
||||
return keyword_result_;
|
||||
}
|
||||
}
|
||||
|
||||
OnlineCtcDecoderResult &GetCtcResult() { return ctc_result_; }
|
||||
|
||||
void SetCtcResult(const OnlineCtcDecoderResult &r) { ctc_result_ = r; }
|
||||
@@ -93,6 +112,9 @@ class OnlineStream::Impl {
|
||||
int32_t start_frame_index_ = 0; // never reset
|
||||
int32_t segment_ = 0;
|
||||
OnlineTransducerDecoderResult result_;
|
||||
TransducerKeywordResult prev_keyword_result_;
|
||||
TransducerKeywordResult keyword_result_;
|
||||
TransducerKeywordResult empty_keyword_result_;
|
||||
OnlineCtcDecoderResult ctc_result_;
|
||||
std::vector<Ort::Value> states_; // states for transducer or ctc models
|
||||
std::vector<float> paraformer_feat_cache_;
|
||||
@@ -149,6 +171,15 @@ OnlineTransducerDecoderResult &OnlineStream::GetResult() {
|
||||
return impl_->GetResult();
|
||||
}
|
||||
|
||||
void OnlineStream::SetKeywordResult(const TransducerKeywordResult &r) {
|
||||
impl_->SetKeywordResult(r);
|
||||
}
|
||||
|
||||
TransducerKeywordResult &OnlineStream::GetKeywordResult(
|
||||
bool remove_duplicates /*=false*/) {
|
||||
return impl_->GetKeywordResult(remove_duplicates);
|
||||
}
|
||||
|
||||
OnlineCtcDecoderResult &OnlineStream::GetCtcResult() {
|
||||
return impl_->GetCtcResult();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user