Documentation
¶
Overview ¶
Package text is the script pipeline shared by the Studio (M1), Stories and Audiobook (M3) and Dubbing (M4): segmentation into TTS chunks with source offsets, content-addressed chunk keys, word counts and runtime estimates.
Subpackages:
- markup: the SSML-lite parser ([pause 500ms], [voice:NAME], # chapters…)
- normalize: numbers, times, dates, currency and abbreviations → words
- lexicon: the pronunciation dictionary and [[word|say]] overrides
- autocast: speaker detection for Stories
Everything here is pure, allocation-light and goroutine-safe. Offsets are byte offsets into the source string; lengths that users see (max chars per chunk) count runes. Nothing here returns user-visible strings: problems are reported as Diagnostics (a code plus parameters) that the UI translates.
Index ¶
- Constants
- func Count(s string) (words, chars int)
- func Estimate(words, chars int) time.Duration
- func IsCJK(r rune) bool
- func IsHeading(line string) bool
- func IsUnspaced(r rune) bool
- func IsWordRune(r rune) bool
- func Key(text string, params map[string]string) string
- func NormalizeForKey(s string) string
- func Outside(s string, fn func(string) string) string
- func RuneLen(s string) int
- func SplitOverride(tag string) (word, say string, ok bool)
- type Chunk
- type Cut
- type Diagnostic
- type Mode
- type Options
- type Paragraph
- type Severity
- type Span
Constants ¶
const ( WordsPerMinute = 155 CharsPerSecond = 4.5 )
Reading rates used by Estimate: 155 words a minute for spaced scripts (the audiobook industry's narration rate) and 4.5 characters a second for unspaced ones (Mandarin/Japanese narration).
const DefaultMaxChars = 800
DefaultMaxChars is the TTS chunk limit (runes) when Options.MaxChars is 0.
Variables ¶
This section is empty.
Functions ¶
func Count ¶
Count counts the words of s the way a script editor's stats line does: words is the number of space-separated words in spaced scripts (Latin, Cyrillic, Hangul…); chars is the number of characters in unspaced scripts (Han, kana, Thai…), each of which is read on its own. Bracket tags are not counted.
func Estimate ¶
Estimate is the expected narration time for words spaced-script words and chars unspaced-script characters.
func IsCJK ¶
IsCJK reports whether r is a Han ideograph, kana, Bopomofo, Hangul or a CJK symbol/full-width form: characters that are typeset without spaces and counted one per "word" in CJK runtime estimates.
func IsHeading ¶
IsHeading reports whether line is a chapter heading: "#" alone or "#" followed by a space. "##" and deeper are body text.
func IsUnspaced ¶
IsUnspaced reports whether r belongs to a script written without spaces between words (Han, kana, Thai, Lao, Khmer, Myanmar, Tibetan), where a term may match anywhere instead of only at word boundaries. Hangul is spaced and is not included.
func IsWordRune ¶
IsWordRune reports whether r is part of a word: a letter, a digit or a combining mark.
func Key ¶
Key is the content address of a synthesised chunk: a hex SHA-256 of the normalised text and every parameter that changes the audio (model, revision, voice, language, seed, speed, steps…). Params are hashed in key order, so map iteration order does not matter; format numbers the same way every time (strconv.FormatFloat(v, 'g', -1, 64)).
func NormalizeForKey ¶
NormalizeForKey is the text identity used by Key: Unicode NFC, runs of white space collapsed to one space, trimmed. Case and punctuation are kept because they change how a sentence is spoken.
func Outside ¶
Outside calls fn for each maximal piece of s outside bracket tags, in order, and returns the concatenation of fn's results with the tags kept verbatim. It is how normalisation and the lexicon skip "[…]" spans.
func SplitOverride ¶
SplitOverride splits an inline pronunciation override "[[word|say]]" into its parts (trimmed). ok is false when tag is not of that form.
Types ¶
type Chunk ¶
type Chunk struct {
Span
Text string
Paragraph int // index of the paragraph the chunk starts in
Heading bool // a "# Title" line
Cut Cut
}
Chunk is one piece of a script, with its source offsets for highlighting and caching. Text is src[Start:End]: trimmed, otherwise verbatim (it may still contain line breaks and tags).
type Diagnostic ¶
Diagnostic is one finding about a script, for validation UIs. Code is a stable identifier ("markup.unknown_tag"); Params carry the values a translated message needs ({"tag": "[foo]"}). Span points into the source.
type Mode ¶
type Mode uint8
Mode chooses what one chunk holds.
const ( // Pack packs whole sentences into chunks of at most MaxChars: the TTS // default, few chunks with natural boundaries. Pack Mode = iota // Sentences makes one chunk per sentence (Stories "split by sentences"). Sentences // Paragraphs makes one chunk per paragraph. Paragraphs // Chapters makes one chunk per chapter body; "# Title" headings are // chunks of their own in every mode. Chapters )
type Options ¶
type Options struct {
Mode Mode
// MaxChars caps a chunk's length in runes: 0 means DefaultMaxChars, a
// negative value means no cap. Oversized sentences are cut at a clause
// mark, then a line break, then a space, then anywhere outside a tag.
MaxChars int
// CrossParagraphs lets Pack fill a chunk across blank lines. Headings
// still break chunks.
CrossParagraphs bool
}
Options configure Chunks.
type Span ¶
type Span struct {
Start, End int
}
Span is a half-open byte range [Start, End) into a source string.
func SentenceSpans ¶
SentenceSpans returns the sentences of src, trimmed, in order.
func Tags ¶
Tags returns the bracketed spans of s in order: "[tag]" and "[[override]]". A tag never crosses a line break; an unmatched "[" is plain text. When a "[" appears before the closing "]", the scan restarts there, so in "[a [b]" only "[b]" is a tag.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package autocast detects who speaks each line of a story, for the Stories editor's Auto-cast: tagged lines ("[Mara] Hello"), screenplay lines ("MARA: Hello", "小明:你好") and quoted prose attributed with a speech verb (`"Hello," said Mara.`, `小明说:“你好。
|
Package autocast detects who speaks each line of a story, for the Stories editor's Auto-cast: tagged lines ("[Mara] Hello"), screenplay lines ("MARA: Hello", "小明:你好") and quoted prose attributed with a speech verb (`"Hello," said Mara.`, `小明说:“你好。 |
|
Package lexicon is the pronunciation dictionary: user entries that say how a term is pronounced, applied to script text before synthesis.
|
Package lexicon is the pronunciation dictionary: user entries that say how a term is pronounced, applied to script text before synthesis. |
|
Package markup parses AudioSmith's SSML-lite script markup into a typed token stream with diagnostics, for the Studio, Stories and Audiobook editors and their validation UIs.
|
Package markup parses AudioSmith's SSML-lite script markup into a typed token stream with diagnostics, for the Studio, Stories and Audiobook editors and their validation UIs. |
|
Package normalize rewrites written forms a TTS model may misread into spoken words, conservatively and per language: numbers (with grouping and decimals), negative numbers, percentages, ordinals, times ("3:30"), simple dates, currency ("$5", "¥5", "5 €"), number ranges ("3–5", "3~5"), temperatures and common abbreviations ("Dr.", "z.
|
Package normalize rewrites written forms a TTS model may misread into spoken words, conservatively and per language: numbers (with grouping and decimals), negative numbers, percentages, ordinals, times ("3:30"), simple dates, currency ("$5", "¥5", "5 €"), number ranges ("3–5", "3~5"), temperatures and common abbreviations ("Dr.", "z. |
|
Package plan turns a script into what a TTS engine is asked to say: the markup parsed (internal/text/markup) and lowered for one engine, the pronunciation dictionary and inline overrides applied, written forms normalised, and the result cut into chunks the engine can take, with the silences and joins between them.
|
Package plan turns a script into what a TTS engine is asked to say: the markup parsed (internal/text/markup) and lowered for one engine, the pronunciation dictionary and inline overrides applied, written forms normalised, and the result cut into chunks the engine can take, with the silences and joins between them. |