From cb01d07bd7537a062d419b0267b81955d857fc86 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Mon, 15 Sep 2025 14:33:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(azure=5Fspeech):=20=E5=B0=86=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E8=AF=AD=E9=9F=B3=E5=90=88=E6=88=90=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=90=8C=E6=AD=A5=E4=BB=A5=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改Azure语音合成方法,从异步调用改为同步调用,避免潜在的并发问题。同时更新版本号以反映此次修改。 --- .../Sources/azure_speech/AzureTtsHelper.swift | 41 +++++++------------ pubspec.yaml | 2 +- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift index 6689f5138..2d08ca702 100644 --- a/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift +++ b/local_plugins/azure_speech/ios/azure_speech/Sources/azure_speech/AzureTtsHelper.swift @@ -276,11 +276,9 @@ public class AzureTtsHelper: NSObject, ITtsService { do { print("liwei-------------停止语音合成播放") - // 使用异步停止方法 + // 使用同步停止方法 if let synthesizer = self.synthesizer { - let stopFuture = synthesizer.stopSpeakingAsync() - // 等待停止操作完成 - _ = stopFuture.get() + try synthesizer.stopSpeaking() } self.notifyEvent(eventType: .synthesisCanceled) @@ -328,8 +326,7 @@ public class AzureTtsHelper: NSObject, ITtsService { // 确保合成器完全停止后再销毁 if let synthesizer = self.synthesizer { do { - let stopFuture = synthesizer.stopSpeakingAsync() - _ = try stopFuture.get() + try synthesizer.stopSpeaking() } catch { os_log("停止合成器失败: %{public}@", log: self.log, type: .error, error.localizedDescription) } @@ -493,28 +490,18 @@ public class AzureTtsHelper: NSObject, ITtsService { } os_log("开始合成: %{public}@", log: log, type: .debug, ssml) - // 使用异步合成方法 + // 使用同步合成方法 if let synthesizer = self.synthesizer { - let future = synthesizer.speakSsmlAsync(ssml) - - // 在后台等待合成完成 - DispatchQueue.global(qos: .userInitiated).async { [weak self] in - defer { - self?.synthesisGroup.leave() - } - - do { - let result = try future.get() - os_log("合成完成,结果: %{public}@", log: self?.log ?? OSLog.default, type: .debug, String(describing: result.reason)) - } catch { - self?.speaking = false - self?.pendingTextCount = max(0, (self?.pendingTextCount ?? 0) - text.count) - os_log("异步语音合成失败: %{public}@", log: self?.log ?? OSLog.default, type: .error, error.localizedDescription) - self?.notifyEvent(eventType: .error, params: [ - "errorCode": "ASYNC_SYNTHESIS_FAILED", - "errorMessage": error.localizedDescription - ]) - } + do { + try synthesizer.startSpeakingSsml(ssml) + os_log("合成开始成功", log: self.log, type: .debug) + } catch { + self.speaking = false + os_log("合成失败: %{public}@", log: self.log, type: .error, error.localizedDescription) + self.notifyEvent(eventType: .error, params: [ + "errorCode": "SYNTHESIS_FAILED", + "errorMessage": error.localizedDescription + ]) } } diff --git a/pubspec.yaml b/pubspec.yaml index 1a6b7388d..d8cd1e987 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: voitrans description: "Voitrans - AI Voice Assistant." publish_to: "none" -version: 1.0.14+37 +version: 1.0.15+38 environment: sdk: ">=3.3.0 <4.0.0"