diff --git a/setup.cfg b/setup.cfg index c1255d6..e25cccb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/src/edge_tts/communicate.py b/src/edge_tts/communicate.py index e5ed6f7..e8f5a65 100644 --- a/src/edge_tts/communicate.py +++ b/src/edge_tts/communicate.py @@ -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}"