Skip to content

Commit a60d6d0

Browse files
authored
Fix matcha tts zh-en model (k2-fsa#2851)
1 parent 172c906 commit a60d6d0

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

scripts/matcha-tts/zh-en/generate_lexicon.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
from pypinyin import Style, lazy_pinyin, load_phrases_dict, phrases_dict, pinyin_dict
3+
from pypinyin import Style, pinyin, load_phrases_dict, phrases_dict, pinyin_dict
44

55
load_phrases_dict(
66
{
@@ -28,7 +28,8 @@ def main():
2828
continue
2929

3030
w = chr(key)
31-
tokens = lazy_pinyin(w, style=Style.TONE3, tone_sandhi=True)[0]
31+
tokens = pinyin(w, style=Style.TONE3, neutral_tone_with_five=True)[0][0]
32+
3233
if tokens == "shei2":
3334
tokens = "shui2"
3435

@@ -43,15 +44,17 @@ def main():
4344
for key in phrases:
4445
if key in user_defined:
4546
continue
46-
tokens = lazy_pinyin(key, style=Style.TONE3, tone_sandhi=True)
47+
tokens = pinyin(key, style=Style.TONE3, neutral_tone_with_five=True)
4748
for i in range(len(tokens)):
4849
if tokens[i] == "shei2":
4950
tokens[i] = "shui2"
5051

5152
if tokens[i][-1] not in ("1", "2", "3", "4", "5"):
5253
tokens[i] += "1"
5354

54-
tokens = " ".join(tokens)
55+
flatten = [t[0] for t in tokens]
56+
57+
tokens = " ".join(flatten)
5558

5659
f.write(f"{key} {tokens}\n")
5760

sherpa-onnx/csrc/matcha-tts-lexicon.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@ class MatchaTtsLexicon::Impl {
266266
}
267267
}
268268

269-
if (IsAlphaOrPunct(w.front())) {
270-
ans.push_back(token2id_.at(" "));
271-
}
272-
273269
if (debug_) {
274270
std::ostringstream os;
275271
os << w << ": ";

sherpa-onnx/csrc/offline-tts-matcha-impl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,16 @@ class OfflineTtsMatchaImpl : public OfflineTtsImpl {
431431

432432
std::vector<int64_t> x;
433433
x.reserve(num_tokens);
434-
for (const auto &k : tokens) {
435-
x.insert(x.end(), k.begin(), k.end());
434+
if (config_.model.debug) {
435+
for (const auto &k : tokens) {
436+
x.insert(x.end(), k.begin(), k.end());
437+
}
438+
std::ostringstream oss;
439+
for (int32_t i : x) {
440+
oss << i << ", ";
441+
}
442+
oss << "\n";
443+
SHERPA_ONNX_LOGE("%s\n", oss.str().c_str());
436444
}
437445

438446
auto memory_info =

0 commit comments

Comments
 (0)