Skip to content

Commit

Permalink
fixed #12 festival supports apostrophes again
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmaat committed Aug 28, 2018
1 parent c41e5e1 commit a2af480
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 7 additions & 2 deletions phonemizer/festival.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ def _double_quoted(line):

def _cleaned(line):
"""Remove 'forbidden' characters from the line"""
return line.replace('"', '').replace("'", '').replace(
'(', '').replace(')', '').strip()
# special case (very unlikely) where a line is only made of '
if len(set(line) - set("'")) == 0:
line = ''

# remove forbidden characters (reserved for scheme, ie festival
# scripting language)
return line.replace('"', '').replace('(', '').replace(')', '').strip()


def _preprocess(text):
Expand Down
11 changes: 9 additions & 2 deletions test/test_festival.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from phonemizer import festival, separator


def _test(text):
def _test(text, separator=separator.Separator(' ', '|', '-')):
return festival.phonemize(
text, language='en-us', strip=True,
separator=separator.Separator(' ', '|', '-'))
separator=separator)

@pytest.mark.skipif(
'2.1' in festival.festival_version(),
Expand All @@ -45,3 +45,10 @@ def test_its():
assert _test("its") == ['ih-t-s']
assert _test("it s") == ['ih-t eh-s']
assert _test('it "s') == ['ih-t eh-s']

def test_im():
sep = separator.Separator(' ', '', '')
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']

0 comments on commit a2af480

Please sign in to comment.