Skip to content

Text-to-speech and speech-to-text

These two one-shot calls turn text into audio and audio into text, and Alfe meters both against your credits. See voice billing for how, and live pricing for rates.

They live under /voice/ rather than /agent/, and take the same agent API key. All examples use the @alfe.ai/agent-api-client.

voice.ts
const { audio, sampleRate, channels, bitDepth } = await client.tts({
text: "Your report is ready.", // 1 to 5,000 characters
voiceId, // optional, from listVoices()
});
// POST /voice/tts

audio is a Buffer of raw little-endian PCM samples with no container. The default framing is 24 kHz, mono, 16-bit. Wrap it in a WAV container to get a playable file.

To pick a voice, call listVoices().

const { text, confidence } = await client.stt({
audio: pcmBytes, // a Uint8Array of raw PCM, up to 10 MiB
sampleRate: 16000, // 8000 to 48000
});
// POST /voice/stt