QVAC Logo

textToSpeech( )

Converts text to speech audio using a loaded TTS model. Supports both streaming and buffered modes.

function textToSpeech(params: { inputType: string; modelId: string; stream: boolean; text: string }, options?: { forceNewConnection?: boolean; profiling?: { enabled?: boolean; includeServerBreakdown?: boolean; mode?: "summary" | "verbose" }; timeout?: number }): { buffer: Promise<number[]>; bufferStream: AsyncGenerator<number>; done: Promise<boolean> }

Parameters

NameTypeRequired?Description
params\{ inputType: string; modelId: string; stream: boolean; text: string \}TTS synthesis parameters
options`{ forceNewConnection?: boolean; profiling?: { enabled?: boolean; includeServerBreakdown?: boolean; mode?: "summary""verbose" }; timeout?: number }`
FieldTypeRequired?Description
inputTypestringThe type of input content, typically "text"
modelIdstringThe ID of the loaded TTS model to use for synthesis
streambooleanWhen true, audio bytes are emitted incrementally via bufferStream. When false, the full audio is returned via buffer
textstringThe text content to synthesize into speech

Returns

{ buffer: Promise<number[]>; bufferStream: AsyncGenerator<number>; done: Promise<boolean> }
FieldTypeDescription
bufferPromiseResolves with the complete audio buffer as a byte array when stream is false. Resolves to an empty array in streaming mode
bufferStreamAsyncGeneratorYields audio bytes incrementally in streaming mode. Empty generator when stream is false
donePromiseResolves to true when synthesis is complete

Example

import { textToSpeech } from "@qvac/sdk";

// Streaming mode — process audio chunks as they arrive
const { bufferStream, done } = textToSpeech({
  modelId: "my-tts-model",
  text: "Hello, welcome to QVAC!",
  inputType: "text",
  stream: true,
});

const audioChunks = [];
for await (const byte of bufferStream) {
  audioChunks.push(byte);
}
await done;

// Buffered mode — wait for the full audio
const { buffer } = textToSpeech({
  modelId: "my-tts-model",
  text: "Hello, welcome to QVAC!",
  inputType: "text",
  stream: false,
});

const audioBytes = await buffer;
console.log("Audio size:", audioBytes.length, "bytes");

On this page