TPdfSpokenText chunk from a contiguous TPdfWordBox rangefunction BuildSpokenTextFromWords(const Words: TPdfWordBoxes; FirstWord, LastWord: Integer): TPdfSpokenText;
| Words | TPdfWordBoxes - Word boxes from a page or viewer |
| FirstWord | Integer - First zero-based word index, clamped to 0 |
| LastWord | Integer - Last zero-based word index, clamped to High(Words) |
TPdfSpokenText whose Text is ready for a speech engine and whose Spans map each word back to page textThe helper traverses the selected TPdfWordBox range and appends each word with SpokenTextAppend
The resulting span table preserves each word's page number, source character index and source character count so a speech engine offset can be translated back to the PDF page
WordSegmentation defaults to wsmWhitespace, preserving the original space/tab/newline/NBSP tokenizer
Explicit wsmCjk provides deterministic tailored units: individual Han scalars, Hiragana runs, Katakana runs, Hangul runs, separate punctuation and script transitions, including fullwidth forms and Unicode whitespace
Recognised combining accents, voiced marks and variation selectors remain with the preceding unit; valid surrogate pairs are never split
This profile provides useful navigation units without a dictionary and is not linguistic Chinese/Japanese word recognition or full Unicode boundary-conformance; see Unicode text segmentation for the distinction between default boundaries and language-specific tailoring
Document, viewer and session modes are independent; change the applicable host before extracting or playing words
Viewer changes clear tracked/prefetched word geometry and the active cursor; session changes stop playback so the next chunk uses the selected mode
Native CJK word boxes include CharacterIndices, mapping each UTF-16 text unit to its native character index; StartIndex and Count remain native ranges, whilst pure BuildWordBoxes uses UTF-16 ranges
BuildSpokenTextFromWords preserves adjacent source units without inserting artificial spaces and emits exact source mappings from CharacterIndices; invalid explicit maps raise EPdfError
SpokenToPageChar or TPdfReadingSession.FeedSpokenPosition to drive word-level highlighting from the spoken offsetWords := Pdf1.PageWordBoxes;
Spoken := BuildSpokenTextFromWords(Words, 0, High(Words));