We're starting a new chapter on text-to-speech, and we're going to turn text into audio.
Text-to-speech runs the Supertonic engine on the supplied text and hands us back raw audio samples. The result is an Int16Array (one sample per array slot), 44100 Hz by default. We write it to disk as a WAV with a 44-byte header prepended.
Supertonic needs three knobs at first load: ttsEngine (backend), language, voice (F1/F2/M1/M2). All three are required. The first load with them set would look like the following:
const modelId = await loadModel({
modelSrc: TTS_MULTILINGUAL_SUPERTONIC3_Q8_0,
modelConfig: {
ttsEngine: "supertonic",
language: "en",
voice: "F1",
},
});textToSpeech() is fire-and-await. Returns a 44.1 kHz mono Int16Array, the unit a WAV writer expects as follows:
const result = textToSpeech({
modelId,
text: "Hello, world.",
inputType: "text",
stream: false,
});
const audioBuffer = await result.buffer;
console.log(`▸ TTS complete. Total samples: ${audioBuffer.length}`);To save it as a .wav file, we prepend a 44-byte header (see the supertonic example's createWav helper). The samples themselves are Int16Array values at the engine's sample rate.
Note: the
ttsSpeedandttsNumInferenceStepsfields inmodelConfigtrade latency against quality.ttsSpeed: 1.05andttsNumInferenceSteps: 5are the defaults in the SDK and a good starting point.
loadModel with modelConfig.ttsEngine: "supertonic", a language, and a voice.textToSpeech({ modelId, text, inputType: "text", stream: false }) and await result.buffer.$ Run your code to see results
$