Skip to content

Commit e79d085

Browse files
authored
Merge pull request #529 from remsky/feat/normalization-followups
feat(normalizer): dashes, emoji, phone numbers, all-caps, plural acronyms; web normalization menu and graded voice list (#249, #259, #353)
2 parents 8f1b42f + 5fec3ad commit e79d085

31 files changed

Lines changed: 759 additions & 248 deletions

‎.claude/skills/integration-tests/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ Or the full compose stack (builds a CPU server + test-client, self-contained):
3636
- `test_tts_roundtrip.py` - synth + Whisper transcribe across 9 languages, WER/CER thresholds
3737
- `test_voices_endpoint.py` - voice listing shape, legacy compat, nova mapping
3838

39-
17 tests total. The roundtrip tests need ~30s (Whisper inference is the bottleneck).
39+
19 tests total. The roundtrip tests need ~30s (Whisper inference is the bottleneck).

‎.claude/skills/web-contrib/SKILL.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ Read [AGENTS.md](../../../AGENTS.md) and [CONTRIBUTING.md](../../../CONTRIBUTING
2929
- E2e: `npm run test:e2e` (Playwright against a static fixture server, no TTS backend needed).
3030
- Bundled Chromium has no mp3 codec, so real MSE playback needs system Chrome: launch with `channel: 'chrome'` in the spec/config when a test depends on real decoding.
3131
- For manual testing against a real backend, mount `web/` over the image's copy in the compose file rather than rebuilding per edit.
32+
- Before committing, check the change against [modern-web-guidance](https://developer.chrome.com/docs/modern-web-guidance) for current HTML/CSS/JS and accesibility patterns.
33+

‎CHANGELOG.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ Notable changes to this project will be documented in this file.
55
Per-PR attribution and contributor credits are published automatically on the corresponding GitHub release page; this file is the curated, human-readable summary.
66

77
## [Unreleased]
8+
### Added
9+
- `normalization_options.remove_emoji` drops emoji before synthesis instead of reading them by name, any language (#353). Off by default.
10+
- `normalization_options.caps_normalization` reads all-caps headers and names (`ARNE SAKNUSSEMM`) as words instead of letter by letter. On by default. Short acronyms (`FBI`, `US GDP`) are still spelled.
11+
812
### Changed
913
- Text normalization refactored towards multi-language support: `Normalizer` base class w/ neutral passes, `EnglishNormalizer` implements the rest, registry keyed by lang code. Adding a language is a subclass + table test, see CONTRIBUTING.md.
14+
- Web player:
15+
- the normalize checkbox is now a menu with every `normalization_options` field.
16+
- voice list sorted by model card grade, best first, then name. `DEFAULT_VOICE` is the preselected voice.
1017

1118
### Fixed
1219
- Blank lines now end a sentence, so headings, bylines, etc no longer run into the next paragraph. Single newlines still join (#519, #525 by @Christian-Sidak).
@@ -16,7 +23,13 @@ Per-PR attribution and contributor credits are published automatically on the co
1623
- Digits glued to letters (`MP3`, `B2B`, `v1.0`, `1.5x`) pass through as written. `COVID-19` is no longer COVID minus nineteen.
1724
- `.5` reads as zero point five, `1980S` as nineteen eighty S.
1825
- Long digit runs no longer stall or 500 the request.
26+
- Phone numbers read as spoken digits, `555-123-4567` as five five five, one two three, four five six seven.
27+
- `3.5 GHz` reads gigahertz and `1 min` reads one minute with `unit_normalization` on.
28+
- Plural and possessive acronyms (`DVDs`, `DVD's`) are no longer rewritten to `DVD'S`, which was spelled out as dee-vee-dee-ess.
1929
- Times with seconds keep their am/pm (`12:30:15 pm`).
30+
- `DEFAULT_VOICE` now applies to speech requests that omit a voice. Previously it only chose the warmup voice and requests fell back to `af_heart`. `/v1/audio/voices` reports it as `default_voice`.
31+
- Blank input, or emoji-only input with `remove_emoji`, is a 400 on the streaming path too, not an empty 200.
32+
- `--` and `---` read as a dash. Previously the words on either side fused and word timestamps stopped for the rest of the chunk (#249).
2033

2134
## [v0.8.2] - 2026-09-05
2235
### Added

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ Global API [loguru logging level](https://loguru.readthedocs.io/en/stable/api/lo
780780
<details>
781781
<summary>Missing words & Missing some timestamps</summary>
782782
783-
The API normalizes input text, which can incorrectly remove or change some phrases. Disable it with `"normalization_options":{"normalize": false}` in the request json:
783+
The API normalizes input text, which can incorrectly remove or change some phrases. Disable it with `"normalization_options":{"normalize": false}` in the request json, the full field list is in [Text normalization](docs/configuration.md#text-normalization):
784784
```python
785785
import requests
786786

‎api/src/core/config.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
)
55
from pathlib import Path
66

7-
import torch
87
from dotenv import dotenv_values
98
from pydantic_settings import BaseSettings
109

@@ -106,6 +105,8 @@ def get_device(self) -> str:
106105
return self.device_type
107106

108107
# Auto-detect device
108+
import torch
109+
109110
if torch.backends.mps.is_available():
110111
return "mps"
111112
elif torch.cuda.is_available():

‎api/src/inference/kokoro_v1.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ async def generate(
400400
continue
401401
if not token.text or not token.text.strip():
402402
continue
403+
if token.start_ts is None or token.end_ts is None:
404+
continue
403405

404406
start_time = float(token.start_ts) + current_offset
405407
end_time = float(token.end_ts) + current_offset

‎api/src/routers/development.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
from ..services.streaming_audio_writer import StreamingAudioWriter
1616
from ..services.temp_manager import TempFileWriter
1717
from ..services.text_processing import smart_split
18-
from ..services.text_processing.text_processor import check_pause_budget
18+
from ..services.text_processing.text_processor import (
19+
check_pause_budget,
20+
check_speakable,
21+
)
1922
from ..services.tts_service import TTSService
2023
from ..structures import (
2124
CaptionedSpeechRequest,
@@ -241,6 +244,11 @@ async def create_captioned_speech(
241244
apply_alias_rate(request)
242245
# checked post-SSML and pre-stream, so an over-budget request 400s before headers
243246
check_pause_budget(request.input)
247+
check_speakable(
248+
request.input,
249+
request.allow_voice_tags,
250+
request.normalization_options,
251+
)
244252

245253
# Set content type based on format
246254
content_type = {

‎api/src/routers/openai_compatible.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ..services.text_processing.text_processor import (
1717
VOICE_TAG_PATTERN,
1818
check_pause_budget,
19+
check_speakable,
1920
)
2021
from ..services.tts_service import TTSService
2122
from ..structures import OpenAISpeechRequest
@@ -331,6 +332,11 @@ async def create_speech(
331332
apply_alias_rate(request)
332333
# checked post-SSML and pre-stream, so an over-budget request 400s before headers
333334
check_pause_budget(request.input)
335+
check_speakable(
336+
request.input,
337+
request.allow_voice_tags,
338+
request.normalization_options,
339+
)
334340

335341
# Set content type based on format
336342
content_type = {
@@ -725,7 +731,8 @@ async def list_voices(legacy: bool = False):
725731
full voice list. Entries also carry `target_quality`, `training_duration`
726732
and `overall_grade` for the voices graded in the upstream model card;
727733
ungraded voices (Spanish, Brazilian Portuguese, custom `.pt` files) omit
728-
those keys. Pass `?legacy=true` for the pre-0.3.x plain-string shape.
734+
those keys. `default_voice` is the DEFAULT_VOICE setting. Pass
735+
`?legacy=true` for the pre-0.3.x plain-string shape.
729736
"""
730737
try:
731738
tts_service = await get_tts_service()
@@ -735,7 +742,8 @@ async def list_voices(legacy: bool = False):
735742
return {
736743
"voices": [
737744
{"id": v, "name": v, **_voice_grades.get(v, {})} for v in voices
738-
]
745+
],
746+
"default_voice": settings.default_voice,
739747
}
740748
except Exception as e:
741749
logger.error(f"Error listing voices: {str(e)}")

‎api/src/services/text_processing/normalization/base.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def pass_order(
2323
self, options: NormalizationOptions
2424
) -> tuple[Callable[[str], str] | None, ...]:
2525
return (
26+
self.caps_words if options.caps_normalization else None,
2627
self.contractions,
2728
self.emails if options.email_normalization else None,
2829
self.urls if options.url_normalization else None,
@@ -39,7 +40,6 @@ def pass_order(
3940
self.common_words,
4041
self.numbers,
4142
self.symbols if options.replace_remaining_symbols else None,
42-
self.possessives,
4343
self.acronyms,
4444
)
4545

@@ -51,9 +51,9 @@ def normalize(self, text: str, options: NormalizationOptions) -> str:
5151

5252
# neutral passes
5353
def quotes(self, text: str) -> str:
54-
text = text.replace(chr(8216), "'").replace(chr(8217), "'")
55-
text = text.replace("«", chr(8220)).replace("»", chr(8221))
56-
return text.replace(chr(8220), '"').replace(chr(8221), '"')
54+
text = text.replace("\u2018", "'").replace("\u2019", "'")
55+
text = text.replace("\u00ab", "\u201c").replace("\u00bb", "\u201d")
56+
return text.replace("\u201c", '"').replace("\u201d", '"')
5757

5858
def cjk_punctuation(self, text: str) -> str:
5959
for a, b in CJK_PUNCTUATION.items():
@@ -65,6 +65,9 @@ def whitespace(self, text: str) -> str:
6565
return re.sub(r" +", " ", text)
6666

6767
# language hooks, no-op until overridden
68+
def caps_words(self, text: str) -> str:
69+
return text
70+
6871
def contractions(self, text: str) -> str:
6972
return text
7073

@@ -98,8 +101,5 @@ def numbers(self, text: str) -> str:
98101
def symbols(self, text: str) -> str:
99102
return text
100103

101-
def possessives(self, text: str) -> str:
102-
return text
103-
104104
def acronyms(self, text: str) -> str:
105105
return text

‎api/src/services/text_processing/normalization/english.py‎

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
import inflect
88

99
from .base import Normalizer
10-
from .english_data import MONEY_UNITS, SYMBOL_REPLACEMENTS, VALID_TLDS, VALID_UNITS
10+
from .english_data import (
11+
INFLECT_NOUNS,
12+
MONEY_UNITS,
13+
SYMBOL_REPLACEMENTS,
14+
VALID_TLDS,
15+
VALID_UNITS,
16+
)
1117

1218
INFLECT_ENGINE = inflect.engine()
19+
for singular, plural in INFLECT_NOUNS.items():
20+
INFLECT_ENGINE.defnoun(singular, plural)
1321

1422

1523
def conditional_int(number: float, threshold: float = 0.00001):
@@ -53,6 +61,21 @@ def wrapped(m: re.Match[str]) -> str:
5361
class EnglishNormalizer(Normalizer):
5462
lang_codes = ("a", "b", "en-us", "en-gb")
5563

64+
CAPS_RUN_PATTERN = re.compile(r"\b[A-Z]+(?:[^A-Za-z]+[A-Z]+)+\b")
65+
CAPS_WORD_PATTERN = re.compile(r"\b[A-Z]{4,}\b")
66+
LONG_CAPS_PATTERN = re.compile(r"\b[A-Z]{6,}\b")
67+
ROMAN_PATTERN = re.compile(r"[IVXLCDM]+")
68+
69+
def caps_words(self, text: str) -> str:
70+
def lower(m: re.Match[str]) -> str:
71+
word = m.group()
72+
return word if self.ROMAN_PATTERN.fullmatch(word) else word.lower()
73+
74+
text = self.CAPS_RUN_PATTERN.sub(
75+
lambda run: self.CAPS_WORD_PATTERN.sub(lower, run.group()), text
76+
)
77+
return self.LONG_CAPS_PATTERN.sub(lower, text)
78+
5679
def contractions(self, text: str) -> str:
5780
# Expand the "'re" contractions that espeak mis-phonemizes with a spurious
5881
# /ɹeɪ/ ("-ray") ending, e.g. "how're" -> /haʊɹeɪ/ which sounds like "harry".
@@ -175,28 +198,16 @@ def optional_plurals(self, text: str) -> str:
175198
return re.sub(r"\(s\)", "s", text)
176199

177200
PHONE_PATTERN = re.compile(
178-
r"(\+?\d{1,2})?([ .-]?)(\(?\d{3}\)?)[\s.-](\d{3})[\s.-](\d{4})"
201+
r"(?:(\+?\d{1,2})[ .-]?)?(\(?\d{3}\)?)[\s.-](\d{3})[\s.-](\d{4})"
179202
)
180203

181204
def phone_numbers(self, text: str) -> str:
182205
def handle(p: re.Match[str]) -> str:
183-
p = list(p.groups())
184-
185-
country_code = ""
186-
if p[0] is not None:
187-
p[0] = p[0].replace("+", "")
188-
country_code += INFLECT_ENGINE.number_to_words(p[0])
189-
190-
area_code = INFLECT_ENGINE.number_to_words(
191-
p[2].replace("(", "").replace(")", ""), group=1, comma=""
206+
groups = [re.sub(r"\D", "", g) for g in p.groups() if g]
207+
return ", ".join(
208+
" ".join(INFLECT_ENGINE.number_to_words(d) for d in g) for g in groups
192209
)
193210

194-
telephone_prefix = INFLECT_ENGINE.number_to_words(p[3], group=1, comma="")
195-
196-
line_number = INFLECT_ENGINE.number_to_words(p[4], group=1, comma="")
197-
198-
return ",".join([country_code, area_code, telephone_prefix, line_number])
199-
200211
return self.PHONE_PATTERN.sub(handle, text)
201212

202213
TIME_PATTERN = re.compile(
@@ -345,14 +356,11 @@ def handle(n: re.Match[str]) -> str:
345356
return self.NUMBER_PATTERN.sub(handle, text)
346357

347358
def symbols(self, text: str) -> str:
359+
text = re.sub(r" ?-{2,} ?", " — ", text)
348360
for symbol, replacement in SYMBOL_REPLACEMENTS.items():
349361
text = text.replace(symbol, replacement)
350362
return text
351363

352-
def possessives(self, text: str) -> str:
353-
text = re.sub(r"(?<=[BCDFGHJ-NP-TV-Z])'?s\b", "'S", text)
354-
return re.sub(r"(?<=X')S\b", "s", text)
355-
356364
def acronyms(self, text: str) -> str:
357365
text = re.sub(
358366
# {2,12} not {2,}: real acronyms are short; unbounded backtracks O(n^2) on floods.

0 commit comments

Comments
 (0)