Add C++ support for MatchaTTS models not from icefall. (#1834)

This commit is contained in:
Fangjun Kuang
2025-02-10 15:38:29 +08:00
committed by GitHub
parent 7d62ccf1fe
commit 9559a10bd3
5 changed files with 61 additions and 7 deletions

View File

@@ -214,7 +214,7 @@ class OfflineTtsMatchaImpl : public OfflineTtsImpl {
}
std::vector<TokenIDs> token_ids =
frontend_->ConvertTextToTokenIds(text, "en-US");
frontend_->ConvertTextToTokenIds(text, meta_data.voice);
if (token_ids.empty() ||
(token_ids.size() == 1 && token_ids[0].tokens.empty())) {

View File

@@ -21,6 +21,8 @@ struct OfflineTtsMatchaModelMetaData {
int32_t has_espeak = 0;
int32_t use_eos_bos = 0;
int32_t pad_id = 0;
std::string voice;
};
} // namespace sherpa_onnx

View File

@@ -83,15 +83,32 @@ class OfflineTtsMatchaModel::Impl {
Ort::Value sid_tensor =
Ort::Value::CreateTensor(memory_info, &sid, 1, &scale_shape, 1);
std::array<float, 2> scales = {noise_scale, length_scale};
int64_t scales_shape = 2;
Ort::Value scales_tensor = Ort::Value::CreateTensor(
memory_info, scales.data(), scales.size(), &scales_shape, 1);
std::vector<Ort::Value> inputs;
inputs.reserve(5);
inputs.push_back(std::move(x));
inputs.push_back(std::move(x_length));
inputs.push_back(std::move(noise_scale_tensor));
inputs.push_back(std::move(length_scale_tensor));
if (input_names_[2] == "scales") {
// for models from
// https://github.com/shivammehta25/Matcha-TTS
inputs.push_back(std::move(scales_tensor));
} else {
// for models from icefall
inputs.push_back(std::move(noise_scale_tensor));
inputs.push_back(std::move(length_scale_tensor));
}
if (input_names_.size() == 5 && input_names_.back() == "sid") {
// for models from icefall
inputs.push_back(std::move(sid_tensor));
// Note that we have not supported multi-speaker tts models from
// https://github.com/shivammehta25/Matcha-TTS
}
auto out =
@@ -145,6 +162,8 @@ class OfflineTtsMatchaModel::Impl {
SHERPA_ONNX_READ_META_DATA(meta_data_.has_espeak, "has_espeak");
SHERPA_ONNX_READ_META_DATA(meta_data_.use_eos_bos, "use_eos_bos");
SHERPA_ONNX_READ_META_DATA(meta_data_.pad_id, "pad_id");
SHERPA_ONNX_READ_META_DATA_STR_WITH_DEFAULT(meta_data_.voice, "voice",
"en-us");
}
private: