Skip to content

Commit

Permalink
Support VITS TTS models from coqui-ai/TTS (#416)
Browse files Browse the repository at this point in the history
* Support VITS TTS models from coqui-ai/TTS

* release v1.8.9
  • Loading branch information
csukuangfj authored Nov 10, 2023
1 parent ab0e830 commit 61341b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(sherpa-onnx)

set(SHERPA_ONNX_VERSION "1.8.8")
set(SHERPA_ONNX_VERSION "1.8.9")

# Disable warning about
#
Expand Down
29 changes: 22 additions & 7 deletions sherpa-onnx/csrc/lexicon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,27 @@ std::vector<int64_t> Lexicon::ConvertTextToTokenIdsChinese(

std::vector<int64_t> ans;

int32_t blank = -1;
if (token2id_.count(" ")) {
blank = token2id_.at(" ");
}

int32_t sil = -1;
int32_t eos = -1;
if (token2id_.count("sil")) {
sil = token2id_.at("sil");
eos = token2id_.at("eos");
} else {
sil = 0;
}

ans.push_back(sil);
if (sil != -1) {
ans.push_back(sil);
}

for (const auto &w : words) {
if (punctuations_.count(w)) {
ans.push_back(sil);
if (sil != -1) {
ans.push_back(sil);
}
continue;
}

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

const auto &token_ids = word2ids_.at(w);
ans.insert(ans.end(), token_ids.begin(), token_ids.end());
if (blank != -1) {
ans.push_back(blank);
}
}

if (sil != -1) {
ans.push_back(sil);
}
ans.push_back(sil);

if (eos != -1) {
ans.push_back(eos);
}

return ans;
}

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

std::vector<int64_t> ans;
if (is_piper_) {
if (is_piper_ && token2id_.count("^")) {
ans.push_back(token2id_.at("^")); // sos
}

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

if (is_piper_) {
if (is_piper_ && token2id_.count("$")) {
ans.push_back(token2id_.at("$")); // eos
}

Expand Down
3 changes: 2 additions & 1 deletion sherpa-onnx/csrc/offline-tts-vits-model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class OfflineTtsVitsModel::Impl {

std::string comment;
SHERPA_ONNX_READ_META_DATA_STR(comment, "comment");
if (comment.find("piper") != std::string::npos) {
if (comment.find("piper") != std::string::npos ||
comment.find("coqui") != std::string::npos) {
is_piper_ = true;
}
}
Expand Down

0 comments on commit 61341b7

Please sign in to comment.