<gh_stars>0
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/text.symbols.ipynb (unless otherwise specified).

__all__ = ['symbols', 'symbols_with_ipa', 'DEFAULT_SYMBOLS', 'IPA_SYMBOLS', 'SYMBOL_SETS', 'symbols_to_sequence',
           'arpabet_to_sequence', 'should_keep_symbol', 'symbol_to_id', 'id_to_symbol', 'curly_re', 'words_re']

# Cell

""" from https://github.com/keithito/tacotron """

"""
Defines the set of symbols used in text input to the model.
The default is a set of ASCII characters that works well for English or text that has been run through Unidecode. For other data, you can modify _characters. See TRAINING_DATA.md for details. """

from . import cmudict

_pad = "_"
_punctuation = "!'\",.:;? "
_math = "#%&*+-/[]()"
_special = "@©°½—₩€$"
_accented = "áçéêëñöøćž"
_numbers = "0123456789"
_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
_letters_ipa = "ɑɐɒæɓʙβɔɕçɗɖðʤəɘɚɛɜɝɞɟʄɡɠɢʛɦɧħɥʜɨɪʝɭɬɫɮʟɱɯɰŋɳɲɴøɵɸθœɶʘɹɺɾɻʀʁɽʂʃʈʧʉʊʋⱱʌɣɤʍχʎʏʑʐʒʔʡʕʢǀǁǂǃˈˌːˑʼʴʰʱʲʷˠˤ˞↓↑→↗↘'̩'ᵻ"

# Prepend "@" to ARPAbet symbols to ensure uniqueness (some are the same as
# uppercase letters):
_arpabet = ["@" + s for s in cmudict.valid_symbols]

# Export all symbols:
symbols = (
    list(_pad + _punctuation + _math + _special + _accented + _numbers + _letters)
    + _arpabet
)

symbols_with_ipa = symbols + list(_letters_ipa)

DEFAULT_SYMBOLS = "default"
IPA_SYMBOLS = "ipa"
SYMBOL_SETS = {
    DEFAULT_SYMBOLS: symbols,
    IPA_SYMBOLS: symbols_with_ipa,
}

# Cell
import re

symbol_to_id = {
    DEFAULT_SYMBOLS: {s: i for i, s in enumerate(SYMBOL_SETS[DEFAULT_SYMBOLS])},
    IPA_SYMBOLS: {s: i for i, s in enumerate(SYMBOL_SETS[IPA_SYMBOLS])},
}
id_to_symbol = {
    DEFAULT_SYMBOLS: {i: s for i, s in enumerate(SYMBOL_SETS[DEFAULT_SYMBOLS])},
    IPA_SYMBOLS: {i: s for i, s in enumerate(SYMBOL_SETS[IPA_SYMBOLS])},
}
curly_re = re.compile(r"(.*?)\{(.+?)\}(.*)")
words_re = re.compile(
    r"([a-zA-ZÀ-ž]+['][a-zA-ZÀ-ž]{1,2}|[a-zA-ZÀ-ž]+)|([{][^}]+[}]|[^a-zA-ZÀ-ž{}]+)"
)


def symbols_to_sequence(symbols, symbol_set=DEFAULT_SYMBOLS, ignore_symbols=["_", "~"]):
    return [
        symbol_to_id[symbol_set][s]
        for s in symbols
        if should_keep_symbol(s, symbol_set, ignore_symbols)
    ]


def arpabet_to_sequence(text, symbol_set=DEFAULT_SYMBOLS):
    return symbols_to_sequence(["@" + s for s in text.split()], symbol_set=symbol_set)


def should_keep_symbol(s, symbol_set=DEFAULT_SYMBOLS, ignore_symbols=["_", "~"]):
    return s in symbol_to_id[symbol_set] and s not in ignore_symbols
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/text.symbols.ipynb (unless otherwise specified).

__all__ = ['symbols', 'symbols_with_ipa', 'DEFAULT_SYMBOLS', 'IPA_SYMBOLS', 'SYMBOL_SETS', 'symbols_to_sequence',
           'arpabet_to_sequence', 'should_keep_symbol', 'symbol_to_id', 'id_to_symbol', 'curly_re', 'words_re']

# Cell

""" from https://github.com/keithito/tacotron """

"""
Defines the set of symbols used in text input to the model.
The default is a set of ASCII characters that works well for English or text that has been run through Unidecode. For other data, you can modify _characters. See TRAINING_DATA.md for details. """

from . import cmudict

_pad = "_"
_punctuation = "!'\",.:;? "
_math = "#%&*+-/[]()"
_special = "@©°½—₩€$"
_accented = "áçéêëñöøćž"
_numbers = "0123456789"
_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
_letters_ipa = "ɑɐɒæɓʙβɔɕçɗɖðʤəɘɚɛɜɝɞɟʄɡɠɢʛɦɧħɥʜɨɪʝɭɬɫɮʟɱɯɰŋɳɲɴøɵɸθœɶʘɹɺɾɻʀʁɽʂʃʈʧʉʊʋⱱʌɣɤʍχʎʏʑʐʒʔʡʕʢǀǁǂǃˈˌːˑʼʴʰʱʲʷˠˤ˞↓↑→↗↘'̩'ᵻ"

# Prepend "@" to ARPAbet symbols to ensure uniqueness (some are the same as
# uppercase letters):
_arpabet = ["@" + s for s in cmudict.valid_symbols]

# Export all symbols:
symbols = (
    list(_pad + _punctuation + _math + _special + _accented + _numbers + _letters)
    + _arpabet
)

symbols_with_ipa = symbols + list(_letters_ipa)

DEFAULT_SYMBOLS = "default"
IPA_SYMBOLS = "ipa"
SYMBOL_SETS = {
    DEFAULT_SYMBOLS: symbols,
    IPA_SYMBOLS: symbols_with_ipa,
}

# Cell
import re

symbol_to_id = {
    DEFAULT_SYMBOLS: {s: i for i, s in enumerate(SYMBOL_SETS[DEFAULT_SYMBOLS])},
    IPA_SYMBOLS: {s: i for i, s in enumerate(SYMBOL_SETS[IPA_SYMBOLS])},
}
id_to_symbol = {
    DEFAULT_SYMBOLS: {i: s for i, s in enumerate(SYMBOL_SETS[DEFAULT_SYMBOLS])},
    IPA_SYMBOLS: {i: s for i, s in enumerate(SYMBOL_SETS[IPA_SYMBOLS])},
}
curly_re = re.compile(r"(.*?)\{(.+?)\}(.*)")
words_re = re.compile(
    r"([a-zA-ZÀ-ž]+['][a-zA-ZÀ-ž]{1,2}|[a-zA-ZÀ-ž]+)|([{][^}]+[}]|[^a-zA-ZÀ-ž{}]+)"
)


def symbols_to_sequence(symbols, symbol_set=DEFAULT_SYMBOLS, ignore_symbols=["_", "~"]):
    return [
        symbol_to_id[symbol_set][s]
        for s in symbols
        if should_keep_symbol(s, symbol_set, ignore_symbols)
    ]


def arpabet_to_sequence(text, symbol_set=DEFAULT_SYMBOLS):
    return symbols_to_sequence(["@" + s for s in text.split()], symbol_set=symbol_set)


def should_keep_symbol(s, symbol_set=DEFAULT_SYMBOLS, ignore_symbols=["_", "~"]):
    return s in symbol_to_id[symbol_set] and s not in ignore_symbols
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/text.symbols.ipynb (unless otherwise specified). # Cell from https://github.com/keithito/tacotron Defines the set of symbols used in text input to the model. The default is a set of ASCII characters that works well for English or text that has been run through Unidecode. For other data, you can modify _characters. See TRAINING_DATA.md for details. # Prepend "@" to ARPAbet symbols to ensure uniqueness (some are the same as # uppercase letters): # Export all symbols: # Cell