Skip to content
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

Support German TTS #394

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading