From a50b2b3d8e2cc3a9f0035221be703b45b05632ff Mon Sep 17 00:00:00 2001 From: Bryce Boe Date: Sun, 20 Sep 2026 15:52:13 -0700 Subject: [PATCH] Fix duplicate ID3 tag when tagging TTS audio (#182800) --- homeassistant/components/tts/__init__.py | 1 + tests/components/tts/fixtures/tagged.mp3 | Bin 0 -> 957 bytes tests/components/tts/test_init.py | 27 ++++++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/components/tts/fixtures/tagged.mp3 diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 71adc8a98752..7a876c31d20d 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -1212,6 +1212,7 @@ class SpeechManager: tts_file["artist"] = artist tts_file["album"] = album tts_file["title"] = message + data_bytes.seek(0) tts_file.save(data_bytes) except mutagen.MutagenError as err: _LOGGER.error("ID3 tag error: %s", err) diff --git a/tests/components/tts/fixtures/tagged.mp3 b/tests/components/tts/fixtures/tagged.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..b29b59e5add726e01930b985422cee4e8ef6c071 GIT binary patch literal 957 zcmeZtF=k-^0p*b3U{@f`&%nU!lUSB!W~65bL None: + """Test tagging audio that already carries an ID3 tag does not add a second one.""" + data = load_fixture_bytes("tagged.mp3", DOMAIN) + assert data.startswith(b"ID3") + assert data.count(b"ID3") == 1 + + tagged = ORIG_WRITE_TAGS( + "42f18378fd4393d18c8dd11d03fa9563c1e54491_en-us_-_test.mp3", + data, + "Test", + "There is someone at the door.", + "en", + None, + ) + + assert tagged.startswith(b"ID3") + assert tagged.count(b"ID3") == 1