gpt4 book ai didi

swift - 如何确定 AVSpeechSynthesizer 速度 Swift?

转载 作者:行者123 更新时间:2023-11-30 13:26:34 27 4
gpt4 key购买 nike

有人知道如何确定语音合成器的速度吗?现在听起来真的很快吗?

import UIKit
import AVFoundation

class ViewController: UIViewController {
var voice = AVSpeechSynthesizer()

override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

@IBAction func buttonPushed(sender: UIButton) {
var utterance = AVSpeechUtterance(string:"This is a test")
voice.speakUtterance(utterance)
}
}

最佳答案

为了降低语速,请使用 AVSpeechUtterance 类的速率属性

    let speechUtterance: AVSpeechUtterance = AVSpeechUtterance(string: "Sample text for speech")
speechUtterance.voice = AVSpeechSynthesisVoice(language: "en-US")

print("Default Speech Rate: " + String(speechUtterance.rate))

speechUtterance.rate = 0.3

let speechSynthesizer = AVSpeechSynthesizer()
speechSynthesizer.speakUtterance(speechUtterance)

关于swift - 如何确定 AVSpeechSynthesizer 速度 Swift?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37109127/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com