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_tts tool. 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 (returning tools.manage_api_keys.missing_api_key_error when absent), then normalizes the voice and format via _normalize_voice() and _normalize_format(). It issues a GET to POLLINATIONS_AUDIO_BASE with the URL-encoded text and voice/format/optional speed query params using the SSRF-guarded tools._safe_http client, stages the returned bytes off-loop through _write_temp_read_unlink(), and uploads them via ctx.adapter.send_file to ctx.channel_id, also appending a record to ctx.sent_files so downstream code can reference the upload. It is registered and dispatched dynamically by tool_loader.py as the module-level run handler; 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 within 0.25-4.0.

  • ctx (ToolContext | None) – The tool execution context. Must expose a non-None adapter; ctx.channel_id and ctx.sent_files are 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:

str