Skip to content

Commit

Permalink
Support German TTS (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Oct 27, 2023
1 parent 93ef4ee commit fbf4c90
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,13 @@ class MainActivity : AppCompatActivity() {
return
}

Toast.makeText(applicationContext, "Generating...Please wait", Toast.LENGTH_LONG).show()
play.isEnabled = false;
val audio = tts.generate(text = textStr, sid = sidInt, speed = speedFloat)

val filename = application.filesDir.absolutePath + "/generated.wav"
val ok = audio.samples.size > 0 && audio.save(filename)
if (ok) {
play.isEnabled = true
Toast.makeText(
applicationContext,
"Generated! Please click play to listen to it",
Toast.LENGTH_LONG
).show()
} else {
play.isEnabled = false
}
}

Expand All @@ -110,4 +103,4 @@ class MainActivity : AppCompatActivity() {
val config = getOfflineTtsConfig(type = type, debug = true)!!
tts = OfflineTts(assetManager = application.assets, config = config)
}
}
}
10 changes: 7 additions & 3 deletions sherpa-onnx/csrc/lexicon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ std::vector<int64_t> Lexicon::ConvertTextToTokenIds(
switch (language_) {
case Language::kEnglish:
return ConvertTextToTokenIdsEnglish(text);
case Language::kGerman:
return ConvertTextToTokenIdsGerman(text);
case Language::kChinese:
return ConvertTextToTokenIdsChinese(text);
default:
SHERPA_ONNX_LOGE("Unknonw language: %d", static_cast<int32_t>(language_));
SHERPA_ONNX_LOGE("Unknown language: %d", static_cast<int32_t>(language_));
exit(-1);
}

Expand Down Expand Up @@ -246,6 +248,8 @@ void Lexicon::InitLanguage(const std::string &_lang) {
ToLowerCase(&lang);
if (lang == "english") {
language_ = Language::kEnglish;
} else if (lang == "german") {
language_ = Language::kGerman;
} else if (lang == "chinese") {
language_ = Language::kChinese;
} else {
Expand All @@ -269,8 +273,8 @@ void Lexicon::InitLexicon(std::istream &is) {
ToLowerCase(&word);

if (word2ids_.count(word)) {
SHERPA_ONNX_LOGE("Duplicated word: %s", word.c_str());
return;
SHERPA_ONNX_LOGE("Duplicated word: %s. Ignore it.", word.c_str());
continue;
}

while (iss >> phone) {
Expand Down
6 changes: 6 additions & 0 deletions sherpa-onnx/csrc/lexicon.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class Lexicon {
std::vector<int64_t> ConvertTextToTokenIds(const std::string &text) const;

private:
std::vector<int64_t> ConvertTextToTokenIdsGerman(
const std::string &text) const {
return ConvertTextToTokenIdsEnglish(text);
}

std::vector<int64_t> ConvertTextToTokenIdsEnglish(
const std::string &text) const;

Expand All @@ -50,6 +55,7 @@ class Lexicon {
private:
enum class Language {
kEnglish,
kGerman,
kChinese,
kUnknown,
};
Expand Down

0 comments on commit fbf4c90

Please sign in to comment.