Skip to content

dTelecom/stt-client-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@dtelecom/stt

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.

Install

npm install @dtelecom/stt

Quick Start

import { 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();
}

Real-Time Streaming

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();

Auto-Extend Sessions

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();

Audio Format

The server expects PCM16, 16kHz, mono audio. Convert with ffmpeg:

ffmpeg -i input.mp3 -ar 16000 -ac 1 -acodec pcm_s16le output.wav

Pricing

const info = await client.pricing();
console.log(`$${info.pricePerMinuteUsd}/min (${info.currency} on ${info.network})`);

Current pricing: $0.005/min (USDC on Base or Solana).

API Reference

new STTClient({ privateKey, url? }) / STTClient.create({ privateKey, url? })

Main client. Default URL: https://x402stt.dtelecom.org.

  • EVM key (hex, 0x-prefixed): pays with USDC on Base — use new STTClient() or STTClient.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

SessionContext

Returned by client.session().

  • open() — Create the paid session and connect, returns a Stream

Stream

Returned by sessionContext.open().

  • sendAudio(data: Buffer) — Send raw PCM16 audio
  • transcriptions() — Async generator of Transcription objects
  • transcribeFile(path) — Stream a WAV file and yield transcriptions
  • onTranscription(callback) — Register callback for transcriptions
  • close() — Close the stream

Transcription

  • text: string — Transcribed text
  • start?: number — Start time in seconds
  • end?: number — End time in seconds
  • confidence?: number — Confidence score
  • isFinal: boolean — Whether this is a final transcription

Supported Languages

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.

Error Handling

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");
  }
}

License

MIT

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •