SpeakTextTool

class SpeakTextTool(context: Context) : McpTool

Speaks text aloud through the device TextToSpeech engine, suspending until playback completes. No permissions required.

Initializes a one-shot engine (init bounded by TTS_INIT_TIMEOUT_MS), applies pitch/speed (each clamped to 0.5–2.0) and language (falls back to English if the requested BCP-47 tag is unsupported or missing data), then speaks. Text longer than TextToSpeech.getMaxSpeechInputLength is split into chunks (at whitespace where possible) and queued with QUEUE_ADD after an initial QUEUE_FLUSH; the call completes when the last chunk finishes. Playback is bounded by a timeout that scales with text length and speed (roughly twice the estimated speaking time plus slack, capped at MAX_PLAYBACK_TIMEOUT_MS). The engine is shut down on every path — completion, error, timeout, and coroutine cancellation (which therefore also stops playback).

Output map (on completion): success (true), text_length (Int), language (the requested tag, not necessarily the one actually used after fallback), chunk_count (Int).

Constructors

Link copied to clipboard
constructor(context: Context)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val annotations: ToolAnnotations
Link copied to clipboard
open override val description: String
Link copied to clipboard
open override val name: String
Link copied to clipboard
open override val outputSchema: Map<String, Any>
Link copied to clipboard
open override val parameters: List<ToolParameter>

Functions

Link copied to clipboard
open suspend override fun execute(params: Map<String, Any>): ToolResult