Text-to-Speech API
The Text-to-Speech (TTS) API allows scripts to generate spoken audio from text using NovelAI’s TTS. Scripts can queue text for speech, control playback, and manage the TTS system.
Basic Usage
Speaking Text
To have text spoken immediately, use the api.v1.tts.speak function:
await api.v1.tts.speak('Hello! This text will be spoken aloud.');
The function will interrupt any currently playing speech and immediately speak the new text.
Queuing Text
To add text to the speech queue without interrupting current playback, use the api.v1.tts.queue function:
// This will be spoken first
await api.v1.tts.speak('First sentence.');
// This will be queued and spoken after the first completes
await api.v1.tts.queue('Second sentence.');
await api.v1.tts.queue('Third sentence.');
Queued text will be spoken in the order it was added, after any currently playing speech completes.
Playback Control
Pausing and Resuming
Control playback with pause and resume functions:
// Pause playback
await api.v1.tts.pause();
// Resume playback
await api.v1.tts.resume();
Toggle Pause State
Toggle between paused and playing states:
// If playing, pause. If paused, resume.
await api.v1.tts.togglePause();
Stopping Playback
Stop all current and queued speech:
await api.v1.tts.stop();
This immediately stops playback and clears the speech queue.
See Also
- API Reference - Complete API documentation