Skip to content

AzureTTS

Convert text to speech using Microsoft Azure's neural voices via the Speech service REST API.

Use AzureTTS when you want Microsoft Azure’s catalog of hundreds of neural voices across 140+ locales via a simple REST call. Each synthesize() request POSTs an SSML document to your regional Speech endpoint and returns the complete audio as a Blob — no WebSocket management required. Speaking styles (cheerful, newscast, …) and rate/pitch controls are exposed as config options.

Prerequisites

  • An Azure Speech resource (key + region) or a CompositeVoice proxy server
  • No additional dependencies required. AzureTTS uses native fetch internally.

Basic setup

import { CompositeVoice, NativeSTT, AnthropicLLM, AzureTTS, BrowserAudioOutput } from 'composite-voice';

const voice = new CompositeVoice({
  providers: [
    new NativeSTT(),
    new AnthropicLLM({
      proxyUrl: '/api/proxy/anthropic',
      model: 'claude-haiku-4-5',
    }),
    new AzureTTS({
      proxyUrl: '/api/proxy/azure-tts',
      voiceName: 'en-US-AriaNeural',
      outputFormat: 'audio-24khz-48kbitrate-mono-mp3',
    }),
    new BrowserAudioOutput(),
  ],
});

await voice.initialize();
await voice.startListening();

Configuration options

OptionTypeDefaultDescription
apiKeystring | () => Promise<string>Speech resource key, or an async factory returning a 10-minute bearer token
proxyUrlstringProxy server URL (recommended for production)
regionstringAzure region, e.g. eastus (required in direct mode)
voiceNamestringrequiredNeural voice, e.g. en-US-AriaNeural
outputFormatstring'audio-24khz-48kbitrate-mono-mp3'X-Microsoft-OutputFormat value (mp3, wav, ogg, webm, raw pcm)
languagestringderived from voiceNameSSML xml:lang locale (e.g. en-US)
stylestringSpeaking style via <mstts:express-as> (e.g. cheerful)
styleDegreenumber1Style intensity, 0.01–2
ratenumberSpeech rate multiplier via <prosody> (1.25 → +25.00%)
pitchnumberPitch shift in semitones via <prosody> (−2 → -2st)
userAgentstringUser-Agent header value (server-side runtimes only)
endpointstringCustom API endpoint URL (overrides region)
maxRetriesnumber3Retry count for failed requests

Available voices

List voices with GET https://<region>.tts.speech.microsoft.com/cognitiveservices/voices/list (send your key as Ocp-Apim-Subscription-Key), or browse the voice gallery. Voice names look like en-US-AriaNeural, en-GB-SoniaNeural, or de-DE-KatjaNeural. Some voices support speaking styles — check the voice’s StyleList.

Output formats

Format familyExampleUse case
audio-*-mp3audio-24khz-48kbitrate-mono-mp3Good compression, wide browser support (default)
riff-*-pcmriff-24khz-16bit-mono-pcmUncompressed WAV, highest quality
ogg-*-opusogg-24khz-16bit-mono-opusGood compression, open format
webm-*-opuswebm-24khz-16bit-mono-opusMediaSource-friendly streaming container
raw-*-pcmraw-24khz-16bit-mono-pcmHeaderless PCM for custom audio pipelines

Complete example

import { CompositeVoice, MicrophoneInput, DeepgramSTT, AnthropicLLM, AzureTTS, BrowserAudioOutput } from 'composite-voice';

const tts = new AzureTTS({
  proxyUrl: '/api/proxy/azure-tts',
  voiceName: 'en-US-AriaNeural',
  style: 'cheerful',
  rate: 1.1,
});

const voice = new CompositeVoice({
  providers: [
    new MicrophoneInput(),
    new DeepgramSTT({ proxyUrl: '/api/proxy/deepgram' }),
    new AnthropicLLM({
      proxyUrl: '/api/proxy/anthropic',
      model: 'claude-haiku-4-5',
    }),
    tts,
    new BrowserAudioOutput(),
  ],
});

voice.on('tts.start', () => console.log('Speaking...'));
voice.on('tts.end', () => console.log('Done speaking'));

await voice.initialize();
await voice.startListening();

Authentication modes

  • Subscription key (direct): pass your Speech resource key as a string apiKey — it is sent as the Ocp-Apim-Subscription-Key header.
  • Bearer token (direct): pass an async apiKey factory that fetches a token from your server (which exchanges the key at POST https://<region>.api.cognitive.microsoft.com/sts/v1.0/issueToken). Tokens are valid for 10 minutes and are sent as Authorization: Bearer; the factory is called on every request so refreshed tokens are picked up automatically.
  • Proxy (recommended): pass proxyUrl and configure azureSpeechApiKey + azureSpeechRegion in your proxy — the key never reaches the browser.

Tips

  • User text is XML-escaped automatically before being embedded in the SSML <speak> document, so &, <, and quotes in LLM output are safe.
  • AzureTTS is REST-based, not streaming. The full audio Blob is returned after the API processes the entire input. For real-time streaming, consider DeepgramTTS.
  • Synthesis is capped at 10 minutes of audio per request by the service.
  • If you select a 48 kHz output format, the high-fidelity 48 kHz voice model is invoked automatically.

Further reading

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency