{"record":{"id":"f53d9813b3537927","repo":"microsoft/semantic-kernel","slug":"audio-file-is-required-for-audio-to-text-service","errorCode":null,"errorMessage":"Audio file is required for audio to text service","messagePattern":"Audio file is required for audio to text service","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/open_ai_handler.py","lineNumber":164,"sourceCode":"\n        Returns:\n            ImagesResponse: The response from the image edit API.\n        \"\"\"\n        try:\n            response: ImagesResponse = await self.client.images.edit(\n                image=image,\n                mask=mask,  # type: ignore\n                **settings.prepare_settings_dict(),\n            )\n            self.store_usage(response)\n            return response\n        except Exception as ex:\n            raise ServiceResponseException(f\"Failed to edit image: {ex}\") from ex\n\n    async def _send_audio_to_text_request(self, settings: OpenAIAudioToTextExecutionSettings) -> Transcription:\n        \"\"\"Send a request to the OpenAI audio to text endpoint.\"\"\"\n        if not settings.filename:\n            raise ServiceInvalidRequestError(\"Audio file is required for audio to text service\")\n\n        try:\n            with open(settings.filename, \"rb\") as audio_file:\n                return await self.client.audio.transcriptions.create(\n                    file=audio_file,\n                    **settings.prepare_settings_dict(),\n                )\n        except Exception as ex:\n            raise ServiceResponseException(\n                f\"{type(self)} service failed to transcribe audio\",\n                ex,\n            ) from ex\n\n    async def _send_text_to_audio_request(\n        self, settings: OpenAITextToAudioExecutionSettings\n    ) -> _legacy_response.HttpxBinaryResponseContent:\n        \"\"\"Send a request to the OpenAI text to audio endpoint.\n","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_handler.py#L146-L182","documentation":"Raised as ServiceInvalidRequestError in _send_audio_to_text_request when settings.filename is falsy. This is a pre-flight validation check — the handler refuses to open a file path it cannot resolve before attempting the API call.","triggerScenarios":"Constructing OpenAIAudioToTextExecutionSettings without a filename, or with filename=None, and then calling the transcription path via the service handler.","commonSituations":"Building a transcription pipeline where the audio path is dynamically resolved but comes back empty; passing settings built for a different endpoint to the audio-to-text service; configuration key mismatch for the audio file path.","solutions":["Set settings.filename to a valid path to the audio file before calling the service","Validate that the audio file path is non-empty and the file exists before constructing settings","If building settings programmatically, default filename from user input or file-upload handling"],"exampleFix":"# before\nsettings = OpenAIAudioToTextExecutionSettings()  # no filename\n# after\nsettings = OpenAIAudioToTextExecutionSettings(filename='/path/to/audio.mp3')","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nif not settings.filename:\n    raise ValueError('Filename is required for audio transcription')\nif not Path(settings.filename).is_file():\n    raise FileNotFoundError(f'Audio file not found: {settings.filename}')","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInvalidRequestError\n\ntry:\n    result = await service._send_audio_to_text_request(settings)\nexcept ServiceInvalidRequestError as e:\n    if 'Audio file is required' in str(e):\n        raise ValueError('Provide a valid audio file path') from e","preventionTips":["Always set and validate the filename on audio-to-text settings before the API call","Use pathlib.Path to resolve and validate the file exists at the application layer"],"tags":["openai","audio-to-text","transcription","validation","file-input"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}