TypeScript SDK for dTelecom real-time speech-to-text with x402 micropayments.
Pay-per-minute STT powered by Whisper and Parakeet, with automatic blockchain payments via USDC on Base or Solana.
npm install @dtelecom/sttimport { STTClient } from "@dtelecom/stt";
// EVM wallet (Base)
const client = new STTClient({ privateKey: "0x..." });
// Or Solana wallet — use async factory
// const client = await STTClient.create({ privateKey: "base58..." });
const stream = await client.session({ minutes: 5, language: "en" }).open();
try {
for await (const t of stream.transcribeFile("meeting.wav")) {
console.log(`[${t.start?.toFixed(1)}s] ${t.text}`);
}
} finally {
await stream.close();
}import { STTClient } from "@dtelecom/stt";
const client = new STTClient({ privateKey: "0x..." }); // or await STTClient.create({ privateKey: "base58..." })
const stream = await client.session({ minutes: 5, language: "en" }).open();
// Callback-based
stream.onTranscription((t) => console.log(t.text));
// Send audio chunks (PCM16, 16kHz, mono)
await stream.sendAudio(pcmBuffer);
// Or iterate asynchronously
for await (const t of stream.transcriptions()) {
console.log(t.text);
}
await stream.close();Sessions automatically buy more time when running low (enabled by default):
// 30-minute session that auto-extends
const stream = await client.session({ minutes: 30, language: "en" }).open();
// When <60s remaining, SDK buys 5 more minutes automatically
// Disable auto-extend
const stream = await client.session({ minutes: 5, autoExtend: false }).open();The server expects PCM16, 16kHz, mono audio. Convert with ffmpeg:
ffmpeg -i input.mp3 -ar 16000 -ac 1 -acodec pcm_s16le output.wavconst info = await client.pricing();
console.log(`$${info.pricePerMinuteUsd}/min (${info.currency} on ${info.network})`);Current pricing: $0.005/min (USDC on Base or Solana).
Main client. Default URL: https://x402stt.dtelecom.org.
-
EVM key (hex, 0x-prefixed): pays with USDC on Base — use
new STTClient()orSTTClient.create() -
Solana key (base58): pays with USDC on Solana — use
await STTClient.create() -
session({ minutes?, language?, autoExtend? })— Create a session context -
pricing()— Get pricing info -
health()— Check server health
Returned by client.session().
open()— Create the paid session and connect, returns aStream
Returned by sessionContext.open().
sendAudio(data: Buffer)— Send raw PCM16 audiotranscriptions()— Async generator ofTranscriptionobjectstranscribeFile(path)— Stream a WAV file and yield transcriptionsonTranscription(callback)— Register callback for transcriptionsclose()— Close the stream
text: string— Transcribed textstart?: number— Start time in secondsend?: number— End time in secondsconfidence?: number— Confidence scoreisFinal: boolean— Whether this is a final transcription
25 languages via Parakeet-TDT (fast) with Whisper fallback:
English, Russian, German, French, Spanish, Italian, Portuguese, Dutch, Polish, Czech, Romanian, Hungarian, Greek, Turkish, Ukrainian, Swedish, Norwegian, Danish, Finnish, Catalan, Croatian, Lithuanian, Slovenian, Latvian, Estonian.
import { PaymentError, SessionExpiredError, ConnectionError } from "@dtelecom/stt";
try {
const stream = await client.session({ minutes: 5 }).open();
for await (const t of stream.transcriptions()) {
console.log(t.text);
}
} catch (e) {
if (e instanceof PaymentError) {
console.log("Payment failed — check wallet balance");
} else if (e instanceof SessionExpiredError) {
console.log("Session time ran out");
} else if (e instanceof ConnectionError) {
console.log("Cannot connect to server");
}
}MIT