diff --git a/dashscope/legacy_1x/audio/tts/speech_synthesizer.py b/dashscope/legacy_1x/audio/tts/speech_synthesizer.py index c3328681..5597c224 100644 --- a/dashscope/legacy_1x/audio/tts/speech_synthesizer.py +++ b/dashscope/legacy_1x/audio/tts/speech_synthesizer.py @@ -180,6 +180,14 @@ def call( # pylint: disable=R1702,too-many-branches # type: ignore[override] # part, ) else: + if ( + not isinstance(part.output, dict) + or "sentence" not in part.output + ): + # Non-timestamp message (e.g. extra messages returned + # in the SSML/bgm scenario). Skip it safely instead of + # raising KeyError on part.output["sentence"]. + continue if _callback is not None: sentence = SpeechSynthesisResult( None, # type: ignore[arg-type]