Skip to content

Commit

Permalink
phonemizer-2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Bernard committed Nov 7, 2019
1 parent 6372005 commit 5ed5ca5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
55 changes: 27 additions & 28 deletions phonemizer/backend/espeak.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,38 +164,37 @@ def _phonemize_aux(self, text, separator, strip):
if self.logger:
self.logger.debug('running %s', command)

raw_output = subprocess.check_output(
line = subprocess.check_output(
shlex.split(command, posix=False)).decode('utf8')

# espeak can split an utterance into several lines because
# of punctuation, here we merge the lines into a single one
raw_output = raw_output.strip().replace('\n', ' ')
finally:
os.remove(data.name)

for line in (l.strip() for l in raw_output.split('\n') if l):
line = self._process_lang_switch(n, line)
if not line:
continue

out_line = ''
for word in line.split(u' '):
w = word.strip()

# remove the stresses on phonemes
if not self._with_stress:
w = w.replace(u"ˈ", u'')
w = w.replace(u'ˌ', u'')
w = w.replace(u"'", u'')

if not strip:
w += '_'
w = w.replace('_', separator.phone)
out_line += w + separator.word

if strip:
out_line = out_line[:-len(separator.word)]
output.append(out_line)
# espeak can split an utterance into several lines because
# of punctuation, here we merge the lines into a single one
line = line.strip().replace('\n', ' ').replace(' ', ' ')

line = self._process_lang_switch(n, line)
if not line:
continue

out_line = ''
for word in line.split(u' '):
w = word.strip()

# remove the stresses on phonemes
if not self._with_stress:
w = w.replace(u"ˈ", u'')
w = w.replace(u'ˌ', u'')
w = w.replace(u"'", u'')

if not strip:
w += '_'
w = w.replace('_', separator.phone)
out_line += w + separator.word

if strip:
out_line = out_line[:-len(separator.word)]
output.append(out_line)

# warn the user on language switches fount during phonemization
if self._lang_switch_list:
Expand Down
1 change: 0 additions & 1 deletion test/test_espeak.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def test_language_switch():
'a comma. a point.',
'a comma,, a point.',
'a comma, , a point.',
'a comma, a point,',
'a comma? a point!']
for s in (True, False)
for u in (separator.Separator(), separator.Separator(word='_', phone=' '))
Expand Down

0 comments on commit 5ed5ca5

Please sign in to comment.