Refactor TTS Android code to support jieba for Chinese TTS models (#800)

This commit is contained in:
Fangjun Kuang
2024-04-22 17:21:05 +08:00
committed by GitHub
parent 494cb5c733
commit 7f3b9ffe5d
40 changed files with 352 additions and 285 deletions

View File

@@ -32,7 +32,7 @@ bool AudioTaggingModelConfig::Validate() const {
}
if (!ced.empty() && !FileExists(ced)) {
SHERPA_ONNX_LOGE("CED model file %s does not exist", ced.c_str());
SHERPA_ONNX_LOGE("CED model file '%s' does not exist", ced.c_str());
return false;
}

View File

@@ -48,7 +48,7 @@ bool AudioTaggingConfig::Validate() const {
}
if (!FileExists(labels)) {
SHERPA_ONNX_LOGE("--labels %s does not exist", labels.c_str());
SHERPA_ONNX_LOGE("--labels '%s' does not exist", labels.c_str());
return false;
}

View File

@@ -7,7 +7,7 @@
#include <fstream>
#include <string>
#include "sherpa-onnx/csrc/log.h"
#include "sherpa-onnx/csrc/macros.h"
namespace sherpa_onnx {
@@ -17,7 +17,7 @@ bool FileExists(const std::string &filename) {
void AssertFileExists(const std::string &filename) {
if (!FileExists(filename)) {
SHERPA_ONNX_LOG(FATAL) << filename << " does not exist!";
SHERPA_ONNX_LOGE("filename '%s' does not exist", filename.c_str());
exit(-1);
}
}

View File

@@ -146,6 +146,14 @@ class JiebaLexicon::Impl {
if (token2id_.count(p.first) && !token2id_.count(p.second)) {
token2id_[p.second] = token2id_[p.first];
}
if (!token2id_.count(p.first) && token2id_.count(p.second)) {
token2id_[p.first] = token2id_[p.second];
}
}
if (!token2id_.count("") && token2id_.count("")) {
token2id_[""] = token2id_[""];
}
}

View File

@@ -101,7 +101,8 @@ bool KeywordSpotterConfig::Validate() const {
// Solution: take keyword_file variable is directly
// parsed as a string of keywords
if (!std::ifstream(keywords_file.c_str()).good()) {
SHERPA_ONNX_LOGE("Keywords file %s does not exist.", keywords_file.c_str());
SHERPA_ONNX_LOGE("Keywords file '%s' does not exist.",
keywords_file.c_str());
return false;
}
#endif

View File

@@ -34,7 +34,7 @@ void OfflineCtcFstDecoderConfig::Register(ParseOptions *po) {
bool OfflineCtcFstDecoderConfig::Validate() const {
if (!graph.empty() && !FileExists(graph)) {
SHERPA_ONNX_LOGE("graph: %s does not exist", graph.c_str());
SHERPA_ONNX_LOGE("graph: '%s' does not exist", graph.c_str());
return false;
}
return true;

View File

@@ -22,7 +22,7 @@ void OfflineLMConfig::Register(ParseOptions *po) {
bool OfflineLMConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("%s does not exist", model.c_str());
SHERPA_ONNX_LOGE("'%s' does not exist", model.c_str());
return false;
}

View File

@@ -16,7 +16,7 @@ void OfflineNemoEncDecCtcModelConfig::Register(ParseOptions *po) {
bool OfflineNemoEncDecCtcModelConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("NeMo model: %s does not exist", model.c_str());
SHERPA_ONNX_LOGE("NeMo model: '%s' does not exist", model.c_str());
return false;
}

View File

@@ -15,7 +15,7 @@ void OfflineParaformerModelConfig::Register(ParseOptions *po) {
bool OfflineParaformerModelConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("Paraformer model %s does not exist", model.c_str());
SHERPA_ONNX_LOGE("Paraformer model '%s' does not exist", model.c_str());
return false;
}

View File

@@ -18,19 +18,19 @@ void OfflineTransducerModelConfig::Register(ParseOptions *po) {
bool OfflineTransducerModelConfig::Validate() const {
if (!FileExists(encoder_filename)) {
SHERPA_ONNX_LOGE("transducer encoder: %s does not exist",
SHERPA_ONNX_LOGE("transducer encoder: '%s' does not exist",
encoder_filename.c_str());
return false;
}
if (!FileExists(decoder_filename)) {
SHERPA_ONNX_LOGE("transducer decoder: %s does not exist",
SHERPA_ONNX_LOGE("transducer decoder: '%s' does not exist",
decoder_filename.c_str());
return false;
}
if (!FileExists(joiner_filename)) {
SHERPA_ONNX_LOGE("transducer joiner: %s does not exist",
SHERPA_ONNX_LOGE("transducer joiner: '%s' does not exist",
joiner_filename.c_str());
return false;
}

View File

@@ -35,7 +35,7 @@ bool OfflineTtsVitsModelConfig::Validate() const {
}
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("--vits-model: %s does not exist", model.c_str());
SHERPA_ONNX_LOGE("--vits-model: '%s' does not exist", model.c_str());
return false;
}
@@ -45,31 +45,31 @@ bool OfflineTtsVitsModelConfig::Validate() const {
}
if (!FileExists(tokens)) {
SHERPA_ONNX_LOGE("--vits-tokens: %s does not exist", tokens.c_str());
SHERPA_ONNX_LOGE("--vits-tokens: '%s' does not exist", tokens.c_str());
return false;
}
if (!data_dir.empty()) {
if (!FileExists(data_dir + "/phontab")) {
SHERPA_ONNX_LOGE("%s/phontab does not exist. Skipping test",
SHERPA_ONNX_LOGE("'%s/phontab' does not exist. Skipping test",
data_dir.c_str());
return false;
}
if (!FileExists(data_dir + "/phonindex")) {
SHERPA_ONNX_LOGE("%s/phonindex does not exist. Skipping test",
SHERPA_ONNX_LOGE("'%s/phonindex' does not exist. Skipping test",
data_dir.c_str());
return false;
}
if (!FileExists(data_dir + "/phondata")) {
SHERPA_ONNX_LOGE("%s/phondata does not exist. Skipping test",
SHERPA_ONNX_LOGE("'%s/phondata' does not exist. Skipping test",
data_dir.c_str());
return false;
}
if (!FileExists(data_dir + "/intonations")) {
SHERPA_ONNX_LOGE("%s/intonations does not exist.", data_dir.c_str());
SHERPA_ONNX_LOGE("'%s/intonations' does not exist.", data_dir.c_str());
return false;
}
}
@@ -82,7 +82,8 @@ bool OfflineTtsVitsModelConfig::Validate() const {
for (const auto &f : required_files) {
if (!FileExists(dict_dir + "/" + f)) {
SHERPA_ONNX_LOGE("%s/%s does not exist.", data_dir.c_str(), f.c_str());
SHERPA_ONNX_LOGE("'%s/%s' does not exist.", data_dir.c_str(),
f.c_str());
return false;
}
}

View File

@@ -42,7 +42,7 @@ bool OfflineTtsConfig::Validate() const {
SplitStringToVector(rule_fsts, ",", false, &files);
for (const auto &f : files) {
if (!FileExists(f)) {
SHERPA_ONNX_LOGE("Rule fst %s does not exist. ", f.c_str());
SHERPA_ONNX_LOGE("Rule fst '%s' does not exist. ", f.c_str());
return false;
}
}
@@ -53,7 +53,7 @@ bool OfflineTtsConfig::Validate() const {
SplitStringToVector(rule_fars, ",", false, &files);
for (const auto &f : files) {
if (!FileExists(f)) {
SHERPA_ONNX_LOGE("Rule far %s does not exist. ", f.c_str());
SHERPA_ONNX_LOGE("Rule far '%s' does not exist. ", f.c_str());
return false;
}
}

View File

@@ -18,7 +18,7 @@ void OfflineWenetCtcModelConfig::Register(ParseOptions *po) {
bool OfflineWenetCtcModelConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("WeNet model: %s does not exist", model.c_str());
SHERPA_ONNX_LOGE("WeNet model: '%s' does not exist", model.c_str());
return false;
}

View File

@@ -48,7 +48,8 @@ bool OfflineWhisperModelConfig::Validate() const {
}
if (!FileExists(encoder)) {
SHERPA_ONNX_LOGE("whisper encoder file %s does not exist", encoder.c_str());
SHERPA_ONNX_LOGE("whisper encoder file '%s' does not exist",
encoder.c_str());
return false;
}
@@ -58,7 +59,8 @@ bool OfflineWhisperModelConfig::Validate() const {
}
if (!FileExists(decoder)) {
SHERPA_ONNX_LOGE("whisper decoder file %s does not exist", decoder.c_str());
SHERPA_ONNX_LOGE("whisper decoder file '%s' does not exist",
decoder.c_str());
return false;
}

View File

@@ -21,7 +21,7 @@ bool OfflineZipformerAudioTaggingModelConfig::Validate() const {
}
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("--zipformer-model: %s does not exist", model.c_str());
SHERPA_ONNX_LOGE("--zipformer-model: '%s' does not exist", model.c_str());
return false;
}

View File

@@ -15,7 +15,7 @@ void OfflineZipformerCtcModelConfig::Register(ParseOptions *po) {
bool OfflineZipformerCtcModelConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("zipformer CTC model file %s does not exist",
SHERPA_ONNX_LOGE("zipformer CTC model file '%s' does not exist",
model.c_str());
return false;
}

View File

@@ -31,7 +31,7 @@ void OnlineCtcFstDecoderConfig::Register(ParseOptions *po) {
bool OnlineCtcFstDecoderConfig::Validate() const {
if (!graph.empty() && !FileExists(graph)) {
SHERPA_ONNX_LOGE("graph: %s does not exist", graph.c_str());
SHERPA_ONNX_LOGE("graph: '%s' does not exist", graph.c_str());
return false;
}
return true;

View File

@@ -22,7 +22,7 @@ void OnlineLMConfig::Register(ParseOptions *po) {
bool OnlineLMConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("%s does not exist", model.c_str());
SHERPA_ONNX_LOGE("'%s' does not exist", model.c_str());
return false;
}

View File

@@ -45,7 +45,7 @@ bool OnlineModelConfig::Validate() const {
}
if (!FileExists(tokens)) {
SHERPA_ONNX_LOGE("tokens: %s does not exist", tokens.c_str());
SHERPA_ONNX_LOGE("tokens: '%s' does not exist", tokens.c_str());
return false;
}

View File

@@ -18,12 +18,12 @@ void OnlineParaformerModelConfig::Register(ParseOptions *po) {
bool OnlineParaformerModelConfig::Validate() const {
if (!FileExists(encoder)) {
SHERPA_ONNX_LOGE("Paraformer encoder %s does not exist", encoder.c_str());
SHERPA_ONNX_LOGE("Paraformer encoder '%s' does not exist", encoder.c_str());
return false;
}
if (!FileExists(decoder)) {
SHERPA_ONNX_LOGE("Paraformer decoder %s does not exist", decoder.c_str());
SHERPA_ONNX_LOGE("Paraformer decoder '%s' does not exist", decoder.c_str());
return false;
}

View File

@@ -18,17 +18,19 @@ void OnlineTransducerModelConfig::Register(ParseOptions *po) {
bool OnlineTransducerModelConfig::Validate() const {
if (!FileExists(encoder)) {
SHERPA_ONNX_LOGE("transducer encoder: %s does not exist", encoder.c_str());
SHERPA_ONNX_LOGE("transducer encoder: '%s' does not exist",
encoder.c_str());
return false;
}
if (!FileExists(decoder)) {
SHERPA_ONNX_LOGE("transducer decoder: %s does not exist", decoder.c_str());
SHERPA_ONNX_LOGE("transducer decoder: '%s' does not exist",
decoder.c_str());
return false;
}
if (!FileExists(joiner)) {
SHERPA_ONNX_LOGE("joiner: %s does not exist", joiner.c_str());
SHERPA_ONNX_LOGE("joiner: '%s' does not exist", joiner.c_str());
return false;
}

View File

@@ -21,7 +21,7 @@ void OnlineWenetCtcModelConfig::Register(ParseOptions *po) {
bool OnlineWenetCtcModelConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("WeNet CTC model %s does not exist", model.c_str());
SHERPA_ONNX_LOGE("WeNet CTC model '%s' does not exist", model.c_str());
return false;
}

View File

@@ -22,7 +22,8 @@ bool OnlineZipformer2CtcModelConfig::Validate() const {
}
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("--zipformer2-ctc-model %s does not exist", model.c_str());
SHERPA_ONNX_LOGE("--zipformer2-ctc-model '%s' does not exist",
model.c_str());
return false;
}

View File

@@ -44,7 +44,8 @@ bool SileroVadModelConfig::Validate() const {
}
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("Silero vad model file %s does not exist", model.c_str());
SHERPA_ONNX_LOGE("Silero vad model file '%s' does not exist",
model.c_str());
return false;
}

View File

@@ -31,7 +31,7 @@ bool SpeakerEmbeddingExtractorConfig::Validate() const {
}
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("--speaker-embedding-model: %s does not exist",
SHERPA_ONNX_LOGE("--speaker-embedding-model: '%s' does not exist",
model.c_str());
return false;
}

View File

@@ -43,7 +43,8 @@ bool SpokenLanguageIdentificationWhisperConfig::Validate() const {
}
if (!FileExists(encoder)) {
SHERPA_ONNX_LOGE("whisper encoder file %s does not exist", encoder.c_str());
SHERPA_ONNX_LOGE("whisper encoder file '%s' does not exist",
encoder.c_str());
return false;
}
@@ -53,7 +54,8 @@ bool SpokenLanguageIdentificationWhisperConfig::Validate() const {
}
if (!FileExists(decoder)) {
SHERPA_ONNX_LOGE("whisper decoder file %s does not exist", decoder.c_str());
SHERPA_ONNX_LOGE("whisper decoder file '%s' does not exist",
decoder.c_str());
return false;
}