moeru-ai/airi · error · Error

Failed to initialize speech provider

Error message

Failed to initialize speech provider

What it means

The speech-preview handler for Alibaba Cloud Model Studio awaits providersStore.getProviderInstance(providerId) and throws this generic message when it resolves falsy. In practice construction usually fails earlier with the credentials error from provider.ts when the API key is missing; this guard covers factories that return nothing. The surrounding code is a shared template (it references ElevenLabs option types).

Source

Thrown at packages/stage-pages/src/pages/settings/providers/speech/alibaba-cloud-model-studio.vue:47

const speechStore = useSpeechStore()
const providersStore = useProviderStore()
const providerStore = useProviderConfigStore()
const { configs: providers } = storeToRefs(providerStore)
const { t } = useI18n()

// Check if API key is configured
const apiKeyConfigured = computed(() => !!providers.value[providerId]?.apiKey)

// Get available voices for ElevenLabs
const availableVoices = computed(() => {
  return speechStore.availableVoices[providerId] || []
})

// Generate speech with ElevenLabs-specific parameters
async function handleGenerateSpeech(input: string, voiceId: string, _useSSML: boolean) {
  const provider = await providersStore.getProviderInstance(providerId) as SpeechProviderWithExtraOptions<string, UnElevenLabsOptions>
  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

  // ElevenLabs doesn't need SSML conversion, but if SSML is provided, use it directly
  return await speechStore.speech(
    provider,
    model,
    input,
    voiceId,
    {
      ...providerConfig,
      ...defaultVoiceSettings,
    },

View on GitHub (pinned to 677329427f)

Solutions

  1. Save the provider API key in Settings > Providers > Speech (the apiKeyConfigured computed reads the same state).
  2. Confirm providerId matches a registered speech definition.
  3. Catch the credentials error from getProviderInstance and link the user to provider settings.
  4. Keep the generate action disabled until apiKeyConfigured is true.

Example fix

// before
const provider = await providersStore.getProviderInstance(providerId)
if (!provider)
  throw new Error('Failed to initialize speech provider')

// after
if (!apiKeyConfigured.value)
  throw new Error('Configure the provider API key in Settings before generating speech')
const provider = await providersStore.getProviderInstance(providerId)
if (!provider)
  throw new Error(`Speech provider "${providerId}" factory returned no instance`)
Defensive patterns

Strategy: validation

Validate before calling

const apiKeyConfigured = computed(() => !!providers.value[providerId]?.apiKey)
if (!apiKeyConfigured.value) {
  // disable the generate button / prompt provider settings
}

Try / catch

catch (e) {
  if (errorMessageFrom(e)?.includes('credentials'))
    openProviderSettings(providerId)
  else
    throw e
}

Prevention

When it happens

Trigger: Clicking generate/test speech before saving the provider's API key in Settings > Providers > Speech; providerId not matching a registered speech definition.

Common situations: Fresh install with no speech credentials; switching speech provider without configuring it; stale providerId from an older version.

Related errors


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