voice-sdk

Examples

Runnable programs covering synthesis, transcription, realtime sessions, and provider switching.

The repository contains six single-purpose programs in examples/basics. Each one is a single file that you can copy into your own project. They are typechecked in CI, so they stay in sync with the API.

Running them

Install dependencies at the repository root, then run an example with tsx:

pnpm install
cd examples/basics
DEEPGRAM_API_KEY=… pnpm tsx src/speak-to-file.ts

Each example calls a real API and uses your quota.

What each one shows

FileDescriptionEnvironment
speak-to-file.tsspeak() written to a WAV fileDEEPGRAM_API_KEY
speak-stream.tsspeakStream() written as chunks arriveDEEPGRAM_API_KEY
transcribe.tstranscribe() with word timestamps and diarizationDEEPGRAM_API_KEY
realtime-stt.tsA realtime session fed at playback speed, printing turnsDEEPGRAM_API_KEY
realtime-tts.tsA realtime session driven by incremental textDEEPGRAM_API_KEY
swap-providers.tsThe same calls running on any of the three providersPROVIDER, plus that provider's key and voice

Order

Run speak-to-file.ts before transcribe.ts. The second reads the WAV file the first writes. Output is written to examples/basics/out/, which is gitignored.

realtime-stt.ts has no microphone available, so it synthesizes audio and then pushes it back into the session frame by frame at playback speed. Replace that loop with your capture device to use it in an application.

Playing raw audio

Streaming endpoints return headerless PCM. Pass the format explicitly to your player:

ffplay -f s16le -ar 24000 -ch_layout mono out/stream.raw

On this page