-
Notifications
You must be signed in to change notification settings - Fork 473
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
Allow modify model config at decode time for ASR #1124
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -308,8 +308,27 @@ struct SherpaOnnxOfflineStream { | |||||
: impl(std::move(p)) {} | ||||||
}; | ||||||
|
||||||
sherpa_onnx::OfflineRecognizerConfig convertConfig( | ||||||
const SherpaOnnxOfflineRecognizerConfig *config); | ||||||
SherpaOnnxOfflineRecognizer *CreateOfflineRecognizer( | ||||||
const SherpaOnnxOfflineRecognizerConfig *config) { | ||||||
sherpa_onnx::OfflineRecognizerConfig recognizer_config = | ||||||
convertConfig(config); | ||||||
|
||||||
if (!recognizer_config.Validate()) { | ||||||
SHERPA_ONNX_LOGE("Errors in config"); | ||||||
return nullptr; | ||||||
} | ||||||
|
||||||
SherpaOnnxOfflineRecognizer *recognizer = new SherpaOnnxOfflineRecognizer; | ||||||
|
||||||
recognizer->impl = | ||||||
std::make_unique<sherpa_onnx::OfflineRecognizer>(recognizer_config); | ||||||
|
||||||
return recognizer; | ||||||
} | ||||||
sherpa_onnx::OfflineRecognizerConfig convertConfig( | ||||||
const SherpaOnnxOfflineRecognizerConfig *config) { | ||||||
sherpa_onnx::OfflineRecognizerConfig recognizer_config; | ||||||
|
||||||
recognizer_config.feat_config.sampling_rate = | ||||||
|
@@ -398,17 +417,15 @@ SherpaOnnxOfflineRecognizer *CreateOfflineRecognizer( | |||||
SHERPA_ONNX_LOGE("%s", recognizer_config.ToString().c_str()); | ||||||
} | ||||||
|
||||||
if (!recognizer_config.Validate()) { | ||||||
SHERPA_ONNX_LOGE("Errors in config"); | ||||||
return nullptr; | ||||||
} | ||||||
|
||||||
SherpaOnnxOfflineRecognizer *recognizer = new SherpaOnnxOfflineRecognizer; | ||||||
|
||||||
recognizer->impl = | ||||||
std::make_unique<sherpa_onnx::OfflineRecognizer>(recognizer_config); | ||||||
return recognizer_config; | ||||||
} | ||||||
|
||||||
return recognizer; | ||||||
void SetSherpaOnnxOfflineRecognizerConfig( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
const SherpaOnnxOfflineRecognizer *recognizer, | ||||||
const SherpaOnnxOfflineRecognizerConfig *config){ | ||||||
sherpa_onnx::OfflineRecognizerConfig recognizer_config = | ||||||
convertConfig(config); | ||||||
recognizer->impl->SetConfig(recognizer_config); | ||||||
} | ||||||
|
||||||
void DestroyOfflineRecognizer(SherpaOnnxOfflineRecognizer *recognizer) { | ||||||
|
@@ -461,6 +478,13 @@ const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult( | |||||
pText[text.size()] = 0; | ||||||
r->text = pText; | ||||||
|
||||||
//lang | ||||||
const auto &lang = result.lang; | ||||||
char *c_lang = new char[lang.size() + 1]; | ||||||
std::copy(lang.begin(), lang.end(), c_lang); | ||||||
c_lang[lang.size()] = '\0'; | ||||||
r->lang = c_lang; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to use
to avoid memory leak. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
|
||||||
// copy json | ||||||
std::string json = result.AsJsonString(); | ||||||
char *pJson = new char[json.size() + 1]; | ||||||
|
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.
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.