### Text-to-Speech Inference with TurkicTTS Source: https://github.com/is2ai/turkictts/blob/master/README.md This Python script demonstrates how to perform text-to-speech inference using a pretrained vocoder and acoustic model. Ensure the vocoder and acoustic model checkpoints are unzipped in the same directory. Specify the correct paths for the vocoder checkpoint, config file, and model path. The script supports multiple Turkic languages for synthesis. ```python from parallel_wavegan.utils import load_model from espnet2.bin.tts_inference import Text2Speech from scipy.io.wavfile import write from utils import normalization import torch fs = 22050 vocoder_checkpoint="parallelwavegan_male2_checkpoint/checkpoint-400000steps.pkl" ### specify vocoder path vocoder = load_model(vocoder_checkpoint).to("cuda").eval() vocoder.remove_weight_norm() ### specify path to the main model(transformer/tacotron2/fastspeech) and its config file config_file = "exp/tts_train_raw_char/config.yaml" model_path = "exp/tts_train_raw_char/train.loss.ave_5best.pth" text2speech = Text2Speech( config_file, model_path, device="cuda", ## if cuda not available use cpu ### only for Tacotron 2 threshold=0.5, minlenratio=0.0, maxlenratio=10.0, use_att_constraint=True, backward_window=1, forward_window=3, ### only for FastSpeech & FastSpeech2 speed_control_alpha=1.0, ) text2speech.spc2wav = None ### disable griffin-lim text = "merhaba" ### available options are azerbaijani, bashkir, kazakh, kyrgyz, sakha, tatar, turkish, turkmen, uyghur, uzbek lang = "turkish" text = normalization(text, lang) with torch.no_grad(): c_mel = text2speech(text)['feat_gen'] wav = vocoder.inference(c_mel) write("result.wav", fs, wav.view(-1).cpu().numpy()) ``` -------------------------------- ### normalization(x, lang="kazakh") Source: https://context7.com/is2ai/turkictts/llms.txt Converts text in any of the ten supported Turkic languages into the Kazakh Cyrillic alphabet via an IPA intermediate representation. This is the primary entry point used before feeding text into the acoustic model. The `lang` parameter selects the source language; the default is "kazakh". ```APIDOC ## `normalization(x, lang="kazakh")` — Transliterate source-language text to Kazakh script for TTS ### Description Converts text in any of the ten supported Turkic languages into the Kazakh Cyrillic alphabet via an IPA intermediate representation. This is the primary entry point used before feeding text into the acoustic model. The `lang` parameter selects the source language; the default is `"kazakh"`. Supported values: `"kazakh"`, `"turkish"`, `"azerbaijani"`, `"kyrgyz"`, `"uzbek"`, `"turkmen"`, `"tatar"`, `"bashkir"`, `"sakha"`, `"uyghur"`. ### Method ```python from utils import normalization # Turkish → IPA → Kazakh Cyrillic text_tr = "merhaba" kz_text = normalization(text_tr, lang="turkish") print(kz_text) # Output: Kazakh Cyrillic transcription ready for TTS model input # Uzbek (Latin script) text_uz = "salom dunyo" kz_text_uz = normalization(text_uz, lang="uzbek") print(kz_text_uz) # Azerbaijani text_az = "salam" kz_text_az = normalization(text_az, lang="azerbaijani") print(kz_text_az) # Default: Kazakh — text passes through unchanged in script, rules applied text_kz = "Қазақстан" kz_text_kz = normalization(text_kz, lang="kazakh") print(kz_text_kz) ``` ``` -------------------------------- ### kazakh_to_ipa(text) / ipa_to_kazakh(text) Source: https://context7.com/is2ai/turkictts/llms.txt Bidirectional conversion between Kazakh Cyrillic and IPA. `kazakh_to_ipa` maps every Kazakh letter to an IPA symbol and applies four phonological rules. `ipa_to_kazakh` reverses the mapping with corresponding anti-rules. These functions also serve as the final stage for all other language pipelines. ```APIDOC ## `kazakh_to_ipa(text)` / `ipa_to_kazakh(text)` — Kazakh Cyrillic ↔ IPA conversion ### Description Bidirectional conversion between Kazakh Cyrillic and IPA. `kazakh_to_ipa` maps every Kazakh letter to an IPA symbol and applies four phonological rules: soft-[l] palatalization ([ł] rule), word-initial [w] insertion before [o]/[ö], [u]→[w] before consonants, and [ǐ]→[i] before consonants. `ipa_to_kazakh` reverses the mapping with corresponding anti-rules. These functions also serve as the final stage for all other language pipelines (via `ipa_to_kazakh`), since Kazakh is the TTS model's input script. ### Method ```python import ipa_convert # Forward: Kazakh → IPA ipa = ipa_convert.kazakh_to_ipa("Қазақстан") print(ipa) # e.g., "qɑzɑqstɑn" (IPA symbols) # Backward: IPA → Kazakh kz = ipa_convert.ipa_to_kazakh(ipa) print(kz) # "қазақстан" # Round-trip test (should print "input text and output text -- identical") ipa_convert.test_kazakh("Қазақ тілі әдемі") ``` ``` -------------------------------- ### Convert Uyghur Latin to IPA and back Source: https://context7.com/is2ai/turkictts/llms.txt Use `uyghur_to_ipa` to convert Uyghur Latin script to IPA and `ipa_to_uyghur` to convert IPA back to Uyghur Latin. Handles digraphs and special characters like apostrophes for glottal stops. ```python import ipa_convert # Latin ULY input ipa = ipa_convert.uyghur_to_ipa("Uyghur xelqi") print(ipa) back = ipa_convert.ipa_to_uyghur(ipa) print(back) # "uyghur xelqi" # Digraph and glottal stop ipa2 = ipa_convert.uyghur_to_ipa("qoshni") print(ipa2) ipa_convert.test_uyghur("Uyghur tili ghayiti bay til") ``` -------------------------------- ### Azerbaijani Latin to IPA and back Source: https://context7.com/is2ai/turkictts/llms.txt Converts Azerbaijani Latin-script text to IPA and back. Maps specific characters like [Cc]→[Ǯ], [Çç]→[ʆ], [Gg]→[ḡ], and [Əə]→[æ]. ```python import ipa_convert ipa = ipa_convert.azerbaijani_to_ipa("Azərbaycan") print(ipa) # IPA with æ for ə back = ipa_convert.ipa_to_azerbaijani(ipa) print(back) # "azərbaycan" # Round-trip ipa_convert.test_azerbaijani("Bakı gözəl şəhərdir") ``` -------------------------------- ### Turkmen Latin to IPA and back Source: https://context7.com/is2ai/turkictts/llms.txt Converts Turkmen Latin-script text to IPA and back. Handles specific graphemes like [Çç]→[ʆ], [Jj]→[Ǯ], [Žž]→[ʒ], [Ňň]→[ŋ], [Şş]→[ʃ], [Ww]→[v], and [Ýý]→[j]. ```python import ipa_convert ipa = ipa_convert.turkmen_to_ipa("Türkmenistan") print(ipa) back = ipa_convert.ipa_to_turkmen(ipa) print(back) # "türkmenistan" # Test with Ý and Ň ipa2 = ipa_convert.turkmen_to_ipa("ýurt") print(ipa2) ipa_convert.test_turkmen("Aşgabat gözel şäher") ``` -------------------------------- ### Uzbek Latin to IPA and back Source: https://context7.com/is2ai/turkictts/llms.txt Converts Uzbek Latin-script text to IPA and vice-versa. Handles specific graphemes like 'ch', 'sh', 'ng', 'g'', and 'oʻ'. ```python import ipa_convert ipa = ipa_convert.uzbek_to_ipa("salom dunyo") print(ipa) # IPA output back = ipa_convert.ipa_to_uzbek(ipa) print(back) # "salom dunyo" # Grapheme cluster handling ipa2 = ipa_convert.uzbek_to_ipa("o'zbek tili") print(ipa2) # Round-trip ipa_convert.test_uzbek("O'zbekiston go'zal") ``` -------------------------------- ### kyrgyz_to_ipa(text) / ipa_to_kyrgyz(text) Source: https://context7.com/is2ai/turkictts/llms.txt Handles the Kyrgyz Cyrillic alphabet, including the [Жж]→[Ǯ] digraph mapping. Applies the same four base rules as Kazakh plus two Kyrgyz-specific rules for velar/uvular alternation driven by vowel harmony. ```APIDOC ## `kyrgyz_to_ipa(text)` / `ipa_to_kyrgyz(text)` — Kyrgyz Cyrillic ↔ IPA conversion ### Description Handles the Kyrgyz Cyrillic alphabet, including the [Жж]→[Ǯ] digraph mapping. Applies the same four base rules as Kazakh plus two Kyrgyz-specific rules: back-vowel context triggers k→q and g→ɣ substitutions (velar/uvular alternation driven by vowel harmony). This correctly models the phonological distinction between front-vowel /k,g/ and back-vowel /q,ɣ/ environments. ### Method ```python import ipa_convert ipa = ipa_convert.kyrgyz_to_ipa("Кыргызстан") print(ipa) # IPA with uvular stops in back-vowel contexts back = ipa_convert.ipa_to_kyrgyz(ipa) print(back) # "кыргызстан" ``` ``` -------------------------------- ### turkish_to_ipa(text) / ipa_to_turkish(text) Source: https://context7.com/is2ai/turkictts/llms.txt Converts Turkish Latin-script text to IPA and back. Handles Turkish-specific characters and applies rules for soft-[l] (ł), [u]→[w] before consonants, and [i]→[i] disambiguation. ```APIDOC ## `turkish_to_ipa(text)` / `ipa_to_turkish(text)` — Turkish ↔ IPA conversion ### Description Converts Turkish Latin-script text to IPA and back. Handles Turkish-specific characters (Ç/ç, Ş/ş, Ğ/ğ, İ/i, Ö/ö, Ü/ü) and applies rules for soft-[l] (ł), [u]→[w] before consonants, and [i]→[i] disambiguation. The [Cc] digraph is mapped to the affricate [Ǯ] (representing /dʒ/), and [Ğğ] to the fricative [ɣ]. Also experimentally supports circumflex vowels î and â. ### Method ```python import ipa_convert ipa = ipa_convert.turkish_to_ipa("merhaba") print(ipa) # "merhɑbɑ" ipa2 = ipa_convert.turkish_to_ipa("Türk dünyası") print(ipa2) back = ipa_convert.ipa_to_turkish(ipa2) print(back) # "türk dünyası" # Test round-trip ipa_convert.test_turkish("Türkiye güzel bir ülkedir") # Expected: "input text and output text -- identical" ``` ``` -------------------------------- ### Full TTS Inference Pipeline for Turkic Languages Source: https://context7.com/is2ai/turkictts/llms.txt Synthesize speech for any supported Turkic language using a pipeline that combines text normalization, an acoustic model (Tacotron2), and a neural vocoder (ParallelWaveGAN). Ensure vocoder and acoustic model checkpoints are downloaded and unzipped. ```python from parallel_wavegan.utils import load_model from espnet2.bin.tts_inference import Text2Speech from scipy.io.wavfile import write from utils import normalization import torch fs = 22050 # Load vocoder vocoder_checkpoint = "parallelwavegan_male2_checkpoint/checkpoint-400000steps.pkl" vocoder = load_model(vocoder_checkpoint).to("cuda").eval() vocoder.remove_weight_norm() # Load acoustic model (Tacotron2) config_file = "exp/tts_train_raw_char/config.yaml" model_path = "exp/tts_train_raw_char/train.loss.ave_5best.pth" text2speech = Text2Speech( config_file, model_path, device="cuda", # use "cpu" if CUDA unavailable threshold=0.5, # Tacotron2 stop threshold minlenratio=0.0, maxlenratio=10.0, use_att_constraint=True, backward_window=1, forward_window=3, speed_control_alpha=1.0, # FastSpeech speed factor (ignored for Tacotron2) ) text2speech.spc2wav = None # disable Griffin-Lim; use neural vocoder instead # --- Synthesize speech for each supported language --- examples = [ ("merhaba", "turkish"), ("salom", "uzbek"), ("Azərbaycan", "azerbaijani"), ("Кыргызстан", "kyrgyz"), ("Башҡортостан", "bashkir"), ("Татарстан", "tatar"), ("Türkmenistan", "turkmen"), ("Саха", "sakha"), ("Uyghur xelqi", "uyghur"), ("Қазақстан", "kazakh"), ] for text, lang in examples: normalized = normalization(text, lang) # transliterate to Kazakh script with torch.no_grad(): c_mel = text2speech(normalized)("feat_gen") # mel spectrogram wav = vocoder.inference(c_mel) # waveform out_path = f"result_{lang}.wav" write(out_path, fs, wav.view(-1).cpu().numpy()) print(f"[{lang}] '{text}' → saved to {out_path}") ``` -------------------------------- ### Bashkir Cyrillic to IPA and back Source: https://context7.com/is2ai/turkictts/llms.txt Converts Bashkir Cyrillic text to IPA and back. Handles Bashkir-specific letters like [Ғғ]→[ɣ], [Ҡҡ]→[q], [Ҙҙ]→[z], and [Ҫҫ]→[s]. ```python import ipa_convert ipa = ipa_convert.bashkir_to_ipa("Башҡортостан") print(ipa) # Note: Ҡ → q back = ipa_convert.ipa_to_bashkir(ipa) print(back) # "башҡортостан" # Ғ and Ҙ handling ipa2 = ipa_convert.bashkir_to_ipa("Ғәжәп") print(ipa2) ipa_convert.test_bashkir("Башҡорт теле матур тел") ``` -------------------------------- ### Tatar Cyrillic to IPA and back Source: https://context7.com/is2ai/turkictts/llms.txt Converts Tatar Cyrillic text to IPA and back. Includes Tatar-specific letters like [Җҗ]→[Ǯ] and handles vowels [Әә]→[æ], [Өө]→[ɵ], [Үү]→[ʏ]. ```python import ipa_convert ipa = ipa_convert.tatar_to_ipa("Татарстан") print(ipa) back = ipa_convert.ipa_to_tatar(ipa) print(back) # "татарстан" # Tatar-specific Җ ipa2 = ipa_convert.tatar_to_ipa("Җир") print(ipa2) # Contains Ǯ ipa_convert.test_tatar("Татар теле матур тел") ``` -------------------------------- ### Full TTS Inference Pipeline Source: https://context7.com/is2ai/turkictts/llms.txt End-to-end speech synthesis for any Turkic language using a pipeline that combines text normalization, an acoustic model (ESPnet2 Tacotron2), and a vocoder (ParallelWaveGAN). ```APIDOC ## Full TTS Inference Pipeline ### Description Combines `normalization()` from `utils.py` with ESPnet2 Tacotron2 and ParallelWaveGAN to synthesize speech. Download the pretrained vocoder (`parallelwavegan_male2_checkpoint`) and acoustic model (`kaztts_male2_tacotron2_train.loss.ave`) from the ISSAI website, unzip both into the same directory, then run the following. ### Usage ```python from parallel_wavegan.utils import load_model from espnet2.bin.tts_inference import Text2Speech from scipy.io.wavfile import write from utils import normalization import torch fs = 22050 # Load vocoder vocoder_checkpoint = "parallelwavegan_male2_checkpoint/checkpoint-400000steps.pkl" vocoder = load_model(vocoder_checkpoint).to("cuda").eval() vocoder.remove_weight_norm() # Load acoustic model (Tacotron2) config_file = "exp/tts_train_raw_char/config.yaml" model_path = "exp/tts_train_raw_char/train.loss.ave_5best.pth" text2speech = Text2Speech( config_file, model_path, device="cuda", # use "cpu" if CUDA unavailable threshold=0.5, # Tacotron2 stop threshold minlenratio=0.0, maxlenratio=10.0, use_att_constraint=True, backward_window=1, forward_window=3, speed_control_alpha=1.0, # FastSpeech speed factor (ignored for Tacotron2) ) text2speech.spc2wav = None # disable Griffin-Lim; use neural vocoder instead # --- Synthesize speech for each supported language --- examples = [ ("merhaba", "turkish"), ("salom", "uzbek"), ("Azərbaycan", "azerbaijani"), ("Кыргызстан", "kyrgyz"), ("Башҡортостан", "bashkir"), ("Татарстан", "tatar"), ("Türkmenistan", "turkmen"), ("Саха", "sakha"), ("Uyghur xelqi", "uyghur"), ("Қазақстан", "kazakh"), ] for text, lang in examples: normalized = normalization(text, lang) # transliterate to Kazakh script with torch.no_grad(): c_mel = text2speech(normalized)("feat_gen") # mel spectrogram wav = vocoder.inference(c_mel) # waveform out_path = f"result_{lang}.wav" write(out_path, fs, wav.view(-1).cpu().numpy()) print(f"[{lang}] '{text}' → saved to {out_path}") ``` ``` -------------------------------- ### Kazakh Cyrillic ↔ IPA Conversion Source: https://context7.com/is2ai/turkictts/llms.txt Bidirectional conversion between Kazakh Cyrillic and IPA, including phonological rules for palatalization and vowel/consonant alternations. Serves as the final stage for other language pipelines. ```python import ipa_convert # Forward: Kazakh → IPA ipa = ipa_convert.kazakh_to_ipa("Қазақстан") print(ipa) # e.g., "qɑzɑqstɑn" (IPA symbols) # Backward: IPA → Kazakh kz = ipa_convert.ipa_to_kazakh(ipa) print(kz) # "қазақстан" # Round-trip test (should print "input text and output text -- identical") ipa_convert.test_kazakh("Қазақ тілі әдемі") ``` -------------------------------- ### Kyrgyz Cyrillic ↔ IPA Conversion Source: https://context7.com/is2ai/turkictts/llms.txt Handles Kyrgyz Cyrillic, including the [Жж]→[Ǯ] mapping. Applies base rules plus Kyrgyz-specific rules for velar/uvular alternations driven by vowel harmony. ```python import ipa_convert ipa = ipa_convert.kyrgyz_to_ipa("Кыргызстан") print(ipa) # IPA with uvular stops in back-vowel contexts back = ipa_convert.ipa_to_kyrgyz(ipa) print(back) # "кыргызстан" ``` -------------------------------- ### Sakha (Yakut) Cyrillic to IPA and back Source: https://context7.com/is2ai/turkictts/llms.txt Converts Sakha Cyrillic text to IPA and back. Handles Sakha-specific features like [Ҕҕ]→[ɣ], [Ҥҥ]→[ŋ], and digraphs `дь`/`ДЬ`→[Ǯ], `нь`/`НЬ`→[ɲ]. ```python import ipa_convert ipa = ipa_convert.sakha_to_ipa("Саха Өрөспүүбүлүкэтэ") print(ipa) back = ipa_convert.ipa_to_sakha(ipa) print(back) # "саха өрөспүүбүлүкэтэ" # дь → Ǯ and нь → ɲ ipa2 = ipa_convert.sakha_to_ipa("дьиэ") # house print(ipa2) # Ǯɪě ipa_convert.test_sakha("Саха тыла дэгэтэ") ``` -------------------------------- ### Transliterate Turkic Text to Kazakh Script for TTS Source: https://context7.com/is2ai/turkictts/llms.txt Converts text in supported Turkic languages to Kazakh Cyrillic via IPA. This is the primary entry point for TTS inference. The `lang` parameter specifies the source language. ```python from utils import normalization # Turkish → IPA → Kazakh Cyrillic text_tr = "merhaba" kz_text = normalization(text_tr, lang="turkish") print(kz_text) # Output: Kazakh Cyrillic transcription ready for TTS model input # Uzbek (Latin script) text_uz = "salom dunyo" kz_text_uz = normalization(text_uz, lang="uzbek") print(kz_text_uz) # Azerbaijani text_az = "salam" kz_text_az = normalization(text_az, lang="azerbaijani") print(kz_text_az) # Default: Kazakh — text passes through unchanged in script, rules applied text_kz = "Қазақстан" kz_text_kz = normalization(text_kz, lang="kazakh") print(kz_text_kz) ``` -------------------------------- ### Uyghur Latin ↔ IPA Conversion Source: https://context7.com/is2ai/turkictts/llms.txt Converts Uyghur Latin-script text (ULY) to IPA and vice versa. Handles specific two-character graphemes and the apostrophe for glottal stops. The `ipa_to_uyghur` function restores `ë` before `e` to maintain accuracy. ```APIDOC ## `uyghur_to_ipa(text)` / `ipa_to_uyghur(text)` ### Description Converts Uyghur Latin-script text (ULY — Uyghur Latin Yéziqi) to IPA and back. Handles two-character graphemes: `ch`→[ʆ], `sh`→[ʃ], `gh`→[ɣ], `ng`→[ŋ], `zh`→[ʒ], and `j`→[Ǯ]. The e-diaeresis `ë`/`é` maps to [e] (the more front vowel), while plain `e` maps to [æ]. Apostrophe `'` maps to glottal stop [ʔ]. In `ipa_to_uyghur`, [e] is carefully restored to `ë` before [æ]→`e` to handle precedence. ### Usage ```python import ipa_convert # Latin ULY input ipa = ipa_convert.uyghur_to_ipa("Uyghur xelqi") print(ipa) back = ipa_convert.ipa_to_uyghur(ipa) print(back) # "uyghur xelqi" # Digraph and glottal stop ipa2 = ipa_convert.uyghur_to_ipa("qoshni") print(ipa2) ipa_convert.test_uyghur("Uyghur tili ghayiti bay til") ``` ``` -------------------------------- ### Turkish ↔ IPA Conversion Source: https://context7.com/is2ai/turkictts/llms.txt Converts Turkish Latin-script text to IPA and back, handling Turkish-specific characters and phonological rules. Supports digraphs like [Cc] and [Ğğ]. ```python import ipa_convert ipa = ipa_convert.turkish_to_ipa("merhaba") print(ipa) # "merhɑbɑ" ipa2 = ipa_convert.turkish_to_ipa("Türk dünyası") print(ipa2) back = ipa_convert.ipa_to_turkish(ipa2) print(back) # "türk dünyası" # Test round-trip ipa_convert.test_turkish("Türkiye güzel bir ülkedir") # Expected: "input text and output text -- identical" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.