可可-NSSpeechSynthesiser讲话时如何更改讲话速度?

时间:2019-01-05 17:50:36

标签: swift macos cocoa

我想更改NSSpeechSynthesiser的讲话速度。 目前,我可以实现这一点,但是当再次调用“ startSpeaking”方法时,效果将得到应用。

   func speak(content: String) {
    if isCurrentlySpeaking {
        addToSpeakQueue(content: content)
        return
    }
    isCurrentlySpeaking = true
    loadVoicePreferences()
    speechSynthesiser.startSpeaking(content)
}

private func loadVoicePreferences() {
    guard let selectedVoice = TPPreferenceManager.shared.getSelectedVoiceIdentifier() else {return}
    let speechRate = TPPreferenceManager.shared.getSpeechRate()
    let speechVolume = TPPreferenceManager.shared.getSpeechVolume()
    speechSynthesiser.volume = speechVolume
    speechSynthesiser.setVoice(NSSpeechSynthesizer.VoiceName(rawValue: selectedVoice))
    speechSynthesiser.rate = speechRate
}

我希望所做的更改能够在更改的同时应用,而不会像VoiceOver一样停止或暂停NSSpeechSynthesiser。

0 个答案:

没有答案