Skip to content

Commit 61341b7

Browse files
authored
Support VITS TTS models from coqui-ai/TTS (#416)
* Support VITS TTS models from coqui-ai/TTS * release v1.8.9
1 parent ab0e830 commit 61341b7

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
22
project(sherpa-onnx)
33

4-
set(SHERPA_ONNX_VERSION "1.8.8")
4+
set(SHERPA_ONNX_VERSION "1.8.9")
55

66
# Disable warning about
77
#

sherpa-onnx/csrc/lexicon.cc

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,27 @@ std::vector<int64_t> Lexicon::ConvertTextToTokenIdsChinese(
196196

197197
std::vector<int64_t> ans;
198198

199+
int32_t blank = -1;
200+
if (token2id_.count(" ")) {
201+
blank = token2id_.at(" ");
202+
}
203+
199204
int32_t sil = -1;
200205
int32_t eos = -1;
201206
if (token2id_.count("sil")) {
202207
sil = token2id_.at("sil");
203208
eos = token2id_.at("eos");
204-
} else {
205-
sil = 0;
206209
}
207210

208-
ans.push_back(sil);
211+
if (sil != -1) {
212+
ans.push_back(sil);
213+
}
209214

210215
for (const auto &w : words) {
211216
if (punctuations_.count(w)) {
212-
ans.push_back(sil);
217+
if (sil != -1) {
218+
ans.push_back(sil);
219+
}
213220
continue;
214221
}
215222

@@ -220,11 +227,19 @@ std::vector<int64_t> Lexicon::ConvertTextToTokenIdsChinese(
220227

221228
const auto &token_ids = word2ids_.at(w);
222229
ans.insert(ans.end(), token_ids.begin(), token_ids.end());
230+
if (blank != -1) {
231+
ans.push_back(blank);
232+
}
233+
}
234+
235+
if (sil != -1) {
236+
ans.push_back(sil);
223237
}
224-
ans.push_back(sil);
238+
225239
if (eos != -1) {
226240
ans.push_back(eos);
227241
}
242+
228243
return ans;
229244
}
230245

@@ -252,7 +267,7 @@ std::vector<int64_t> Lexicon::ConvertTextToTokenIdsEnglish(
252267
int32_t blank = token2id_.at(" ");
253268

254269
std::vector<int64_t> ans;
255-
if (is_piper_) {
270+
if (is_piper_ && token2id_.count("^")) {
256271
ans.push_back(token2id_.at("^")); // sos
257272
}
258273

@@ -277,7 +292,7 @@ std::vector<int64_t> Lexicon::ConvertTextToTokenIdsEnglish(
277292
ans.resize(ans.size() - 1);
278293
}
279294

280-
if (is_piper_) {
295+
if (is_piper_ && token2id_.count("$")) {
281296
ans.push_back(token2id_.at("$")); // eos
282297
}
283298

sherpa-onnx/csrc/offline-tts-vits-model.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class OfflineTtsVitsModel::Impl {
8181

8282
std::string comment;
8383
SHERPA_ONNX_READ_META_DATA_STR(comment, "comment");
84-
if (comment.find("piper") != std::string::npos) {
84+
if (comment.find("piper") != std::string::npos ||
85+
comment.find("coqui") != std::string::npos) {
8586
is_piper_ = true;
8687
}
8788
}

0 commit comments

Comments
 (0)