Fix "ValueError: the metadata doesn't contain a Duration field"

* seems like microsoft updated their API to include this metadata type

Fixes #16
This commit is contained in:
rany2 2022-07-27 20:15:17 +03:00
parent 68a9e191d7
commit 3a4595d6d6
2 changed files with 7 additions and 11 deletions

View File

@ -1,6 +1,6 @@
[metadata]
name = edge-tts
version = 5.0.0
version = 5.0.1
author = rany
author_email = ranygh@riseup.net
description = Microsoft Edge's TTS

View File

@ -333,19 +333,13 @@ class Communicate:
metadata_offset = metadata["Metadata"][0]["Data"][
"Offset"
]
try:
if metadata_type == "WordBoundary":
metadata_duration = metadata["Metadata"][0]["Data"][
"Duration"
]
except KeyError as exception:
raise ValueError(
"The metadata doesn't contain a Duration field. "
+ "This usually happens when SentenceBoundary metadata type is sent."
) from exception
metadata_text = metadata["Metadata"][0]["Data"]["text"][
"Text"
]
if metadata_type == "WordBoundary":
metadata_text = metadata["Metadata"][0]["Data"]["text"][
"Text"
]
yield (
[
metadata_offset,
@ -358,6 +352,8 @@ class Communicate:
raise NotImplementedError(
"SentenceBoundary is not supported due to being broken."
)
elif metadata_type == "SessionEnd":
continue
else:
raise NotImplementedError(
f"Unknown metadata type: {metadata_type}"