Support vits models from piper (#390)

This commit is contained in:
Fangjun Kuang
2023-10-26 14:10:24 +08:00
committed by GitHub
parent a8fed2a9ce
commit 44512858d6
5 changed files with 130 additions and 49 deletions

View File

@@ -83,8 +83,8 @@ static std::vector<int32_t> ConvertTokensToIds(
Lexicon::Lexicon(const std::string &lexicon, const std::string &tokens,
const std::string &punctuations, const std::string &language,
bool debug /*= false*/)
: debug_(debug) {
bool debug /*= false*/, bool is_piper /*= false*/)
: debug_(debug), is_piper_(is_piper) {
InitLanguage(language);
{
@@ -103,8 +103,9 @@ Lexicon::Lexicon(const std::string &lexicon, const std::string &tokens,
#if __ANDROID_API__ >= 9
Lexicon::Lexicon(AAssetManager *mgr, const std::string &lexicon,
const std::string &tokens, const std::string &punctuations,
const std::string &language, bool debug /*= false*/)
: debug_(debug) {
const std::string &language, bool debug /*= false*/,
bool is_piper /*= false*/)
: debug_(debug), is_piper_(is_piper) {
InitLanguage(language);
{
@@ -206,6 +207,10 @@ std::vector<int64_t> Lexicon::ConvertTextToTokenIdsEnglish(
int32_t blank = token2id_.at(" ");
std::vector<int64_t> ans;
if (is_piper_) {
ans.push_back(token2id_.at("^")); // sos
}
for (const auto &w : words) {
if (punctuations_.count(w)) {
ans.push_back(token2id_.at(w));
@@ -227,6 +232,10 @@ std::vector<int64_t> Lexicon::ConvertTextToTokenIdsEnglish(
ans.resize(ans.size() - 1);
}
if (is_piper_) {
ans.push_back(token2id_.at("$")); // eos
}
return ans;
}