On this page

AWS

Use Amazon Transcribe and Amazon Polly with aws(): streaming transcripts, speaker labels, and Polly voices, with your AWS credentials.

aws() wraps @aws-sdk/client-transcribe-streaming for speech-to-text and @aws-sdk/client-polly for text-to-speech. Credentials come from the default AWS provider chain.

Install

npm install voiceai-sdk @aws-sdk/client-transcribe-streaming @aws-sdk/client-polly

Use any credentials the AWS SDK finds: environment variables, a shared profile, or an IAM role. Set AWS_REGION.

Quickstart

TypeScript
import { createSession } from "voiceai-sdk";
import { aws } from "voiceai-sdk/aws";

await using session = await createSession(aws());
const result = await session.transcribe(await Bun.file("meeting.wav").bytes());
console.log(result.ok, result.text);

This prints true and the transcript. If the file has no speech, ok is false and reason is "no_speech". await using closes the session when the block ends.

What it supports

FeatureSupportNotes
Speech-to-text (transcribe)Yestranscribe streams the file through Transcribe streaming
Streaming transcripts (listen)Yes
Text-to-speech (speak)Yes
Streaming speechYes
Speech-to-speechNo
Word timingsYesPolly speech marks for speech; item times for transcripts
Speaker labelsYesSet showSpeakerLabel: true
InterruptionsYes
Voice list (listVoices)Yes
pause() and resume()No

The capability matrix compares these with every other provider.

Stream transcripts

Iterate session.listen to get partial transcripts while someone speaks and a final one when they stop.

TypeScript
import { createSession } from "voiceai-sdk";
import { aws } from "voiceai-sdk/aws";

await using session = await createSession(aws(), { language: "en", sampleRate: 16000 });

for await (const t of session.listen(microphone())) {
  if (t.type === "final") console.log(`[${t.startMs}ms] ${t.text}`);
}

microphone() stands for any AsyncIterable<Uint8Array> of 16-bit PCM, such as a transport or a file stream.

Speak

Iterate session.speak to send audio as it is produced. Pass an async iterable of text, such as a model's output, and speech starts before the text is finished.

TypeScript
import { createSession } from "voiceai-sdk";
import { aws } from "voiceai-sdk/aws";

await using session = await createSession(aws());

for await (const chunk of session.speak("Let me check that for you.")) {
  player.write(chunk.data);
}

Voices

listVoices returns the voices you can pass as voice. The default is Joanna.

TypeScript
import { listVoices } from "voiceai-sdk";
import { aws } from "voiceai-sdk/aws";

const voices = await listVoices(aws());
console.log(voices.filter((v) => v.language.startsWith("en")).map((v) => v.id));

Hold a conversation

converse calls your handler for each final transcript and speaks what it returns. Return an async iterable to start speaking before the reply is complete.

TypeScript
import { createSession } from "voiceai-sdk";
import { aws } from "voiceai-sdk/aws";

await using session = await createSession(aws());
session.connect(transport);
await session.converse(async (text, { signal }) => model.stream(text, { signal }));

Configuration

Pass options to aws(). Options that have an environment variable fall back to it.

OptionTypeDefaultEnv var
regionstringAWS_REGION
voicestring"Joanna"
enginestring"neural"
showSpeakerLabelbooleanfalse
credentialsAWS credentialsDefault provider chain

Call the API directly

session.native holds the two AWS clients.

TypeScript
import { createSession } from "voiceai-sdk";
import { aws } from "voiceai-sdk/aws";
import { DescribeVoicesCommand } from "@aws-sdk/client-polly";

await using session = await createSession(aws());
const { Voices } = await session.native.polly.send(new DescribeVoicesCommand({ Engine: "neural" }));

Limitations

  • pause() and resume() fail with unsupported.
  • Batch transcription jobs (S3 input) are not used. transcribe streams the audio, so very long files take as long as they play.

How it works

  • listen opens one StartStreamTranscription call and maps partial results to partial events.
  • speak calls SynthesizeSpeech and streams the response body as chunks.

Next steps

Was this page helpful?

Esc

Loading…

↑↓ navigate openCtrl J preview