moeru-ai/airi · error · Error

Failed to initialize speech provider

Error message

Failed to initialize speech provider

What it means

Thrown by the Microsoft (Azure) Speech playground when the provider factory resolves falsy. The Microsoft provider is created through the unspeech bridge and needs both an API key and a region — the page injects the reactive `region` into the request options after building the instance. `getProviderInstance` types the result as non-nullable, so this guard fires when the factory declines on the persisted config (blank key, or a config shape the bridge refuses) rather than when the store's own missing-credentials/definition errors throw.

Source

Thrown at packages/stage-pages/src/pages/settings/providers/speech/microsoft-speech.vue:79

  if (!providers.value[providerId]?.region) {
    if (!providers.value[providerId])
      providers.value[providerId] = { region: region.value }
    else
      providers.value[providerId].region = region.value
  }

  await speechStore.loadVoicesForProvider(providerId)
})

watch([apiKeyConfigured, region], async () => {
  await speechStore.loadVoicesForProvider(providerId)
})

// Generate speech with Microsoft-specific parameters
async function handleGenerateSpeech(input: string, voiceId: string, useSSML: boolean) {
  const provider = await providersStore.getProviderInstance(providerId) as SpeechProviderWithExtraOptions<string, UnMicrosoftOptions>
  if (!provider) {
    throw new Error('Failed to initialize speech provider')
  }

  // Get provider configuration
  const providerConfig = providerStore.getProviderConfig(providerId)

  // Get model from configuration or use default
  const model = providerConfig.model as string | undefined || defaultModel

  // For Microsoft Speech, we need to ensure we're using the right region
  const options = {
    ...providerConfig,
    region: region.value,
    disableSsml: !useSSML, // If useSSML is true, we don't disable SSML
  }

  // If not using SSML and we have a voice, generate SSML
  if (!useSSML && voiceId) {
    const voice = availableVoices.value.find(v => v.id === voiceId)

View on GitHub (pinned to 677329427f)

Solutions

  1. Save both the API key and a valid Azure region in Settings → Providers → Microsoft Speech, and let validation succeed.
  2. Re-enter the playground after saving so the instance is rebuilt.
  3. Check console for `Error creating provider instance for ...` for the bridge's underlying refusal reason.
  4. Confirm the Azure resource is a Speech resource (not just OpenAI/Cognitive general) and its region matches.
  5. If config is complete and valid, report the silent-undefined factory as a contract bug.

Example fix

// before
const provider = await providersStore.getProviderInstance(providerId) as SpeechProviderWithExtraOptions<string, UnMicrosoftOptions>
if (!provider)
  throw new Error('Failed to initialize speech provider')

// after
const config = providerStore.getProviderConfig(providerId)
if (!config?.apiKey?.trim() || !region.value)
  throw new Error('Microsoft Speech needs both an API key and a region. Save them in provider settings first.')
const provider = await providersStore.getProviderInstance(providerId) as SpeechProviderWithExtraOptions<string, UnMicrosoftOptions>
if (!provider || typeof provider.speech !== 'function')
  throw new Error('Microsoft Speech factory returned no usable instance — check key/region and console logs')
Defensive patterns

Strategy: validation

Validate before calling

const canGenerate = computed(() =>
  !!providers.value[providerId]?.apiKey?.trim() && !!region.value,
)
if (!canGenerate.value)
  throw new Error('Microsoft Speech needs an API key and a region before generating')

Type guard

function isSpeechProvider(v: unknown): v is SpeechProviderWithExtraOptions<string, UnMicrosoftOptions> {
  return typeof v === 'object' && v !== null && typeof (v as SpeechProviderWithExtraOptions<string>).speech === 'function'
}

Try / catch

try { const provider = await providersStore.getProviderInstance(providerId) }
catch (error) { showError(errorMessageFrom(error)) }

Prevention

When it happens

Trigger: Clicking Generate before saving the Azure Speech API key; key present but region never selected so the factory or first request path gets unusable config; whitespace-only credentials; stale falsy result reused within the same session cache.

Common situations: Confusing Azure region names or leaving region at its placeholder; using an Azure resource from a tier without Speech services enabled; rotating keys in the Azure portal without re-saving in AIRI; trying the playground before finishing onboarding.

Related errors


AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18). Data as JSON: /api/errors/81a51691e827cf0a. Report an issue: GitHub.