Fix case-sensitive MIME type check in Google Generative AI TTS#168458
Conversation
|
Hey there @tronikos, @IvanLH, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Fixes Google Generative AI TTS audio handling by making _parse_audio_mime_type treat MIME types case-insensitively, allowing the integration to accept audio/l16 responses from newer Gemini TTS models.
Changes:
- Make the audio MIME type prefix checks case-insensitive in
_parse_audio_mime_type. - Make the
L##bits-per-sample parsing resilient to lowercaselin the subtype. - Add unit tests covering uppercase/lowercase MIME types and unsupported types.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/components/google_generative_ai_conversation/helpers.py |
Adjusts MIME type parsing to be case-insensitive and correctly extract bit depth for audio/l16. |
tests/components/google_generative_ai_conversation/test_helpers.py |
Adds regression tests validating parsing for audio/L16 and audio/l16 and failure on non-audio types. |
| Returns: | ||
| A dictionary with "bits_per_sample" and "rate" keys. Values will be | ||
| integers if found, otherwise None. | ||
|
|
||
| """ | ||
| if not mime_type.startswith("audio/L"): | ||
| if not mime_type.lower().startswith("audio/l"): | ||
| LOGGER.warning("Received unexpected MIME type %s", mime_type) | ||
| raise HomeAssistantError(f"Unsupported audio MIME type: {mime_type}") |
There was a problem hiding this comment.
Update the docstring to match actual behavior by describing the default values used when parsing fails instead of saying the values can be None.
Breaking change
Proposed change
The Google Generative AI integration fails to handle audio responses from the
new
gemini-3.1-flash-tts-previewmodel because of a case-sensitive MIME typecheck. The integration expects MIME types starting with
audio/L(uppercase),but the new model returns
audio/l16; rate=24000; channels=1(lowercase),causing a
HomeAssistantError: Unsupported audio MIME type.This PR fixes all three case-sensitive checks in
_parse_audio_mime_typebyusing
.lower()for comparisons and.upper()when splitting to extractbits_per_sample, making the function work with bothaudio/L16andaudio/l16Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: