microsoft/semantic-kernel · error · ServiceResponseException

{type(self)} service failed to transcribe audio

Error message

{type(self)} service failed to transcribe audio

What it means

Raised as ServiceResponseException in _send_audio_to_text_request when any exception occurs during client.audio.transcriptions.create or while opening the audio file. The handler catches all exceptions and wraps them, preserving the original in ex.__cause__. File I/O errors (file not found, permission denied) are also caught here because the open() call is inside the try block.

Source

Thrown at python/semantic_kernel/connectors/ai/open_ai/services/open_ai_handler.py:173

            )
            self.store_usage(response)
            return response
        except Exception as ex:
            raise ServiceResponseException(f"Failed to edit image: {ex}") from ex

    async def _send_audio_to_text_request(self, settings: OpenAIAudioToTextExecutionSettings) -> Transcription:
        """Send a request to the OpenAI audio to text endpoint."""
        if not settings.filename:
            raise ServiceInvalidRequestError("Audio file is required for audio to text service")

        try:
            with open(settings.filename, "rb") as audio_file:
                return await self.client.audio.transcriptions.create(
                    file=audio_file,
                    **settings.prepare_settings_dict(),
                )
        except Exception as ex:
            raise ServiceResponseException(
                f"{type(self)} service failed to transcribe audio",
                ex,
            ) from ex

    async def _send_text_to_audio_request(
        self, settings: OpenAITextToAudioExecutionSettings
    ) -> _legacy_response.HttpxBinaryResponseContent:
        """Send a request to the OpenAI text to audio endpoint.

        The OpenAI API returns the content of the generated audio file.
        """
        try:
            return await self.client.audio.speech.create(
                **settings.prepare_settings_dict(),
            )
        except Exception as ex:
            raise ServiceResponseException(
                f"{type(self)} service failed to generate audio",

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Inspect ex.__cause__ to distinguish file I/O errors from API errors
  2. Verify the file path exists and the process has read permissions before calling
  3. Ensure the audio format is supported (mp3, mp4, mpeg, mpga, m4a, wav, webm)
  4. For API errors, check rate limits and file-size limits (25MB max for OpenAI transcription)

Example fix

# before
result = await service._send_audio_to_text_request(settings)
# after — pre-validate file
from pathlib import Path
p = Path(settings.filename)
if not p.is_file():
    raise FileNotFoundError(f'Audio file not found: {settings.filename}')
result = await service._send_audio_to_text_request(settings)
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

SUPPORTED_FORMATS = {'.mp3', '.mp4', '.mpeg', '.mpga', '.m4a', '.wav', '.webm'}
p = Path(settings.filename)
if not p.is_file():
    raise FileNotFoundError(f'Audio file not found: {p}')
if p.suffix.lower() not in SUPPORTED_FORMATS:
    raise ValueError(f'Unsupported audio format: {p.suffix}')
if p.stat().st_size > 25 * 1024 * 1024:
    raise ValueError('Audio file exceeds 25MB limit')

Try / catch

from semantic_kernel.exceptions import ServiceResponseException

try:
    result = await service._send_audio_to_text_request(settings)
except ServiceResponseException as e:
    logger.error('Transcription failed: %s (cause: %s)', e, e.__cause__)
    raise

Prevention

When it happens

Trigger: The audio file path does not exist (FileNotFoundError), is not readable (PermissionError), is in an unsupported format, exceeds API limits, or the transcription API call fails due to network/rate-limit/content-filter issues.

Common situations: File path typo or deleted file; insufficient file permissions on the server; unsupported audio format (OpenAI supports mp3, wav, m4a, etc.); audio file too large; rate limit from many transcription requests.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/3c51594d6f273890. Report an issue: GitHub.