tools.pollinations_tts module
Text-to-speech via Pollinations.ai API, uploaded to the current channel.
- async tools.pollinations_tts.run(text, voice='nova', output_format='mp3', speed=None, ctx=None)[source]
Synthesize speech via the Pollinations audio API and upload it.
Implements the
pollinations_ttstool. It turns text into an audio file by calling the Pollinations.ai audio endpoint, stages the bytes locally, and uploads the result to the channel the tool was invoked in, returning a confirmation (with the file URL when available) for the model to reference.The flow validates the context and text length, resolves the caller’s Pollinations API key through
tools.pollinate._resolve_api_key(returningtools.manage_api_keys.missing_api_key_errorwhen absent), then normalizes the voice and format via_normalize_voice()and_normalize_format(). It issues a GET toPOLLINATIONS_AUDIO_BASEwith the URL-encoded text andvoice/format/optionalspeedquery params using the SSRF-guardedtools._safe_httpclient, stages the returned bytes off-loop through_write_temp_read_unlink(), and uploads them viactx.adapter.send_filetoctx.channel_id, also appending a record toctx.sent_filesso downstream code can reference the upload. It is registered and dispatched dynamically bytool_loader.pyas the module-levelrunhandler; no in-repo callers invoke it directly outside of tests.- Parameters:
text (
str) – The text to synthesize; required, trimmed, and capped at 4096 characters.voice (
str) – Voice preset name; normalized and defaulted to"nova".output_format (
str) – Audio container; normalized and defaulted to"mp3".speed (
float|None) – Optional speech speed, applied only when within0.25-4.0.ctx (
ToolContext|None) – The tool execution context. Must expose a non-Noneadapter;ctx.channel_idandctx.sent_filesare used for the upload.
- Returns:
A success message (optionally including the uploaded file URL), or an
Error:prefixed string when the adapter or key is missing, the text is empty or too long, the API returns a non-200 or empty response, or any exception occurs.- Return type: