### Install espeak-ng on macOS Source: https://context7.com/hexgrad/misaki/llms.txt Use Homebrew to install the espeak-ng library on macOS systems. ```bash brew install espeak-ng ``` -------------------------------- ### Install Misaki with English Support Source: https://context7.com/hexgrad/misaki/llms.txt Installs Misaki with English language support, including dependencies like spaCy, num2words, and transformers. ```bash # English support (spaCy, num2words, transformers) pip install "misaki[en]" ``` -------------------------------- ### Install Misaki with Japanese Support Source: https://context7.com/hexgrad/misaki/llms.txt Installs Misaki with Japanese language support, including dependencies like pyopenjtalk, fugashi, and unidic. ```bash # Japanese support (pyopenjtalk, fugashi, unidic) pip install "misaki[ja]" ``` -------------------------------- ### Install Misaki with Vietnamese Support Source: https://context7.com/hexgrad/misaki/llms.txt Installs Misaki with Vietnamese language support, including dependencies like underthesea and spaCy. ```bash # Vietnamese support (underthesea, spaCy) pip install "misaki[vi]" ``` -------------------------------- ### Install Misaki with Hebrew Support Source: https://context7.com/hexgrad/misaki/llms.txt Installs Misaki with Hebrew language support, including the mishkal-hebrew package. ```bash # Hebrew support (mishkal-hebrew) pip install "misaki[he]" ``` -------------------------------- ### Install Misaki with Korean Support Source: https://context7.com/hexgrad/misaki/llms.txt Installs Misaki with Korean language support, including dependencies like jamo and nltk. ```bash # Korean support (jamo, nltk) pip install "misaki[ko]" ``` -------------------------------- ### Install and Use Misaki English G2P with Espeak Fallback Source: https://github.com/hexgrad/misaki/blob/main/README.md Install Misaki with English support and phonemizer-fork, then configure espeak-ng as a fallback for out-of-dictionary words. This enhances robustness for handling unknown words. ```python # Installing espeak varies across platforms, this silent install works on Colab: !apt-get -qq -y install espeak-ng > /dev/null 2>&1 !pip install -q "misaki[en]" phonemizer-fork from misaki import en, espeak fallback = espeak.EspeakFallback(british=False) # en-us g2p = en.G2P(trf=False, british=False, fallback=fallback) # no transformer, American English text = 'Now outofdictionary words are handled by espeak.' phonemes, tokens = g2p(text) print(phonemes) # nˈW Wɾɑfdˈɪkʃənˌɛɹi wˈɜɹdz ɑɹ hˈændəld bI ˈispik. ``` -------------------------------- ### Install Misaki Base Source: https://context7.com/hexgrad/misaki/llms.txt Installs the base Misaki package without any language-specific dependencies. ```bash # Base installation pip install misaki ``` -------------------------------- ### Install Espeak Fallback Dependencies Source: https://context7.com/hexgrad/misaki/llms.txt Installs the necessary Python packages for the espeak fallback G2P functionality. ```bash # For espeak fallback (requires espeak-ng system package) pip install phonemizer-fork espeakng-loader ``` -------------------------------- ### Install and Use Misaki English G2P Source: https://github.com/hexgrad/misaki/blob/main/README.md Install the Misaki library with English support and use the G2P engine for American English without a transformer. This is useful for basic text-to-phoneme conversion. ```python !pip install -q "misaki[en]" from misaki import en g2p = en.G2P(trf=False, british=False, fallback=None) # no transformer, American English text = '[Misaki](/misˈɑki/) is a G2P engine designed for [Kokoro](/kˈOkəɹO/) models.' phonemes, tokens = g2p(text) print(phonemes) # misˈɑki ɪz ə ʤˈitəpˈi ˈɛnʤən dəzˈInd fɔɹ kˈOkəɹO mˈɑdᵊlz. ``` -------------------------------- ### Install Misaki with Chinese Support Source: https://context7.com/hexgrad/misaki/llms.txt Installs Misaki with Chinese language support, including dependencies like jieba, pypinyin, and cn2an. ```bash # Chinese support (jieba, pypinyin, cn2an) pip install "misaki[zh]" ``` -------------------------------- ### Get Available Hebrew Phoneme Set Source: https://context7.com/hexgrad/misaki/llms.txt Retrieves the set of available phonemes supported by the Hebrew G2P module. Requires the 'he' extra for installation. ```python # Get available phoneme set phoneme_set = g2p.get_phonene_set() print(f"Available phonemes: {phoneme_set}") ``` -------------------------------- ### Install espeak-ng on Ubuntu/Debian Source: https://context7.com/hexgrad/misaki/llms.txt Installs the espeak-ng system package on Ubuntu or Debian-based Linux distributions, required for the espeak fallback G2P module. ```bash # Install espeak-ng on Ubuntu/Debian apt-get install espeak-ng ``` -------------------------------- ### MToken Data Structure Example Source: https://context7.com/hexgrad/misaki/llms.txt Demonstrates accessing token data, including text, POS tag, phonemes, whitespace, and language-specific metadata via the underscore object, from an English G2P conversion. ```python from misaki.token import MToken # MToken structure # - text: Original text # - tag: Part-of-speech tag # - whitespace: Trailing whitespace # - phonemes: Converted phonemes (None if conversion failed) # - start_ts: Optional start timestamp # - end_ts: Optional end timestamp # - _: Underscore object with language-specific metadata # Example: Accessing token data from English G2P from misaki import en g2p = en.G2P(trf=False, british=False, fallback=None) _, tokens = g2p("Hello world") for token in tokens: print(f"Text: '{token.text}'") print(f"POS Tag: {token.tag}") print(f"Phonemes: {token.phonemes}") print(f"Whitespace: '{token.whitespace}'") # Language-specific metadata via underscore if token._: print(f"Is head token: {token._.is_head}") print(f"Stress: {token._.stress}") print(f"Rating: {token._.rating}") # Quality rating 1-5 print("---") ``` -------------------------------- ### Initialize Hebrew G2P Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Hebrew G2P module for converting Hebrew text with diacritics (niqqud) to IPA phonemes. Requires the 'he' extra for installation. ```python from misaki import he g2p = he.HEG2P() # Convert Hebrew text (with niqqud) to phonemes # Note: Input text should have diacritics for accurate conversion text = "שָׁלוֹם עוֹלָם" phonemes = g2p(text, preserve_punctuation=True, preserve_stress=True) print(phonemes) ``` -------------------------------- ### Chinese G2P with English Callback Source: https://context7.com/hexgrad/misaki/llms.txt Initializes a Chinese G2P model with an English callable for handling mixed-language text. Requires the 'zh' extra for installation. ```python from misaki import en en_g2p = en.G2P(trf=False, british=False, fallback=None) g2p_mixed = zh.ZHG2P(version='1.1', en_callable=lambda x: en_g2p(x)[0]) text = "我喜欢Python编程" phonemes, _ = g2p_mixed(text) print(phonemes) ``` -------------------------------- ### Initialize Vietnamese G2P (Northern Dialect) Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Vietnamese G2P module for the Northern dialect. Supports tone types, English fallback, and text cleaning for abbreviations and acronyms. Requires the 'vi' extra for installation. ```python from misaki import vi g2p = vi.VIG2P( dialect="north", # "north", "central", or "south" tone_type=0, # 0 for Pham tones, 1 for Cao tones enable_en_g2p=True, # Enable English fallback for loan words clean_abbr=True, # Expand abbreviations clean_acronym=True # Handle acronyms ) # Basic Vietnamese text to phonemes text = "Xin chào thế giới" phonemes, tokens = g2p(text) print(phonemes) ``` -------------------------------- ### Vietnamese G2P Southern Dialect Source: https://context7.com/hexgrad/misaki/llms.txt Initializes and uses the Vietnamese G2P module for the Southern dialect. Requires the 'vi' extra for installation. ```python # Southern dialect g2p_south = vi.VIG2P(dialect="south") phonemes_south, _ = g2p_south("Sài Gòn đẹp lắm") print(phonemes_south) ``` -------------------------------- ### Chinese G2P Legacy Mode Source: https://context7.com/hexgrad/misaki/llms.txt Uses the legacy mode for Chinese G2P, which employs a simpler pinyin-to-IPA conversion. Requires the 'zh' extra for installation. ```python g2p_legacy = zh.ZHG2P() phonemes_legacy, _ = g2p_legacy("中文测试") print(phonemes_legacy) ``` -------------------------------- ### Hebrew G2P Without Stress Markers Source: https://context7.com/hexgrad/misaki/llms.txt Converts Hebrew text to phonemes without preserving stress markers. Requires the 'he' extra for installation. ```python # Without stress markers phonemes_no_stress = g2p(text, preserve_stress=False) print(phonemes_no_stress) ``` -------------------------------- ### Vietnamese G2P Custom Pronunciation Source: https://context7.com/hexgrad/misaki/llms.txt Converts Vietnamese text with custom pronunciation using markdown-style syntax for specific words or phrases. Requires the 'vi' extra for installation. ```python text = "[Việt Nam](/viət nam/) là quê hương tôi" phonemes, _ = g2p(text) print(phonemes) ``` -------------------------------- ### Convert espeak phonemes to Misaki format Source: https://github.com/hexgrad/misaki/blob/main/EN_PHONES.md This Python function converts phonemes generated by the espeak library to the Misaki phoneme set. It handles specific transformations for British English and removes extraneous characters. Ensure the 'phonemizer' and 're' libraries are installed. ```python import re FROM_ESPEAKS = sorted({'̃':'','a^ɪ':'I','a^ʊ':'W','d^ʒ':'ʤ','e':'A','e^ɪ':'A','r':'ɹ','t^ʃ':'ʧ','x':'k','ç':'k','ɐ':'ə','ɔ^ɪ':'Y','ə^l':'ᵊl','ɚ':'əɹ','ɬ':'l','ʔ':'t','ʔn':'tᵊn','ʔˌnˉ':'tᵊn','ʲ':'','ʲO':'jO','ʲQ':'jQ'}.items(), key=lambda kv: -len(kv[0])) def from_espeak(ps, british): for old, new in FROM_ESPEAKS: ps = ps.replace(old, new) ps = re.sub(r'(\S)\ˉ', r'ᵊ\\1', ps).replace(chr(809), '') if british: ps = ps.replace('e^ə', 'ɛː') ps = ps.replace('iə', 'ɪə') ps = ps.replace('ə^ʊ', 'Q') else: ps = ps.replace('o^ʊ', 'O') ps = ps.replace('ɜːɹ', 'ɜɹ') ps = ps.replace('ɜː', 'ɜɹ') ps = ps.replace('ɪə', 'iə') ps = ps.replace('ː', '') return ps.replace('^', '') ``` ```python import phonemizer british = False espeak = phonemizer.backend.EspeakBackend( language=f"en-{'gb' if british else 'us'}", preserve_punctuation=True, with_stress=True, tie='^' ) text = 'merchantship' espeak_ps = espeak.phonemize([text]) espeak_ps = espeak_ps[0].strip() if espeak_ps else '' assert espeak_ps == 'mˈɜːt^ʃəntʃˌɪp', espeak_ps ps = from_espeak(espeak_ps, british) assert ps == ('mˈɜːʧəntʃˌɪp' if british else 'mˈɜɹʧəntʃˌɪp'), ps VOCAB = frozenset('AIWYbdfhijklmnpstuvwzðŋɑɔəɛɜɡɪɹʃʊʌʒʤʧˈˌθᵊ' + ('Qaɒː' if british else 'Oæɾᵻ')) assert len(VOCAB) == 45, len(VOCAB) assert all(p in VOCAB for p in ps), ps ``` -------------------------------- ### Initialize and Use Chinese G2P Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Chinese G2P engine using `jieba` for segmentation and `pypinyin` for conversion. `version='1.1'` uses an improved frontend from PaddleSpeech. ```python from misaki import zh # Initialize Chinese G2P # version='1.1' uses improved frontend from PaddleSpeech g2p = zh.ZHG2P(version='1.1') # Basic Chinese text to phonemes text = "你好世界" phonemes, _ = g2p(text) print(phonemes) ``` -------------------------------- ### Initialize and Use Korean G2P Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Korean G2P engine using the `g2pkc` library. This handles Korean phonological rules including consonant assimilation and liaison. ```python from misaki import ko # Initialize Korean G2P g2p = ko.KOG2P() # Convert Korean text to phonemes text = "안녕하세요" phonemes, _ = g2p(text) print(phonemes) # Output: Korean phonemes following g2pK conventions ``` ```python # Handle mixed Korean text text = "오늘 날씨가 좋습니다" phonemes, _ = g2p(text) print(phonemes) ``` ```python # Korean text with numbers and punctuation text = "2024년 1월 1일입니다." phonemes, _ = g2p(text) print(phonemes) ``` -------------------------------- ### Initialize Espeak G2P for Spanish Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Espeak G2P module for Spanish language conversion. Requires 'phonemizer-fork' and 'espeakng-loader' extras, and the espeak-ng system package. ```python # Initialize for Spanish g2p_es = espeak.EspeakG2P(language='es') phonemes, _ = g2p_es("Hola mundo") print(phonemes) ``` -------------------------------- ### Initialize and Use Japanese G2P Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Japanese G2P engine using either `pyopenjtalk` or `cutlet` backend. The `pyopenjtalk` version provides phonemes with pitch information. ```python from misaki import ja # Initialize Japanese G2P with pyopenjtalk backend g2p = ja.JAG2P(version='pyopenjtalk') # Convert Japanese text to phonemes with pitch information text = "こんにちは世界" result, tokens = g2p(text) # Result includes phonemes + pitch pattern # Phonemes followed by pitch markers: _ (low), - (mid), ^ (falling) print(result) # Output format: phonemes + pitch pattern string ``` ```python # Access detailed token information including pitch accent for token in tokens: if token.phonemes: print(f"Text: {token.text}") print(f"Phonemes: {token.phonemes}") print(f"Pitch: {token._.pitch}") print(f"Mora count: {token._.mora_size}") print(f"Accent position: {token._.acc}") ``` ```python # Alternative: Use cutlet backend (first-gen tokenizer) g2p_cutlet = ja.JAG2P(version='cutlet') result_cutlet, _ = g2p_cutlet("日本語のテスト") print(result_cutlet) ``` -------------------------------- ### Initialize Espeak G2P for French (Version 2.0) Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Espeak G2P module for French with version 2.0, which includes additional nasal vowel mappings. Requires 'phonemizer-fork' and 'espeakng-loader' extras, and the espeak-ng system package. ```python # Version 2.0 includes additional nasal vowel mappings g2p_fr_v2 = espeak.EspeakG2P(language='fr', version='2.0') phonemes_v2, _ = g2p_fr_v2("Un bon vin blanc") print(phonemes_v2) ``` -------------------------------- ### Initialize Espeak G2P for German Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Espeak G2P module for German language conversion. Requires 'phonemizer-fork' and 'espeakng-loader' extras, and the espeak-ng system package. ```python # Initialize for German g2p_de = espeak.EspeakG2P(language='de') phonemes, _ = g2p_de("Guten Tag") print(phonemes) ``` -------------------------------- ### Initialize Espeak G2P for French Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the Espeak G2P module for French language conversion. Requires 'phonemizer-fork' and 'espeakng-loader' extras, and the espeak-ng system package. ```python from misaki import espeak # Initialize for French g2p_fr = espeak.EspeakG2P(language='fr') phonemes, _ = g2p_fr("Bonjour le monde") print(phonemes) ``` -------------------------------- ### Initialize and Use English G2P Source: https://context7.com/hexgrad/misaki/llms.txt Initializes the English G2P engine and performs basic text-to-phoneme conversion. Use `trf=True` for transformer-based accuracy (slower) and `british=True` for British English. `fallback=None` disables espeak fallback. ```python from misaki import en # Initialize English G2P # trf=True uses transformer model for better accuracy (slower) # british=True for British English pronunciation # fallback=None disables espeak fallback g2p = en.G2P(trf=False, british=False, fallback=None) # Basic text to phoneme conversion text = "Hello world! This is a test." phonemes, tokens = g2p(text) print(phonemes) # Output: həlˈO wˈɜɹld! ðˈɪs ɪz ə tˈɛst. ``` ```python # Using inline pronunciation overrides with markdown-style syntax # [word](/phonemes/) - specify exact phonemes # [word](stress) - adjust stress level (-2 to 2) text = '[Misaki](/misˈɑki/) is a G2P engine designed for [Kokoro](/kˈOkəɹO/) models.' phonemes, tokens = g2p(text) print(phonemes) # Output: misˈɑki ɪz ə ʤˈitəpˈi ˈɛnʤən dəzˈInd fɔɹ kˈOkəɹO mˈɑdᵊlz. ``` ```python # Access individual token information for token in tokens: print(f"Text: {token.text}, Tag: {token.tag}, Phonemes: {token.phonemes}") ``` -------------------------------- ### Vietnamese G2P Token Information Source: https://context7.com/hexgrad/misaki/llms.txt Demonstrates accessing detailed token information, including text, phonemes, and tone, from the Vietnamese G2P module. ```python # Access detailed token information for token in tokens: print(f"Text: {token.text}") print(f"Phonemes: {token.phonemes}") if token._.tone: print(f"Tone: {token._.tone}") ``` -------------------------------- ### English G2P with Espeak Fallback Source: https://context7.com/hexgrad/misaki/llms.txt Configures the English G2P engine to use `espeak.EspeakFallback` for handling out-of-vocabulary words. Specify `british=False` for American English or `british=True` for British English. ```python from misaki import en, espeak # Create espeak fallback for American English fallback = espeak.EspeakFallback(british=False) # Initialize G2P with fallback enabled g2p = en.G2P(trf=False, british=False, fallback=fallback) # Now out-of-dictionary words are handled by espeak text = 'The outofdictionary words are handled gracefully.' phonemes, tokens = g2p(text) print(phonemes) # Output: ðə Wɾɑfdˈɪkʃənˌɛɹi wˈɜɹdz ɑɹ hˈændəld ɡɹˈAsəfᵊli. ``` ```python # British English with fallback gb_fallback = espeak.EspeakFallback(british=True) gb_g2p = en.G2P(trf=False, british=True, fallback=gb_fallback) phonemes_gb, _ = gb_g2p("The colour of the centre is grey.") print(phonemes_gb) # British phonemes with different vowel representations ``` -------------------------------- ### Convert Phonetic Characters to Espeak Format Source: https://github.com/hexgrad/misaki/blob/main/EN_PHONES.md Use this function to replace specific phonetic characters with their espeak representations. It handles diphthongs and affricates. ```python def to_espeak(ps): # Optionally, you can add a tie character in between the 2 replacement characters. ps = ps.replace('ʤ', 'dʒ').replace('ʧ', 'tʃ') ps = ps.replace('A', 'eɪ').replace('I', 'aɪ').replace('Y', 'ɔɪ') ps = ps.replace('O', 'oʊ').replace('Q', 'əʊ').replace('W', 'aʊ') return ps.replace('ᵊ', 'ə') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.