Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/cpp/piper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ void parsePhonemizeConfig(json &configRoot, PhonemizeConfig &phonemizeConfig) {
auto phonemeTypeStr = configRoot["phoneme_type"].get<std::string>();
if (phonemeTypeStr == "text") {
phonemizeConfig.phonemeType = TextPhonemes;
} else if (phonemeTypeStr == "raw") {
phonemizeConfig.phonemeType = RawPhonemes;
}
}

Expand Down Expand Up @@ -467,7 +469,16 @@ void textToAudio(PiperConfig &config, Voice &voice, std::string text,
spdlog::debug("Phonemizing text: {}", text);
std::vector<std::vector<Phoneme>> phonemes;

if (voice.phonemizeConfig.phonemeType == eSpeakPhonemes) {
if (voice.phonemizeConfig.phonemeType == RawPhonemes) {
// Use text as raw utf-8 phonemes
phonemes.emplace_back();
// UTF-8 wide
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::wstring wide_text = converter.from_bytes(text);
for (wchar_t c : wide_text) {
phonemes.back().push_back(c); // Adds each wide character as a phoneme
}
} else if (voice.phonemizeConfig.phonemeType == eSpeakPhonemes) {
// Use espeak-ng for phonemization
eSpeakPhonemeConfig eSpeakConfig;
eSpeakConfig.voice = voice.phonemizeConfig.eSpeak.voice;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/piper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct PiperConfig {
std::unique_ptr<tashkeel::State> tashkeelState;
};

enum PhonemeType { eSpeakPhonemes, TextPhonemes };
enum PhonemeType { eSpeakPhonemes, TextPhonemes, RawPhonemes };

struct PhonemizeConfig {
PhonemeType phonemeType = eSpeakPhonemes;
Expand Down
8 changes: 7 additions & 1 deletion src/python/piper_train/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def main() -> None:
parser.add_argument(
"--debug", action="store_true", help="Print DEBUG messages to the console"
)
parser.add_argument(
"--raw-phonemes", action="store_true", help="Raw espeak compatible phonemes"
)
args = parser.parse_args()

if args.single_speaker and (args.speaker_id is not None):
Expand Down Expand Up @@ -299,7 +302,10 @@ def phonemize_batch_espeak(
utt.text = tashkeel_run(utt.text)

_LOGGER.debug(utt)
all_phonemes = phonemize_espeak(casing(utt.text), args.language)
if args.raw_phonemes:
all_phonemes = [utt.text.split()]
else:
all_phonemes = phonemize_espeak(casing(utt.text), args.language)

# Flatten
utt.phonemes = [
Expand Down