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-pollypnpm add voiceai-sdk @aws-sdk/client-transcribe-streaming @aws-sdk/client-pollyyarn add voiceai-sdk @aws-sdk/client-transcribe-streaming @aws-sdk/client-pollybun add voiceai-sdk @aws-sdk/client-transcribe-streaming @aws-sdk/client-pollyUse any credentials the AWS SDK finds: environment variables, a shared profile, or an IAM role. Set AWS_REGION.
Quickstart
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
| Feature | Support | Notes |
|---|---|---|
Speech-to-text (transcribe) | Yes | transcribe streams the file through Transcribe streaming |
Streaming transcripts (listen) | Yes | |
Text-to-speech (speak) | Yes | |
| Streaming speech | Yes | |
| Speech-to-speech | No | |
| Word timings | Yes | Polly speech marks for speech; item times for transcripts |
| Speaker labels | Yes | Set showSpeakerLabel: true |
| Interruptions | Yes | |
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.
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.
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.
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.
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.
| Option | Type | Default | Env var |
|---|---|---|---|
region | string | AWS_REGION | |
voice | string | "Joanna" | |
engine | string | "neural" | |
showSpeakerLabel | boolean | false | |
credentials | AWS credentials | Default provider chain |
Call the API directly
session.native holds the two AWS clients.
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()andresume()fail withunsupported.- Batch transcription jobs (S3 input) are not used.
transcribestreams the audio, so very long files take as long as they play.
How it works
listenopens oneStartStreamTranscriptioncall and maps partial results topartialevents.speakcallsSynthesizeSpeechand streams the response body as chunks.
Next steps
- Lifecycle and cleanup
- Give your agent a voice
- Compare providers: the same features on every other provider