Skip to main content
Commands for generating narration audio with word-level timing.

synthesize

Synthesizes narration text to audio with word-level timing events.
text
string
required
Plain text to synthesize
bundle_path
string | null
Path to TTS bundle directory for caching. If provided and a cache hit occurs, returns cached audio immediately.
on_event
Channel<TTSEvent>
required
Event channel for streaming word boundaries and audio data
result
void
required
Emits events via channel:
  • WordBoundary: Fired for each word
  • AudioReady: Fired once when synthesis completes

TTSEvent

Discriminated union:
import { Channel } from '@tauri-apps/api/core';

const channel = new Channel<TTSEvent>();
channel.onmessage = (event) => {
  if (event.event === 'wordBoundary') {
    console.log(`Word: ${event.data.word} at ${event.data.startMs}ms`);
  } else if (event.event === 'audioReady') {
    const audio = new Audio(`data:audio/wav;base64,${event.data.audioBase64}`);
    audio.play();
  }
};

await invoke('synthesize', {
  text: 'Hello, world!',
  bundlePath: '/path/to/bundle',
  onEvent: channel
});

export_audio

Pre-generates and caches audio for multiple text blocks.
texts
string[]
required
Array of text blocks to synthesize
bundle_dir
string
required
Path to bundle directory for writing cache
exported
number
required
Number of newly generated audio files (cache misses)
const exported = await invoke<number>('export_audio', {
  texts: ['Intro text', 'Section 1', 'Section 2'],
  bundleDir: '/course/tts-bundle'
});

console.log(`Generated ${exported} new audio files`);

ensure_tts_ready

Ensures TTS models are downloaded and ready. Performs a warmup synthesis if models need initialization.
status
string
required
One of:
  • 'ready': Models already present
  • 'downloaded': Models downloaded and initialized
const status = await invoke<string>('ensure_tts_ready');
if (status === 'downloaded') {
  console.log('TTS models initialized');
}
This command is called automatically by the app on startup. You typically don’t need to invoke it manually.

Build docs developers (and LLMs) love