Skip to content

Azure Cognitive Services TTS

Uses Azure Cognitive Services Speech Service via the REST API. Supports hundreds of Neural TTS voices across 140+ locales.

Setup

ts
import { createApp } from 'vue'
import { VueSpeech } from 'vue-text-to-speech'

createApp(App)
  .use(VueSpeech, {
    provider: 'azure',
    subscriptionKey: import.meta.env.VITE_AZURE_KEY,
    region: 'eastus',
    voice: 'en-US-JennyNeural',
  })
  .mount('#app')

Never expose subscription keys

Use baseURL to proxy requests through your server. See the Security Guide.

Configuration

ts
interface AzureConfig {
  provider: 'azure'
  subscriptionKey: string
  region: string
  baseURL?: string   // proxy URL for production
  voice?: string     // Neural TTS voice name
}
OptionTypeDefaultDescription
subscriptionKeystringAzure Speech subscription key
regionstringAzure region, e.g. 'eastus'
baseURLstringAuto-built from regionOverride full endpoint URL
voicestring'en-US-JennyNeural'Neural TTS voice name

Default Endpoint

https://{region}.tts.speech.microsoft.com/cognitiveservices/v1

When baseURL is provided it replaces this URL entirely.

Output Format

The library requests audio-16khz-128kbitrate-mono-mp3 and plays it via an <audio> element blob URL.

LocaleVoiceCharacter
en-USen-US-JennyNeuralFriendly, conversational
en-USen-US-GuyNeuralMale, professional
en-GBen-GB-SoniaNeuralBritish female
es-MXes-MX-DaliaNeuralSpanish (Mexico)
fr-FRfr-FR-DeniseNeuralFrench female
de-DEde-DE-KatjaNeuralGerman female
ja-JPja-JP-NanamiNeuralJapanese female

Browse all voices at the Azure Neural Voice Gallery.

Server Proxy

ts
// Express — strips subscription key from browser
app.post('/tts/azure', async (req, res) => {
  const upstream = `https://eastus.tts.speech.microsoft.com/cognitiveservices/v1`
  const azure = await fetch(upstream, {
    method: 'POST',
    headers: {
      'Ocp-Apim-Subscription-Key': process.env.AZURE_KEY!,
      'Content-Type': 'application/ssml+xml',
      'X-Microsoft-OutputFormat': 'audio-16khz-128kbitrate-mono-mp3',
    },
    body: req.body,
  })
  res.set('Content-Type', 'audio/mpeg')
  azure.body!.pipeTo(Writable.toWeb(res))
})

// App
createApp(App)
  .use(VueSpeech, {
    provider: 'azure',
    subscriptionKey: '',
    region: 'eastus',
    baseURL: '/tts/azure',
  })
  .mount('#app')

Limitations

  • No pause() / resume() support (blob playback)
  • SSML input is not yet directly exposed — use the speak() composable for plain text

Released under the MIT License.