Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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']
self.p = lambda text: phonemize(
text, language='en-us', backend='festival', strip=True,
separator=separator.Separator(' ', '|', '-'))
'(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')
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ʃ_ʊ'
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:
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')