Cleanup parse_metadata

Signed-off-by: rany2 <rany2@riseup.net>
This commit is contained in:
rany2
2024-02-16 20:12:44 +02:00
parent ec91ec1944
commit e58af9da76

View File

@@ -353,7 +353,7 @@ class Communicate:
) )
return True return True
def parse_metadata(): def parse_metadata() -> Dict[str, Any]:
for meta_obj in json.loads(data)["Metadata"]: for meta_obj in json.loads(data)["Metadata"]:
meta_type = meta_obj["Type"] meta_type = meta_obj["Type"]
if meta_type == "WordBoundary": if meta_type == "WordBoundary":
@@ -365,10 +365,10 @@ class Communicate:
"duration": current_duration, "duration": current_duration,
"text": meta_obj["Data"]["text"]["Text"], "text": meta_obj["Data"]["text"]["Text"],
} }
elif meta_type in ("SessionEnd",): if meta_type in ("SessionEnd",):
continue continue
else: raise UnknownResponse(f"Unknown metadata type: {meta_type}")
raise UnknownResponse(f"Unknown metadata type: {meta_type}") raise UnexpectedResponse("No WordBoundary metadata found")
# Split the text into multiple strings if it is too long for the service. # Split the text into multiple strings if it is too long for the service.
texts = split_text_by_byte_length( texts = split_text_by_byte_length(