Azure Speech
Use Azure AI Speech with azure(): continuous recognition, neural voices with word boundaries, and regional endpoints.
azure() wraps microsoft-cognitiveservices-speech-sdk. Each session holds one recognizer and one synthesizer, created in the region you configure.
Install
npm install voiceai-sdk microsoft-cognitiveservices-speech-sdkpnpm add voiceai-sdk microsoft-cognitiveservices-speech-sdkyarn add voiceai-sdk microsoft-cognitiveservices-speech-sdkbun add voiceai-sdk microsoft-cognitiveservices-speech-sdkSet AZURE_SPEECH_KEY and AZURE_SPEECH_REGION on your server, and keep them out of browser bundles.
Quickstart
import { createSession } from "voiceai-sdk";
import { azure } from "voiceai-sdk/azure";
await using session = await createSession(azure());
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 | |
Streaming transcripts (listen) | Yes | |
Text-to-speech (speak) | Yes | |
| Streaming speech | Yes | |
| Speech-to-speech | No | |
| Word timings | Yes | From word boundary events |
| Speaker labels | Yes | Uses conversation transcription; depends on the region |
| Interruptions | Yes | |
Voice list (listVoices) | Yes | |
pause() and resume() | Yes |
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 { azure } from "voiceai-sdk/azure";
await using session = await createSession(azure(), { 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 { azure } from "voiceai-sdk/azure";
await using session = await createSession(azure());
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 en-US-AvaMultilingualNeural.
import { listVoices } from "voiceai-sdk";
import { azure } from "voiceai-sdk/azure";
const voices = await listVoices(azure());
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 { azure } from "voiceai-sdk/azure";
await using session = await createSession(azure());
session.connect(transport);
await session.converse(async (text, { signal }) => model.stream(text, { signal }));Configuration
Pass options to azure(). Options that have an environment variable fall back to it.
| Option | Type | Default | Env var |
|---|---|---|---|
key | string | AZURE_SPEECH_KEY | |
region | string | AZURE_SPEECH_REGION | |
voice | string | "en-US-AvaMultilingualNeural" | |
endpoint | string | Regional default |
Call the API directly
session.native holds the recognizer and synthesizer.
import { createSession } from "voiceai-sdk";
import { azure } from "voiceai-sdk/azure";
await using session = await createSession(azure());
session.native.recognizer.properties.setProperty("SpeechServiceResponse_PostProcessingOption", "TrueText");Limitations
- Diarization is not available in every region. An unsupported region fails with
unsupported. - The factory option is
key, notapiKey, to match Azure's naming. The session optionkeyis unrelated.
How it works
listenruns continuous recognition.recognizingevents becomepartial,recognizedevents becomefinal.interrupt()stops the synthesizer and drops audio it has not sent yet.
Next steps
- Lifecycle and cleanup
- Give your agent a voice
- Compare providers: the same features on every other provider