{"record":{"id":"0e28a33128e76544","repo":"xtekky/gpt4free","slug":"no-voices-found-for-language-audio-get-language","errorCode":null,"errorMessage":"No voices found for language '{audio.get('language')}' and locale '{audio.get('locale')}'.","messagePattern":"No voices found for language '(.+?)' and locale '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/audio/EdgeTTS.py","lineNumber":65,"sourceCode":"        **kwargs,\n    ) -> AsyncResult:\n        prompt = get_last_message(messages, prompt)\n        if not prompt:\n            raise ValueError(\"Prompt is empty.\")\n        voice = audio.get(\"voice\", model if model and model != cls.model_id else None)\n        if not voice:\n            voices = await VoicesManager.create()\n            if \"locale\" in audio:\n                voices = voices.find(Locale=audio[\"locale\"])\n            elif audio.get(\"language\", cls.default_language) != cls.default_language:\n                if \"-\" in audio.get(\"language\"):\n                    voices = voices.find(Locale=audio.get(\"language\"))\n                else:\n                    voices = voices.find(Language=audio.get(\"language\"))\n            else:\n                voices = voices.find(Locale=cls.default_locale)\n            if not voices:\n                raise ValueError(\n                    f\"No voices found for language '{audio.get('language')}' and locale '{audio.get('locale')}'.\"\n                )\n            voice = random.choice(voices)[\"Name\"]\n\n        format = audio.get(\"format\", cls.default_format)\n        filename = get_filename([cls.model_id], prompt, f\".{format}\", prompt)\n        target_path = os.path.join(get_media_dir(), filename)\n        ensure_media_dir()\n\n        extra_parameters = {\n            param: audio[param]\n            for param in [\"rate\", \"volume\", \"pitch\"]\n            if param in audio\n        }\n        communicate = edge_tts.Communicate(\n            prompt, voice=voice, proxy=proxy, **extra_parameters\n        )\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/audio/EdgeTTS.py#L47-L83","documentation":"ValueError from EdgeTTS when no voice matched the requested language/locale after querying Microsoft's VoicesManager. The provider searches voices by audio['locale'], by audio['language'] (as locale if it contains '-', else as language), or falls back to the provider's default locale; an empty result means the combination doesn't exist in edge-tts's voice catalog.","triggerScenarios":"Passing audio={'voice': None, 'language': 'xx'} or audio={'locale': 'xx-XX'} for an unsupported language/region; also defaulting paths when the voices list couldn't load matching entries.","commonSituations":"Requests for languages edge-tts doesn't ship (e.g. constructed or very rare locale codes); typos like 'en-USA' instead of 'en-US'; mismatched pairs like language='fr' with locale='de-DE'.","solutions":["Use a valid BCP-47 locale from edge-tts's voice list (e.g. 'en-US', 'de-DE', 'hi-IN')","Pass an explicit voice name in audio={'voice': 'en-US-AriaNeural'} to skip lookup","List valid voices first: await edge_tts.VoicesManager.create() and inspect find() results","Fix typos in locale/language codes"],"exampleFix":"# before\nawait client.speech.create(model='EdgeTTS', text='hi', audio={'language': 'en-USA'})\n\n# after\nawait client.speech.create(model='EdgeTTS', text='hi', audio={'voice': 'en-US-AriaNeural'})","handlingStrategy":"validation","validationCode":"import edge_tts\n\nasync def voice_exists(locale=None, language=None):\n    vm = await edge_tts.VoicesManager.create()\n    found = vm.find(Locale=locale) if locale else vm.find(Language=language)\n    return bool(found)\n\n# or validate a fixed allowlist: {'en-US', 'de-DE', 'hi-IN', ...}","typeGuard":"import re\n\ndef is_valid_locale(code: str) -> bool:\n    return bool(re.fullmatch(r'[a-z]{2,3}-[A-Z]{2}(?:[A-Z]{2})?', code or ''))","tryCatchPattern":"try:\n    ...  # speech call with language\nexcept ValueError as e:\n    if 'No voices found' in str(e):\n        retry with audio={'voice': 'en-US-AriaNeural'}  # known-good default","preventionTips":["Prefer explicit voice names over locale lookups in production","Cache the VoicesManager list and validate user locales against it","Normalize locale codes with BCP-47 rules before passing them in"],"tags":["edgetts","tts","locale","voice-selection"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}