Access the Typecast API with our official Javascript/Typescript SDK.
The official Node.js library for the Typecast API. Convert text to lifelike speech using AI-powered voices.Works with both Javascript and TypeScript. Full TypeScript types included.ESM & CommonJS supported. Works in Node.js 18+ and modern browsers. Node.js 16/17 users need to install isomorphic-fetch polyfill.
Make sure you have version 0.1.5 or higher installed. You can check your version with npm list @neosapience/typecast-js. If you have an older version, run npm update @neosapience/typecast-js to update.
ssfm-v30 offers two emotion control modes: Preset and Smart.
Smart Mode
Preset Mode
Let the AI infer emotion from context:
import { SmartPrompt } from '@neosapience/typecast-js';const audio = await client.textToSpeech({ text: "Everything is going to be okay.", voice_id: "tc_672c5f5ce59fac2a48faeaee", model: "ssfm-v30", prompt: { emotion_type: "smart", previous_text: "I just got the best news!", // Optional context next_text: "I can't wait to celebrate!" // Optional context } as SmartPrompt});
Explicitly set emotion with preset values:
import { PresetPrompt } from '@neosapience/typecast-js';const audio = await client.textToSpeech({ text: "I am so excited to show you these features!", voice_id: "tc_672c5f5ce59fac2a48faeaee", model: "ssfm-v30", prompt: { emotion_type: "preset", emotion_preset: "happy", // normal, happy, sad, angry, whisper, toneup, tonedown emotion_intensity: 1.5 // Range: 0.0 to 2.0 } as PresetPrompt});
Stream audio chunks in real-time for low-latency playback:
// Node 18+ (built-in fetch). Pipe stream to ffplay for real-time playback.// Prerequisite: ffmpeg (brew/choco/apt install ffmpeg)import { spawn } from "node:child_process";import { TypecastClient } from '@neosapience/typecast-js';const client = new TypecastClient({ apiKey: 'YOUR_API_KEY' });const ffplay = spawn( "ffplay", ["-autoexit", "-nodisp", "-loglevel", "error", "-i", "pipe:0"], { stdio: ["pipe", "ignore", "ignore"] },);const stream = await client.textToSpeechStream({ text: "Stream this text as audio in real time.", model: "ssfm-v30", voice_id: "tc_672c5f5ce59fac2a48faeaee", output: { audio_format: "wav" }});// ReadableStream — read chunks as they arriveconst reader = stream.getReader();while (true) { const { value, done } = await reader.read(); if (done) break; ffplay.stdin.write(value);}ffplay.stdin.end();await new Promise((resolve) => ffplay.on("close", resolve));
WAV streaming format: 32000 Hz, 16-bit, mono PCM. The first chunk includes a 44-byte WAV header (size = 0xFFFFFFFF); subsequent chunks are raw PCM only. For MP3: 320 kbps, 44100 Hz, each chunk is independently decodable. The streaming endpoint does not support volume or target_lufs.