-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bae5c3
commit fe31189
Showing
12 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// sherpa-onnx/csrc/offline-sense-voice-model-config.cc | ||
// | ||
// Copyright (c) 2023 Xiaomi Corporation | ||
|
||
#include "sherpa-onnx/csrc/offline-sense-voice-model-config.h" | ||
|
||
#include "sherpa-onnx/csrc/file-utils.h" | ||
#include "sherpa-onnx/csrc/macros.h" | ||
|
||
namespace sherpa_onnx { | ||
|
||
void OfflineSenseVoiceModelConfig::Register(ParseOptions *po) { | ||
po->Register("sense-voice", &model, "Path to model.onnx of SenseVoice."); | ||
po->Register( | ||
"sense-voice-language", &language, | ||
"Valid values: auto, zh, en, ja, ko, yue. If left empty, auto is used"); | ||
po->Register( | ||
"sense-voice-use-itn", &use_itn, | ||
"True to enable inverse text normalization. False to disable it."); | ||
} | ||
|
||
bool OfflineSenseVoiceModelConfig::Validate() const { | ||
if (!FileExists(model)) { | ||
SHERPA_ONNX_LOGE("SenseVoice model '%s' does not exist", model.c_str()); | ||
return false; | ||
} | ||
|
||
if (!language.empty()) { | ||
if (language != "auto" && language != "zh" && language != "en" && | ||
language != "ja" && language != "ko" && language != "yue") { | ||
SHERPA_ONNX_LOGE( | ||
"Invalid sense-voice-language: '%s'. Valid values are: auto, zh, en, " | ||
"ja, ko, yue. Or you can leave it empty to use 'auto'", | ||
language.c_str()); | ||
|
||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
std::string OfflineSenseVoiceModelConfig::ToString() const { | ||
std::ostringstream os; | ||
|
||
os << "OfflineSenseVoiceModelConfig("; | ||
os << "model=\"" << model << "\", "; | ||
os << "language=\"" << language << "\", "; | ||
os << "use_itn=" << (use_itn ? "True" : "False") << ")"; | ||
|
||
return os.str(); | ||
} | ||
|
||
} // namespace sherpa_onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// sherpa-onnx/csrc/offline-sense-voice-model-config.h | ||
// | ||
// Copyright (c) 2023 Xiaomi Corporation | ||
#ifndef SHERPA_ONNX_CSRC_OFFLINE_SENSE_VOICE_MODEL_CONFIG_H_ | ||
#define SHERPA_ONNX_CSRC_OFFLINE_SENSE_VOICE_MODEL_CONFIG_H_ | ||
|
||
#include <string> | ||
|
||
#include "sherpa-onnx/csrc/parse-options.h" | ||
|
||
namespace sherpa_onnx { | ||
|
||
struct OfflineSenseVoiceModelConfig { | ||
std::string model; | ||
|
||
// "" or "auto" to let the model recognize the language | ||
// valid values: | ||
// zh, en, ja, ko, yue, auto | ||
std::string language = "auto"; | ||
|
||
// true to use inverse text normalization | ||
// false to not use inverse text normalization | ||
bool use_itn = false; | ||
|
||
OfflineSenseVoiceModelConfig() = default; | ||
explicit OfflineSenseVoiceModelConfig(const std::string &model, | ||
const std::string &language, | ||
bool use_itn) | ||
: model(model), language(language), use_itn(use_itn) {} | ||
|
||
void Register(ParseOptions *po); | ||
bool Validate() const; | ||
|
||
std::string ToString() const; | ||
}; | ||
|
||
} // namespace sherpa_onnx | ||
|
||
#endif // SHERPA_ONNX_CSRC_OFFLINE_SENSE_VOICE_MODEL_CONFIG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
sherpa-onnx/python/csrc/offline-sense-voice-model-config.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// sherpa-onnx/python/csrc/offline-sense-voice-model-config.cc | ||
// | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
|
||
#include "sherpa-onnx/csrc/offline-sense-voice-model-config.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "sherpa-onnx/python/csrc/offline-sense-voice-model-config.h" | ||
|
||
namespace sherpa_onnx { | ||
|
||
void PybindOfflineSenseVoiceModelConfig(py::module *m) { | ||
using PyClass = OfflineSenseVoiceModelConfig; | ||
py::class_<PyClass>(*m, "OfflineSenseVoiceModelConfig") | ||
.def(py::init<>()) | ||
.def(py::init<const std::string &, const std::string &, bool>(), | ||
py::arg("model"), py::arg("language"), py::arg("use_itn")) | ||
.def_readwrite("model", &PyClass::model) | ||
.def_readwrite("language", &PyClass::language) | ||
.def_readwrite("use_itn", &PyClass::use_itn) | ||
.def("__str__", &PyClass::ToString); | ||
} | ||
|
||
} // namespace sherpa_onnx |
16 changes: 16 additions & 0 deletions
16
sherpa-onnx/python/csrc/offline-sense-voice-model-config.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// sherpa-onnx/python/csrc/offline-sense-voice-model-config.h | ||
// | ||
// Copyright (c) 2024 Xiaomi Corporation | ||
|
||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SENSE_VOICE_MODEL_CONFIG_H_ | ||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SENSE_VOICE_MODEL_CONFIG_H_ | ||
|
||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h" | ||
|
||
namespace sherpa_onnx { | ||
|
||
void PybindOfflineSenseVoiceModelConfig(py::module *m); | ||
|
||
} | ||
|
||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_SENSE_VOICE_MODEL_CONFIG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters