rt16-tts (D433, addendum 3): piper1-gpl 1.8.0's libpiper gives a Piper 1.5 voice the phoneme ids Piper's own Python gives it (piper/phonemize_espeak.py and piper/phoneme_ids.py of the same release). 1. piper_create_with_options read the voice's phoneme_id_map one codepoint a key (get_codepoint takes a key's first codepoint), so the vowel-cluster keys every Piper 1.5 voice has ("aɪ", "aʊ", "ɔɪ", "eɪ", "oʊ") appended their ids to a, e, o and ɔ: each of those went to the voice as two or three phonemes. A key of more than one codepoint now goes to the cluster map alone. 2. libpiper never merged a cluster. The config's "vowel_clusters" now build that map, and each sentence's phonemes, after the (lang) switch flags are taken out, are merged longest first, as _merge_known_vowel_clusters does. Found 2026-11-12: darkman through rt16-tts spoke 69.5 s of the 20 test lines against Python's 61.8 s, with 1,983 ids against 1,689. Verified by tools/tts-test.sh: the ids of piper-tts 1.8.0 for all six voices of the manifest (darkman, thorsten, siwis, serena, pim, nst), and with the noise at 0 darkman's speech exactly as long as Python's on every line. Not sent upstream yet; retire at the first release whose libpiper gives Python's ids. diff -ru a/libpiper/include/piper_impl.hpp b/libpiper/include/piper_impl.hpp --- a/libpiper/include/piper_impl.hpp 2026-09-04 16:40:50.000000000 +0000 +++ b/libpiper/include/piper_impl.hpp 2026-11-12 13:27:20.196981430 +0000 @@ -73,6 +73,9 @@ int sample_rate; int num_speakers; PhonemeIdMap phoneme_id_map; + // vowel clusters (Piper 1.5 voices, config "vowel_clusters"): several codepoints read as one phoneme, longest first + std::map> cluster_id_map; + size_t max_cluster = 0; PinyinIdMap pinyin_id_map; int hop_length = DEFAULT_HOP_LENGTH; PhonemeType phoneme_type = PhonemeType::Espeak; diff -ru a/libpiper/src/piper.cpp b/libpiper/src/piper.cpp --- a/libpiper/src/piper.cpp 2026-09-04 16:40:50.000000000 +0000 +++ b/libpiper/src/piper.cpp 2026-11-12 13:35:51.022088670 +0000 @@ -146,6 +146,31 @@ } } } else { + // vowel clusters, as Piper's Python phonemizer merges them (piper/phonemize_espeak.py, _merge_known_vowel_clusters): + // a cluster whose joined phonemes the id map names is read as that one phoneme + if (config.contains("vowel_clusters") && config.contains("phoneme_id_map")) { + auto &id_map = config["phoneme_id_map"]; + for (auto &cluster : config["vowel_clusters"]) { + std::string joined; + std::u32string cps; + for (auto &part : cluster) { + std::string p = part.get(); + joined += p; + for (auto cp : una::ranges::utf8_view{p}) { + cps.push_back(cp); + } + } + if (cps.size() < 2 || !id_map.contains(joined)) { + continue; + } + std::vector ids; + for (auto &v : id_map[joined]) { + ids.push_back(v.get()); + } + synth->cluster_id_map[cps] = ids; + synth->max_cluster = std::max(synth->max_cluster, cps.size()); + } + } // phoneme to [id] map for espeak/text if (config.contains("phoneme_id_map")) { auto &phoneme_id_map_value = config["phoneme_id_map"]; @@ -155,6 +180,16 @@ if (!from_codepoint) { continue; } + // a key of several codepoints (a vowel cluster such as "aɪ") is not its first codepoint: 1.8.0 appended its + // id to that codepoint's, so every a, e, o and ɔ of a Piper 1.5 voice read two or three phonemes; clusters + // are read through cluster_id_map above + size_t codepoints = 0; + for (unsigned char c : from_phoneme) { + codepoints += (c & 0xC0) != 0x80; + } + if (codepoints > 1) { + continue; + } for (auto &to_id_value : from_phoneme_item.value()) { PhonemeId to_id = to_id_value.get(); synth->phoneme_id_map[*from_codepoint].push_back(to_id); @@ -561,10 +596,11 @@ auto phonemes_iter = phonemes_range.begin(); auto phonemes_end = phonemes_range.end(); + // the sentence's phonemes without the (lang) switch flags, then each cluster merged into one phoneme + std::vector kept; bool in_lang_flag = false; while (phonemes_iter != phonemes_end) { auto phoneme = *phonemes_iter; - if (in_lang_flag) { if (phoneme == U')') { in_lang_flag = false; @@ -572,7 +608,35 @@ } else if (phoneme == U'(') { in_lang_flag = true; } else { + kept.push_back(phoneme); + } + phonemes_iter++; + } + for (size_t at = 0; at < kept.size();) { + const std::vector *cluster_ids = nullptr; + size_t taken = 1; + for (size_t n = std::min(synth->max_cluster, kept.size() - at); n >= 2; n--) { + auto found = synth->cluster_id_map.find(std::u32string(kept.begin() + at, kept.begin() + at + n)); + if (found != synth->cluster_id_map.end()) { + cluster_ids = &found->second; + taken = n; + break; + } + } + auto phoneme = kept[at]; + at += taken; + { auto ids_for_phoneme = synth->phoneme_id_map.find(phoneme); + if (cluster_ids != nullptr) { + for (auto identifier : *cluster_ids) { + sentence_codepoints.push_back(phoneme); + sentence_ids.push_back(identifier); + sentence_codepoints.push_back(phoneme); + sentence_ids.push_back(ID_PAD); + sentence_codepoints.push_back(PHONEME_SEPARATOR); + } + continue; + } if (ids_for_phoneme != synth->phoneme_id_map.end()) { for (auto identifier : ids_for_phoneme->second) { sentence_codepoints.push_back(phoneme); @@ -585,8 +649,6 @@ } } } - - phonemes_iter++; } sentence_codepoints.push_back(PHONEME_EOS);