【问题标题】:Real time rate and pitch adjustments Swift实时速率和音高调整 Swift
【发布时间】:2019-07-04 20:11:35
【问题描述】:

我正在使用AVSpeechSynthesizer 设置一个 tts 应用程序。我必须进行实时音高和速率调整。我正在使用UISLider 来调整音高和速率。

这是我的代码:-

@IBAction func sl(_ sender: UISlider) {
    if synthesizer.isSpeaking {
        synthesizer.stopSpeaking(at: .immediate)

        self.rate = sender.value

        if currentRange.length > 0 {
            let valuee = currentRange.length + currentRange.location
            let neww = self.tvEditor.text.dropFirst(valuee)
            self.tvEditor.text = String(neww)
            synthesizer.speak(buildUtterance(for: rate, pitch: pitch, with: String(neww), language: self.preferredVoiceLanguageCode2 ?? "en"))
        }
    } else {

    }
}

【问题讨论】:

    标签: ios swift uislider avspeechsynthesizer


    【解决方案1】:

    即使没有提供详细信息,我也可能已经理解了您的问题:您无法在演讲运行时考虑ratepitchMultiplier 的新值

    为了解释以下细节,我阅读了this example,其中包含代码 sn-ps (ObjC, Swift) 和插图。

    1. 使用 ratepitchMultiplier 属性创建您的 AVSpeechUtterance 实例。
    2. 将它们中的每一个添加到一个数组中,该数组将表示要朗读的队列。
    3. 使用合成器在前一个队列中循环读取每个元素。

    现在,如果您想实时更改属性值,请在其中一个滑块移动后查看以下步骤:

    1. 借助AVSpeechSynthesizerDelegate 协议获取当前口语。
    2. 运行stopSpeaking 合成器方法,该方法将从队列中删除尚未说出的话语。
    3. 使用新的属性值创建之前删除的话语。
    4. 重做第 2 步和第 3 步,以使用这些更新后的值恢复您停止的位置。

    在您请求不影响存储话语的新值之前,合成器将所有要说出的信息排入队列:您必须删除并重新创建具有新属性值的话语才能说出。

    如果上面链接提供的代码示例还不够,我建议看看this WWDC video detailed summary处理AVSpeechSynthesizer

    【讨论】:

      猜你喜欢
      • 2018-12-13
      • 1970-01-01
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      • 2021-10-26
      • 1970-01-01
      相关资源
      最近更新 更多