SpeechBuilder

Kotlin DSL builder for constructing structured speech with automatic SSML generation.

This builder provides a type-safe, readable way to compose complex speech sequences including pauses, prosody changes, emphasis, spell-out, and structured say-as interpretations.

Basic usage

tts.speak {
text("Bonjour.")
pause(400)
slow { text("Ceci est important.") }
}

Rich example

tts.speak {
paragraph {
sentence { text("Bienvenue sur notre application.") }
sentence {
text("Votre code est ")
spellOut("AB12")
text(".")
}
}
pause(600)
withPreset(SpeechPreset.CALM) {
text("Merci et à bientôt.")
}
}

See also

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun date(content: String, format: String = "dmy")

Reads content as a date.

Link copied to clipboard
fun emphasis(level: String = "moderate", block: SpeechBuilder.() -> Unit)

Wraps content in an SSML <emphasis> tag.

Link copied to clipboard
fun fast(block: SpeechBuilder.() -> Unit)

Wraps content with rate="fast".

Link copied to clipboard
fun highPitch(block: SpeechBuilder.() -> Unit)

Wraps content with pitch="+3st" (higher).

Link copied to clipboard
fun loud(block: SpeechBuilder.() -> Unit)

Wraps content with volume="loud".

Link copied to clipboard
fun lowPitch(block: SpeechBuilder.() -> Unit)

Wraps content with pitch="-3st" (lower).

Link copied to clipboard
fun number(content: String)

Reads content as a cardinal number (e.g. "1500" → "mille cinq cents").

Link copied to clipboard
fun ordinal(content: String)

Reads content as an ordinal number (e.g. "3" → "troisième").

Link copied to clipboard
fun paragraph(block: SpeechBuilder.() -> Unit)

Wraps content in an SSML <p> (paragraph) tag.

Link copied to clipboard
fun pause(timeMs: Int)

Inserts a silence pause.

Link copied to clipboard
fun phoneme(content: String, ipa: String)

Provides exact phonetic pronunciation using the International Phonetic Alphabet (IPA).

Link copied to clipboard
fun pitch(semitones: Int, block: SpeechBuilder.() -> Unit)

Sets pitch in semitones relative to default.

Link copied to clipboard
fun prosody(rate: String? = null, pitch: String? = null, volume: String? = null, block: SpeechBuilder.() -> Unit)

Wraps content in an SSML <prosody> tag with optional rate, pitch, and volume.

Link copied to clipboard
fun rate(percent: Int, block: SpeechBuilder.() -> Unit)

Sets rate as a percentage of normal speed.

Link copied to clipboard
fun reduced(block: SpeechBuilder.() -> Unit)

Shortcut for emphasis(level = "reduced").

Link copied to clipboard
fun sayAs(interpretAs: String, content: String)

Generates an SSML <say-as> element with a custom interpretation type.

Link copied to clipboard
fun sentence(block: SpeechBuilder.() -> Unit)

Wraps content in an SSML <s> (sentence) tag.

Link copied to clipboard
fun slow(block: SpeechBuilder.() -> Unit)

Wraps content with rate="slow".

Link copied to clipboard
fun soft(block: SpeechBuilder.() -> Unit)

Wraps content with volume="soft".

Link copied to clipboard
fun spellOut(content: String, pauseMs: Int = 150)

Spells out content character by character with French pronunciation.

Link copied to clipboard
fun strong(block: SpeechBuilder.() -> Unit)

Shortcut for emphasis(level = "strong").

Link copied to clipboard
fun sub(content: String, alias: String)

Substitutes content with alias for pronunciation.

Link copied to clipboard
fun telephone(content: String)

Reads content as a telephone number with appropriate digit grouping.

Link copied to clipboard
fun text(content: String)

Adds plain text to the speech output.

Link copied to clipboard
fun withPreset(preset: SpeechPreset, block: SpeechBuilder.() -> Unit)

Applies a SpeechPreset's prosody (rate, pitch, volume) to the enclosed content.

Link copied to clipboard
fun xFast(block: SpeechBuilder.() -> Unit)

Wraps content with rate="x-fast".

Link copied to clipboard
fun xLoud(block: SpeechBuilder.() -> Unit)

Wraps content with volume="x-loud".

Link copied to clipboard
fun xSlow(block: SpeechBuilder.() -> Unit)

Wraps content with rate="x-slow".

Link copied to clipboard
fun xSoft(block: SpeechBuilder.() -> Unit)

Wraps content with volume="x-soft".