scriptconv-copyleft 0.1.0a1__tar.gz → 0.1.2a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/PKG-INFO +1 -1
  2. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/mul.py +32 -4
  3. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/version.py +1 -1
  4. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft.egg-info/PKG-INFO +1 -1
  5. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_espeak_acute_stress.py +21 -0
  6. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_espeak_french_english_switch.py +10 -1
  7. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/LICENSE +0 -0
  8. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/README.md +0 -0
  9. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/pyproject.toml +0 -0
  10. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/__init__.py +0 -0
  11. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/__init__.py +0 -0
  12. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/_vendored/__init__.py +0 -0
  13. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/_vendored/kog2p/COPYING +0 -0
  14. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/_vendored/kog2p/LICENSE.md +0 -0
  15. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/_vendored/kog2p/__init__.py +0 -0
  16. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/_vendored/kog2p/rulebook.txt +0 -0
  17. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/eu.py +0 -0
  18. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/fa.py +0 -0
  19. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/gl.py +0 -0
  20. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/ja.py +0 -0
  21. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/phonemizers/ko.py +0 -0
  22. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft/readings.py +0 -0
  23. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft.egg-info/SOURCES.txt +0 -0
  24. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft.egg-info/dependency_links.txt +0 -0
  25. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft.egg-info/requires.txt +0 -0
  26. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/scriptconv_copyleft.egg-info/top_level.txt +0 -0
  27. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/setup.cfg +0 -0
  28. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_espeak_get_lang_case.py +0 -0
  29. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_lang_default_region.py +0 -0
  30. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_match_lang_direction.py +0 -0
  31. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_match_lang_preferred_value.py +0 -0
  32. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_phonemizers_base.py +0 -0
  33. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_phonemizers_cjk_ar.py +0 -0
  34. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_phonemizers_friendly_import_errors.py +0 -0
  35. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_phonemizers_identity.py +0 -0
  36. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_phonemizers_misaki_british.py +0 -0
  37. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_phonemizers_punctuation.py +0 -0
  38. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_readings.py +0 -0
  39. {scriptconv_copyleft-0.1.0a1 → scriptconv_copyleft-0.1.2a1}/tests/test_transphone_extra_declares_auto_installs.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv-copyleft
3
- Version: 0.1.0a1
3
+ Version: 0.1.2a1
4
4
  Summary: scriptconv phonemizer backends whose code or dependencies are copyleft (GPL, LGPL, AGPL)
5
5
  Author-email: TigreGotico <contact@tigregotico.com>
6
6
  License-Expression: Apache-2.0 AND GPL-3.0-only
@@ -35,15 +35,30 @@ class EspeakError(Exception):
35
35
  # sentence, so a French voice reads "d'aujourd'hui" as English. Respell each of
36
36
  # them as French text espeak-ng reads correctly (checked against espeak-ng 1.52.0):
37
37
  # "de aujourd'hui" -> də oʒuʁdyˈi, "grand-mère" -> ɡʁˈɑ̃mˈɛʁ, "prud-homme" -> pʁˈydˈɔm.
38
+ def _elide_d(match: "re.Match[str]") -> str:
39
+ """"d'aujourd'hui" -> "de aujourd'hui", keeping the case the text was written in."""
40
+ word = match.group(0)
41
+ return ("DE " if word.isupper() else word[0] + "e ") + word[2:].replace("\u2019", "'")
42
+
43
+
44
+ def _hyphenate(match: "re.Match[str]") -> str:
45
+ """"grand'mère" -> "grand-mère" (the apostrophe becomes a hyphen; the letters keep their case)."""
46
+ return match.group(1) + "-" + match.group(2)
47
+
48
+
38
49
  _FRENCH_ENGLISH_SWITCH_FIXES = (
39
- (re.compile(r"\b([Dd])['\u2019]aujourd['\u2019]hui\b"), r"\1e aujourd'hui"),
40
- (re.compile(r"\b([Gg])rand['\u2019](m[\u00e8e]res?)\b"), r"\1rand-\2"),
41
- (re.compile(r"\b([Pp])rud['\u2019](hommes?)\b"), r"\1rud-\2"),
50
+ (re.compile(r"\bd['\u2019]aujourd['\u2019]hui\b", re.IGNORECASE), _elide_d),
51
+ (re.compile(r"\b(grand)['\u2019](m[\u00e8e]res?)\b", re.IGNORECASE), _hyphenate),
52
+ (re.compile(r"\b(prud)['\u2019](hommes?)\b", re.IGNORECASE), _hyphenate),
42
53
  )
43
54
 
44
55
 
45
56
  def _respell_for_espeak(text: str, lang: str) -> str:
46
- """Respell the few words espeak-ng mistakes for English in a French text."""
57
+ """Respell the few words espeak-ng mistakes for English in a French text.
58
+
59
+ The match ignores case, so a heading in capitals ("D'AUJOURD'HUI", "GRAND'MÈRE") gets
60
+ the same treatment; the replacement keeps whatever case each letter had.
61
+ """
47
62
  if lang.split("-")[0].lower() != "fr":
48
63
  return text
49
64
  for pattern, replacement in _FRENCH_ENGLISH_SWITCH_FIXES:
@@ -173,6 +188,9 @@ class EspeakPhonemizer(BasePhonemizer):
173
188
  """
174
189
 
175
190
  engine_distribution = "espeak-ng"
191
+ # The acute after a vowel becomes an espeak-ng stress position only in these
192
+ # languages, and only on the binary path (see reads_stress_mark).
193
+ stress_mark_langs = _ACUTE_STRESS_LANGS
176
194
  ESPEAK_LANGS = ['es-419', 'ca', 'qya', 'ga', 'et', 'ky', 'io', 'fa-latn', 'en-gb', 'fo', 'haw', 'kl',
177
195
  'ta', 'ml', 'gd', 'sd', 'es', 'hy', 'ur', 'ro', 'hi', 'or', 'ti', 'ca-va', 'om', 'tr', 'pa',
178
196
  'smj', 'mk', 'bg', 'cv', "fr", 'fi', 'en-gb-x-rp', 'ru', 'mt', 'an', 'mr', 'pap', 'vi', 'id',
@@ -217,6 +235,16 @@ class EspeakPhonemizer(BasePhonemizer):
217
235
  banner = self._run_espeak_command(["--version"])
218
236
  return self.engine_distribution, banner.split(":")[1].split()[0]
219
237
 
238
+ def reads_stress_mark(self, lang: str) -> bool:
239
+ """True when the espeak-ng binary reads the text and *lang* is one of :attr:`stress_mark_langs`.
240
+
241
+ Only the binary path turns the acute into a stress position. espyak gets the
242
+ text unchanged, and there the mark moves the stress off the marked vowel.
243
+ """
244
+ if self.prefer_espyak or not self._has_binary():
245
+ return False
246
+ return self._match_lang(lang, sorted(self.stress_mark_langs))[1] <= 10
247
+
220
248
  @classmethod
221
249
  def _has_binary(cls) -> bool:
222
250
  if cls._binary_available is None:
@@ -1,7 +1,7 @@
1
1
  # START_VERSION_BLOCK
2
2
  VERSION_MAJOR = 0
3
3
  VERSION_MINOR = 1
4
- VERSION_BUILD = 0
4
+ VERSION_BUILD = 2
5
5
  VERSION_ALPHA = 1
6
6
  # END_VERSION_BLOCK
7
7
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptconv-copyleft
3
- Version: 0.1.0a1
3
+ Version: 0.1.2a1
4
4
  Summary: scriptconv phonemizer backends whose code or dependencies are copyleft (GPL, LGPL, AGPL)
5
5
  Author-email: TigreGotico <contact@tigregotico.com>
6
6
  License-Expression: Apache-2.0 AND GPL-3.0-only
@@ -167,3 +167,24 @@ def test_a_stressed_monosyllable_keeps_its_stress_in_a_sentence(lang, text, word
167
167
  ])
168
168
  def test_other_text_reaches_espeak_unchanged(lang, voice, text):
169
169
  assert EspeakPhonemizer().phonemize_string(text, lang) == espeak(text, voice)
170
+
171
+
172
+ @pytest.mark.parametrize("lang", ["ru", "ru-RU", "rus", "uk", "uk-UA"])
173
+ def test_the_binary_path_reads_the_mark_in_russian_and_ukrainian(monkeypatch, lang):
174
+ monkeypatch.setattr(EspeakPhonemizer, "_binary_available", True)
175
+ assert EspeakPhonemizer().reads_stress_mark(lang)
176
+
177
+
178
+ @pytest.mark.parametrize("lang", ["be", "bg", "kk", "uz", "pt-PT"])
179
+ def test_the_binary_path_does_not_read_the_mark_in_other_languages(monkeypatch, lang):
180
+ monkeypatch.setattr(EspeakPhonemizer, "_binary_available", True)
181
+ assert not EspeakPhonemizer().reads_stress_mark(lang)
182
+
183
+
184
+ @pytest.mark.parametrize("lang", ["ru", "uk"])
185
+ def test_espyak_does_not_read_the_mark(monkeypatch, lang):
186
+ # espyak gets the text unchanged, and the mark moves the stress: Но́вая -> nʌvˈɑja
187
+ monkeypatch.setattr(EspeakPhonemizer, "_binary_available", True)
188
+ assert not EspeakPhonemizer(prefer_espyak=True).reads_stress_mark(lang)
189
+ monkeypatch.setattr(EspeakPhonemizer, "_binary_available", False)
190
+ assert not EspeakPhonemizer().reads_stress_mark(lang)
@@ -21,6 +21,14 @@ from scriptconv_copyleft.phonemizers.mul import EspeakPhonemizer, _respell_for_e
21
21
  ("grand'mere", "grand-mere"),
22
22
  ("prud'homme", "prud-homme"),
23
23
  ("Prud'hommes", "Prud-hommes"),
24
+ # All capitals and mixed case (CodeRabbit on scriptconv#160): the case is kept.
25
+ ("D'AUJOURD'HUI", "DE AUJOURD'HUI"),
26
+ ("D\u2019AUJOURD\u2019HUI", "DE AUJOURD'HUI"),
27
+ ("GRAND'MÈRE", "GRAND-MÈRE"),
28
+ ("GRAND'MÈRES", "GRAND-MÈRES"),
29
+ ("Grand'Mère", "Grand-Mère"),
30
+ ("PRUD'HOMMES", "PRUD-HOMMES"),
31
+ ("LE JOUR D'AUJOURD'HUI", "LE JOUR DE AUJOURD'HUI"),
24
32
  ])
25
33
  def test_the_words_espeak_mistakes_for_english_are_respelled_in_french(text, expected):
26
34
  assert _respell_for_espeak(text, "fr") == expected
@@ -40,7 +48,8 @@ def test_other_languages_are_left_alone():
40
48
  assert _respell_for_espeak("d'aujourd'hui", "it") == "d'aujourd'hui"
41
49
 
42
50
 
43
- @pytest.mark.parametrize("text", ["d'aujourd'hui", "Le jour d'aujourd'hui", "grand'mère", "les prud'hommes"])
51
+ @pytest.mark.parametrize("text", ["d'aujourd'hui", "Le jour d'aujourd'hui", "grand'mère", "les prud'hommes",
52
+ "D'AUJOURD'HUI", "GRAND'MÈRE", "PRUD'HOMMES"])
44
53
  def test_a_french_voice_gets_no_english_phones(text):
45
54
  phonemes = EspeakPhonemizer().phonemize_string(text, "fr-FR")
46
55
  # the English voice's vowels and affricate, which French never produces here