Skip to content

fix(tokenize): keep non-English abbreviations in one sentence in blingfire - #8932

Open
dorukdumlu wants to merge 3 commits into
livekit:mainfrom
dorukdumlu:blingfire-abbreviations
Open

dorukdumlu wants to merge 3 commits into
livekit:mainfrom
dorukdumlu:blingfire-abbreviations

Conversation

@dorukdumlu

@dorukdumlu dorukdumlu commented Dec 4, 2026 •

Copy link
Copy Markdown

Fixes #8931

Summary

blingfire (the default sentence tokenizer in tts_node, StreamAdapter and most TTS plugins) ends a sentence after abbreviations that other languages put before a name, a street or a number, so TTS gets Kartınız Bağdat Cad. and No: 12 Kadıköy adresine gönderildi. as two sentences. English (Dr. Smith, Main St. Suite 200) and French are not affected.

_split_sentences now drops a blingfire boundary when the word before the period is one of a short list of these abbreviations, the same way it already adds a boundary after a danda:

  • Turkish: Doç Uzm Yrd Öğr Arş Müh (titles), Cad Cd Sok Sk Mah Mh Blv (addresses)
  • Spanish Dra Lic Ing Dña Avda Pza Ctra, Portuguese Dra Pç, Italian Dott Avv Ing, Dutch dhr mevr mw mr, Polish inż ul, German Hrn

The list holds only abbreviations blingfire splits after (measured in the issue). The match is case-sensitive, on the whole word, plus the capitalised form of the lowercase entries. A boundary with nothing after it is kept. Left out on purpose, because they can end a sentence: Hz (also hertz), Ud., Rod (a name), Dutch ir (Spanish and Portuguese "to go"), Polish os (French "bone").

before after
Kartınız Bağdat Cad. No: 12 Kadıköy adresine gönderildi. split after Cad. one sentence
Su cita con la Dra. Martínez es en la Avda. Diagonal mañana. 3 sentences one sentence
Uw afspraak met dhr. Jansen is morgen om tien uur precies. split after dhr. one sentence
The signal runs at 50 Hz. Then it stops. 2 sentences 2 sentences
Toplantı yeri İstanbul. Yarın görüşürüz. 2 sentences 2 sentences

Cost: 53 → 66 µs per _split_sentences call on a 453-character reply.

Testing

  • tests/test_tokenizer.py: one case per language (all failed before the change), counter-cases that must still split (an ordinary word, Hz, İstanbul ending in ul, Spanish ir., French os.), a last sentence ending in an abbreviation (newlines still normalized), and two streamed tests with the tts_node settings (retain_format=True): chunks that start with a space, and a chunk that ends in Cad.
  • unit tests in the 16 modules that use the tokenizers or StreamAdapter: 604 passed
  • uv run pytest --unit --audio_eot: no new failures compared to main (on Windows, test_hosted_logs, test_room and a few others fail on both)
  • ruff format, ruff check, mypy --platform linux -p livekit.agents

@dorukdumlu
dorukdumlu requested a review from a team as a code owner December 4, 2026 01:43
devin-ai-integration[bot]

This comment was marked as resolved.

…ailing boundary

"ir" (Spanish/Portuguese "to go") and "os" (French "bone") end sentences in
other languages. A boundary with nothing after it is kept, so the last sentence
still has its newlines normalized.
devin-ai-integration[bot]

This comment was marked as resolved.

…abbreviation in the sentence

A stream chunk that ends in "Cad. " returned the space as a token of its own,
and BufferedTokenStream committed "... Cad." before the rest of the address.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

blingfire sentence tokenizer ends a sentence after common non-English abbreviations

1 participant