|
|
@ -276,11 +276,9 @@ public class AzureTtsHelper: NSObject, ITtsService { |
|
|
|
|
|
|
|
|
do { |
|
|
do { |
|
|
print("liwei-------------停止语音合成播放") |
|
|
print("liwei-------------停止语音合成播放") |
|
|
// 使用异步停止方法 |
|
|
// 使用同步停止方法 |
|
|
if let synthesizer = self.synthesizer { |
|
|
if let synthesizer = self.synthesizer { |
|
|
let stopFuture = synthesizer.stopSpeakingAsync() |
|
|
try synthesizer.stopSpeaking() |
|
|
// 等待停止操作完成 |
|
|
|
|
|
_ = stopFuture.get() |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
self.notifyEvent(eventType: .synthesisCanceled) |
|
|
self.notifyEvent(eventType: .synthesisCanceled) |
|
|
@ -328,8 +326,7 @@ public class AzureTtsHelper: NSObject, ITtsService { |
|
|
// 确保合成器完全停止后再销毁 |
|
|
// 确保合成器完全停止后再销毁 |
|
|
if let synthesizer = self.synthesizer { |
|
|
if let synthesizer = self.synthesizer { |
|
|
do { |
|
|
do { |
|
|
let stopFuture = synthesizer.stopSpeakingAsync() |
|
|
try synthesizer.stopSpeaking() |
|
|
_ = try stopFuture.get() |
|
|
|
|
|
} catch { |
|
|
} catch { |
|
|
os_log("停止合成器失败: %{public}@", log: self.log, type: .error, error.localizedDescription) |
|
|
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) |
|
|
os_log("开始合成: %{public}@", log: log, type: .debug, ssml) |
|
|
|
|
|
|
|
|
// 使用异步合成方法 |
|
|
// 使用同步合成方法 |
|
|
if let synthesizer = self.synthesizer { |
|
|
if let synthesizer = self.synthesizer { |
|
|
let future = synthesizer.speakSsmlAsync(ssml) |
|
|
do { |
|
|
|
|
|
try synthesizer.startSpeakingSsml(ssml) |
|
|
// 在后台等待合成完成 |
|
|
os_log("合成开始成功", log: self.log, type: .debug) |
|
|
DispatchQueue.global(qos: .userInitiated).async { [weak self] in |
|
|
} catch { |
|
|
defer { |
|
|
self.speaking = false |
|
|
self?.synthesisGroup.leave() |
|
|
os_log("合成失败: %{public}@", log: self.log, type: .error, error.localizedDescription) |
|
|
} |
|
|
self.notifyEvent(eventType: .error, params: [ |
|
|
|
|
|
"errorCode": "SYNTHESIS_FAILED", |
|
|
do { |
|
|
"errorMessage": error.localizedDescription |
|
|
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 |
|
|
|
|
|
]) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|