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.
This commit is contained in:
Justin Paupore 2020-10-04 02:59:53 -07:00 committed by GitHub
parent a50405aa6e
commit b4799ba66d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)