Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Treatment synthesize

ml/remote/tts::synthesize


Configuration

⬡ tts: ml/remote/tts::RemoteTts

Inputs

⇥ text: Stream<string>

Outputs

↦ audio: Stream<byte>
↦ error: Stream<string>
↦ failed: Stream<void>


Synthesize speech audio from text using a remote text-to-speech service.

For each string received on text, sends a synthesis request to the configured provider and emits the resulting audio bytes on audio (MP3 format for ElevenLabs). If the request fails, failed and error are emitted instead.

graph LR
     T("synthesize()")
     X["🟩 🟩 …"] -->|text| T
     T -->|audio| A["🟩 🟩 🟩 🟩 …"]
     T -->|failed| F["🟩 🟩 …"]
     T -->|error| E["🟩 🟩 …"]

     style X fill:#ffffff,stroke:#ffffff
     style A fill:#ffffff,stroke:#ffffff
     style F fill:#ffffff,stroke:#ffffff
     style E fill:#ffffff,stroke:#ffffff
use ml/remote/tts::RemoteTts
use ml/remote/tts::synthesize

treatment example()
  model tts: RemoteTts(
    backend = "elevenlabs",
    api_key = "...",
    voice   = "JBFqnCBsd6RMkjVDRZzb"
  )
  input  text:  Stream<string>
  output audio: Stream<byte>
{
    synthesize[tts=tts]()
    Self.text -> synthesize.text,audio -> Self.audio
}