Skip to content

Commit a2af480

Browse files
committed
fixed #12 festival supports apostrophes again
1 parent c41e5e1 commit a2af480

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

phonemizer/festival.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,13 @@ def _double_quoted(line):
8989

9090
def _cleaned(line):
9191
"""Remove 'forbidden' characters from the line"""
92-
return line.replace('"', '').replace("'", '').replace(
93-
'(', '').replace(')', '').strip()
92+
# special case (very unlikely) where a line is only made of '
93+
if len(set(line) - set("'")) == 0:
94+
line = ''
95+
96+
# remove forbidden characters (reserved for scheme, ie festival
97+
# scripting language)
98+
return line.replace('"', '').replace('(', '').replace(')', '').strip()
9499

95100

96101
def _preprocess(text):

test/test_festival.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
from phonemizer import festival, separator
1919

2020

21-
def _test(text):
21+
def _test(text, separator=separator.Separator(' ', '|', '-')):
2222
return festival.phonemize(
2323
text, language='en-us', strip=True,
24-
separator=separator.Separator(' ', '|', '-'))
24+
separator=separator)
2525

2626
@pytest.mark.skipif(
2727
'2.1' in festival.festival_version(),
@@ -45,3 +45,10 @@ def test_its():
4545
assert _test("its") == ['ih-t-s']
4646
assert _test("it s") == ['ih-t eh-s']
4747
assert _test('it "s') == ['ih-t eh-s']
48+
49+
def test_im():
50+
sep = separator.Separator(' ', '', '')
51+
assert _test("I'm looking for an image", sep) \
52+
== ['aym luhkaxng faor axn ihmaxjh']
53+
assert _test("Im looking for an image", sep) \
54+
== ['ihm luhkaxng faor axn ihmaxjh']

0 commit comments

Comments
 (0)