-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add context biasing for mobile #568
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Left some minor comments.
@@ -85,14 +85,17 @@ class SherpaOnnx( | |||
acceptWaveform(ptr, samples, sampleRate) | |||
|
|||
fun inputFinished() = inputFinished(ptr) | |||
fun reset(recreate: Boolean = false) = reset(ptr, recreate = recreate) | |||
fun reset(recreate: Boolean = false, hotWords: String = "") = reset(ptr, recreate, hotWords) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also update
sherpa-onnx/android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx/SherpaOnnx.kt
Line 123 in 558f5e3
fun reset(recreate: Boolean = false) = reset(ptr, recreate = recreate) |
@@ -85,14 +85,17 @@ class SherpaOnnx( | |||
acceptWaveform(ptr, samples, sampleRate) | |||
|
|||
fun inputFinished() = inputFinished(ptr) | |||
fun reset(recreate: Boolean = false) = reset(ptr, recreate = recreate) | |||
fun reset(recreate: Boolean = false, hotWords: String = "") = reset(ptr, recreate, hotWords) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun reset(recreate: Boolean = false, hotWords: String = "") = reset(ptr, recreate, hotWords) | |
fun reset(recreate: Boolean = false, hotwords: String = "") = reset(ptr, recreate, hotwords) |
auto stream = recognizer_.CreateStream(keywords); | ||
// Set new keywords failed, the stream_ will not be updated. | ||
if (stream != nullptr) { | ||
stream_ = std::move(stream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also use SHERPA_ONNX_LOGE()
to print some logs here saying it failed to set the hotwords?
sherpa-onnx/jni/jni.cc
Outdated
std::string keywords_str = p_keywords; | ||
model->Reset(recreate, keywords_str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string keywords_str = p_keywords; | |
model->Reset(recreate, keywords_str); | |
model->Reset(recreate, p_keywords); |
You can pass p_keywords
directly to the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But p_keywords
is const char *
while the reset method accept std::string
? It's incorrect type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But
p_keywords
isconst char *
while the reset method acceptstd::string
? It's incorrect type
Does it cause compiler errors? If yes, please post the error logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, it works normally
swift-api-examples/SherpaOnnx.swift
Outdated
} | ||
|
||
words.withCString { cString in | ||
stream = CreateOnlineStreamWithHotwords(recognizer, cString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please free the previous stream
to avoid memory leak.
@csukuangfj I updated the fixes |
Thanks! Only one comment left now. (I just added one.) |
swift-api-examples/SherpaOnnx.swift
Outdated
/// If hotWords is an empty string, it just recreates the decoding stream | ||
/// If hotWords is not empty, it will create a new decoding stream with | ||
/// the given hotWords appended to the default hotWords. | ||
func reset(hotWords: String? = nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func reset(hotWords: String? = nil) { | |
func reset(hotwords: String? = nil) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
sherpa-onnx/jni/jni.cc
Outdated
if (recreate) { | ||
stream_ = recognizer_.CreateStream(); | ||
} else { | ||
} else { | ||
recognizer_.Reset(stream_.get()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you indent the statements?
You can run
cd /path/to/sherpa-onnx
./scripts/check_style_cpplint.sh
./scripts/check_style_cpplint.sh 1
./scripts/check_style_cpplint.sh 2
to check your code style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you indent the statements?
You can run
cd /path/to/sherpa-onnx ./scripts/check_style_cpplint.sh ./scripts/check_style_cpplint.sh 1 ./scripts/check_style_cpplint.sh 2
to check your code style.
Done!
All code style checks passed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks good to me except for the C++ code style.
Thank you again for your contribution! |
I implement context biasing (hot words) for android/ios frontend by calling: