From b4799ba66d1c831aac5fbcaf507650ecc818fa74 Mon Sep 17 00:00:00 2001 From: Justin Paupore Date: Sun, 4 Oct 2020 02:59:53 -0700 Subject: [PATCH] Fix TTS handling of non-ID3 metadata tags (#41191) Change #40666 used mutagen's ID3 TextFrame to wrap metadata information. While this is the correct behavior for container formats that use ID3 metadata tags, such as MP3 and linear PCM, Ogg container formats use a different metadata format. For these containers, the metadata needs to be a bare str, not wrapped in a TextFrame. --- homeassistant/components/tts/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 2eb12750fe8..e8e07092ce5 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -11,7 +11,7 @@ from typing import Dict, Optional from aiohttp import web import mutagen -from mutagen.id3 import TextFrame as ID3Text +from mutagen.id3 import ID3, TextFrame as ID3Text import voluptuous as vol from homeassistant.components.http import HomeAssistantView @@ -468,9 +468,14 @@ class SpeechManager: try: tts_file = mutagen.File(data_bytes) if tts_file is not None: - tts_file["artist"] = ID3Text(encoding=3, text=artist) - tts_file["album"] = ID3Text(encoding=3, text=album) - tts_file["title"] = ID3Text(encoding=3, text=message) + if isinstance(tts_file.tags, ID3): + tts_file["artist"] = ID3Text(encoding=3, text=artist) + tts_file["album"] = ID3Text(encoding=3, text=album) + tts_file["title"] = ID3Text(encoding=3, text=message) + else: + tts_file["artist"] = artist + tts_file["album"] = album + tts_file["title"] = message tts_file.save(data_bytes) except mutagen.MutagenError as err: _LOGGER.error("ID3 tag error: %s", err)