From b062648064d9b353b08ec67af0e41f48a9bea4da Mon Sep 17 00:00:00 2001 From: Yulin Li Date: Fri, 8 Dec 2023 21:44:47 +0800 Subject: [PATCH] show original error if avatar synthesis failed (#768) --- src/sdk/AvatarSynthesizer.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sdk/AvatarSynthesizer.ts b/src/sdk/AvatarSynthesizer.ts index fc214b0d..1c8a12fc 100644 --- a/src/sdk/AvatarSynthesizer.ts +++ b/src/sdk/AvatarSynthesizer.ts @@ -18,6 +18,7 @@ import { AvatarEventArgs, PropertyCollection, PropertyId, + ResultReason, SpeechConfig, SpeechSynthesisOutputFormat, SpeechSynthesisResult, @@ -99,6 +100,14 @@ export class AvatarSynthesizer extends Synthesizer { this.privProperties.setProperty(PropertyId.TalkingAvatarService_WebRTC_SDP, JSON.stringify(peerConnection.localDescription)); const result: SpeechSynthesisResult = await this.speak("", false); + if (result.reason !== ResultReason.SynthesizingAudioCompleted) { + return new SynthesisResult( + result.resultId, + result.reason, + result.errorDetails, + result.properties, + ); + } const sdpAnswerString: string = atob(result.properties.getProperty(PropertyId.TalkingAvatarService_WebRTC_SDP)); const sdpAnswer: RTCSessionDescription = new RTCSessionDescription( JSON.parse(sdpAnswerString) as RTCSessionDescriptionInit, @@ -156,6 +165,10 @@ export class AvatarSynthesizer extends Synthesizer { * @returns {Promise} The promise of the void result. */ public async stopSpeakingAsync(): Promise { + while (this.synthesisRequestQueue.length() > 0) { + const request = await this.synthesisRequestQueue.dequeue(); + request.err("Synthesis is canceled by user."); + } return this.privAdapter.stopSpeaking(); }