How to use the phonemizer.separator function in phonemizer

To help you get started, we’ve selected a few phonemizer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bootphon / phonemizer / test / test_festival.py View on Github external
def test_im():
    sep = separator.Separator(word=' ', syllable='', phone='')
    assert _test("I'm looking for an image", sep) \
        == ['aym luhkaxng faor axn ihmaxjh']
    assert _test("Im looking for an image", sep) \
        == ['ihm luhkaxng faor axn ihmaxjh']
github bootphon / phonemizer / test / test_backends.py View on Github external
self.p = lambda text: phonemize(
            text, language='en-us', backend='festival', strip=True,
            separator=separator.Separator(' ', '|', '-'))
github bootphon / phonemizer / test / test_espeak.py View on Github external
'(en)fʊtbɔːl(fr)',
        'syʁtu lə- (en)ɹiəl(fr) madʁid',
        'nytiliz pa (en)ɡuːɡəl(fr)']

    # default behavior is to keep the flags
    backend = EspeakBackend('fr-fr')
    out = backend._phonemize_aux(text, separator.Separator(), True)
    assert out == [
        'ʒɛm lɑ̃ɡlɛ',
        'ʒɛm lə- (en)fʊtbɔːl(fr)',
        '(en)fʊtbɔːl(fr)',
        'syʁtu lə- (en)ɹiəl(fr) madʁid',
        'nytiliz pa (en)ɡuːɡəl(fr)']

    backend = EspeakBackend('fr-fr', language_switch='remove-flags')
    out = backend._phonemize_aux(text, separator.Separator(), True)
    assert out == [
        'ʒɛm lɑ̃ɡlɛ',
        'ʒɛm lə- fʊtbɔːl',
        'fʊtbɔːl',
        'syʁtu lə- ɹiəl madʁid',
        'nytiliz pa ɡuːɡəl']

    backend = EspeakBackend('fr-fr', language_switch='remove-utterance')
    out = backend._phonemize_aux(text, separator.Separator(), True)
    assert out == ['ʒɛm lɑ̃ɡlɛ']

    with pytest.raises(RuntimeError):
        backend = EspeakBackend('fr-fr', language_switch='foo')
github bootphon / phonemizer / test / test_segments.py View on Github external
def test_separator_3():
    backend = SegmentsBackend('cree')
    text = 'achi acho'

    sep = separator.Separator(word=' ', syllable=None, phone='_')
    assert backend.phonemize(text, separator=sep) == u'ʌ_tʃ_ɪ_ ʌ_tʃ_ʊ_ '
    assert backend.phonemize(text, separator=sep, strip=True) \
        == u'ʌ_tʃ_ɪ ʌ_tʃ_ʊ'
github mozilla / TTS / utils / text / __init__.py View on Github external
def text2phone(text, language):
    '''
    Convert graphemes to phonemes.
    '''
    seperator = phonemizer.separator.Separator(' |', '', '|')
    #try:
    punctuations = re.findall(PHONEME_PUNCTUATION_PATTERN, text)
    ph = phonemize(text, separator=seperator, strip=False, njobs=1, backend='espeak', language=language)
    ph = ph[:-1].strip() # skip the last empty character
    # Replace \n with matching punctuations.
    if punctuations:
        # if text ends with a punctuation.
        if text[-1] == punctuations[-1]:
            for punct in punctuations[:-1]:
                ph = ph.replace('| |\n', '|'+punct+'| |', 1)
            try:
                ph = ph + punctuations[-1]
            except:
                print(text)
        else:
            for punct in punctuations:
github bootphon / phonemizer / phonemizer / main.py View on Github external
help='output text file to write, if not specified write to stdout.')

    group = parser.add_argument_group('separators')
    group.add_argument(
        '-p', '--phone-separator', metavar='',
        default=separator.default_separator.phone,
        help='phone separator, default is "%(default)s".')

    group.add_argument(
        '-w', '--word-separator', metavar='',
        default=separator.default_separator.word,
        help='word separator, default is "%(default)s".')

    group.add_argument(
        '-s', '--syllable-separator', metavar='',
        default=separator.default_separator.syllable,
        help='''syllable separator, only valid for festival backend,
        this option has no effect if espeak or segments is used.
        Default is "%(default)s".''')

    group.add_argument(
        '--strip', action='store_true',
        help='removes the end separators in phonemized tokens.')

    group = parser.add_argument_group('backends')
    group.add_argument(
        '-b', '--backend', metavar='', default='espeak',
        choices=['espeak', 'festival', 'segments'],
        help="""the phonemization backend, must be 'espeak', 'festival' or
        'segments'. Default is %(default)s.""")

    group = parser.add_argument_group('specific to espeak backend')