繁体   English   中英

AVSpeechSynthesizer 不再在 ios16 下工作

[英]AVSpeechSynthesizer isn't working under ios16 anymore

我为我的应用程序写了一点 function 用于 text2speech function。 代码工作正常,直到 ios16。 现在我看到以下控制台日志:

022-09-13 18:04:02.274692+0200 Blindzeln_Prototyp[47358:164517] [asset] Failed to get sandbox extensions
2022-09-13 18:04:02.314956+0200 Blindzeln_Prototyp[47358:164517] [catalog] Query for com.apple.MobileAsset.VoiceServicesVocalizerVoice failed: 2
2022-09-13 18:04:02.315688+0200 Blindzeln_Prototyp[47358:164517] [catalog] Unable to list voice folder
2022-09-13 18:04:02.333665+0200 Blindzeln_Prototyp[47358:164517] [catalog] Query for com.apple.MobileAsset.VoiceServices.GryphonVoice failed: 2
2022-09-13 18:04:02.334239+0200 Blindzeln_Prototyp[47358:164517] [catalog] Unable to list voice folder
2022-09-13 18:04:02.338622+0200 Blindzeln_Prototyp[47358:164517] [catalog] Unable to list voice folder
2022-09-13 18:04:02.355732+0200 Blindzeln_Prototyp[47358:164583] [AXTTSCommon] File did not exist at content path: (null) (null). Attempting to fallback to default voice for language: (null)
2022-09-13 18:04:02.420342+0200 Blindzeln_Prototyp[47358:164583] [AXTTSCommon] Error: Unable to speak. No speech service: voice: (null) identifier: (null), language: (null), resource: (null)

这是简单的代码:

import Foundation
import AVFoundation

func sayIt(text2speech: String) {
    let utterance = AVSpeechUtterance(string: String(text2speech))
    utterance.voice = AVSpeechSynthesisVoice(language: "de-DE")
    utterance.rate = 0.5
    
    let synthesizer = AVSpeechSynthesizer()
    synthesizer.speak(utterance)
}

有什么提示吗?

Rohit 描述的设置适用于 iOS 16 模拟器。 显然 iOS 16 模拟器默认没有加载任何声音。 模拟设备本身的确切顺序如下:

设置/辅助功能/语音内容必须打开语音选择。 这将列出声音。 触摸那个。 Select 你的语言。 选择一个声音。 单击下载按钮。 等待。 完成后,如果需要,您可以退出并在途中关闭朗读选择。 必须打开它才能拨打 select 并下载语音。

我用过的代码:

let synth = AVSpeechSynthesizer()    
let myUtterance = AVSpeechUtterance(string: message)
myUtterance.rate = 0.4
synth.speak(myUtterance)

可以将let synth = AVSpeechSynthesizer()移出此方法并在顶部声明此 class 并使用。

为 Xcode14 & iOS 启用的设置 16:如果您使用的是 XCode14 和 iOS16,可能是未下载语音内容下的语音,您将在控制台上收到错误消息,提示标识符、来源、内容为 nil。 您需要做的就是,go 进入设置 -> 口语内容 -> 语音 -> Select 任何语言并下载任何配置文件。 在此运行您的声音之后,您将能够听到通过的文本中的语音。

你需要指派一个代表

class Speaker: NSObject, AVSpeechSynthesizerDelegate {
    let synthesizer = AVSpeechSynthesizer()
    init() {
       synthesizer.delegate = self
    }

    func speak(msg: String) {
        let utterance = AVSpeechUtterance(string: msg)

        utterance.rate = 0.57
        utterance.pitchMultiplier = 0.8
        utterance.postUtteranceDelay = 0.2
        utterance.volume = 0.8

        let voice = AVSpeechSynthesisVoice(language: "en-US")

        utterance.voice = voice
        synthesizer.speak(utterance)
    }
}

现在是如何使用

let s = Speaker()

s.speak(msg: "The quick brown fox jumped over the lazy dog.")

我之前外包了let synthesizer = AVSpeechSynthesizer()

用iOS 16,结果不是没有,但是我的voice Over功能已经变成了退化的机器人声音,非常听不见和难以理解。 如果您使用的是所列语言的特定版本: 在这里您可以忘记它。 iOS 16 不再嵌入它们。

[catalog] Unable to list voice folder

你必须用基本的声音来代替它。 例如, "de-DE"而不是"de-DE, Name: Anna, Quality: Default [com.apple.ttsbundle.Anna-compact]"

尝试移动

let synthesizer = AVSpeechSynthesizer()

在 function 之外。 这对我有用。

它对我不起作用错误消息:[目录] 无法列出语音文件夹

它对我也不起作用。 错误:无法说话。 无语音服务:语音:(null)标识符:(null),语言:(null),资源:(null)

我也看到了同样的情况。

我看到“错误:无法说话。没有语音服务:语音:(null)标识符:(null),语言:(null),资源:(null)”和“错误消息:[目录]无法列出语音文件夹“正如其他响应者所提到的。

将 AVSpeechSynthesizer 移出 function 也无济于事。

我们认为这是 Apple 会在后续更新中解决的问题吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM