Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/tts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ def write_tags(
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)
Expand Down
Binary file added tests/components/tts/fixtures/tagged.mp3
Binary file not shown.
27 changes: 26 additions & 1 deletion tests/components/tts/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@
retrieve_media,
)

from tests.common import MockModule, async_mock_service, mock_integration, mock_platform
from tests.common import (
MockModule,
async_mock_service,
load_fixture_bytes,
mock_integration,
mock_platform,
)
from tests.typing import ClientSessionGenerator, WebSocketGenerator

ORIG_WRITE_TAGS = tts.SpeechManager.write_tags
Expand Down Expand Up @@ -2302,3 +2308,22 @@ async def test_stream_override_with_conversion(
assert wav_reader.readframes(wav_reader.getnframes()) == bytes(
22050 * 2 * 2
) # 1 second @ 22.5Khz/stereo


def test_write_tags_keeps_single_id3_tag() -> 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
Loading