iOS9 AVSpeechUtterance rate for AVSpeechSynthesizer issue

前提是你 提交于 2019-12-04 09:44:39

问题


The AVSpeechUtterance rate does not work the same for iOS 9 and prior versions of OS. Which is the change I have to make so that the sentence is spoken at the same speed. Are there any other changes I need to make for iOS9? It seems that multiplying the AVSpeechUtterance.rate by 6.0 works fine. Thank you!


回答1:


I also see the change after compiling with the new XCode. Below are my mappings from old to new speed. I now have different speed assignments if device is <= iOS8 or >= iOS9.

           iOS 8   iOS 9
Very Slow  0       0.42
Slower     0.06    0.5
My Normal  0.15    0.53
Faster     0.23    0.56



回答2:


I've bumped into this issue a few times, too. Given the frequency of changes to iOS lately, I set a default speech rate based on the iOS version the user is running in AppDelegate.swift like so:

// iOS speech synthesis is flakey between 8 and 9, so set default utterance rate based on iOS version
if NSProcessInfo().isOperatingSystemAtLeastVersion(NSOperatingSystemVersion(majorVersion: 8, minorVersion: 0, patchVersion: 0)) {
    NSUserDefaults.standardUserDefaults().setFloat(0.15, forKey: "defaultSpeechRate")
    if NSProcessInfo().isOperatingSystemAtLeastVersion(NSOperatingSystemVersion(majorVersion: 9, minorVersion: 0, patchVersion: 0)) {
        NSUserDefaults.standardUserDefaults().setFloat(0.53, forKey: "defaultSpeechRate")
    }
} else {
    NSUserDefaults.standardUserDefaults().setFloat(0.5, forKey: "defaultSpeechRate")
}

On my preferences scene, I added a slider to adjust the rate:

@IBOutlet var speechRateSlider: UISlider!

In viewDidLoad, I added the following:

    // Set speech rate
    speechRateSlider.value = NSUserDefaults.standardUserDefaults().floatForKey("defaultSpeechRate")
    speechRateSlider.maximumValue = 1.0
    speechRateSlider.minimumValue = 0.0
    speechRateSlider.continuous = true
    speechRateSlider.addTarget(self, action: "adjustSpeechRate:", forControlEvents: UIControlEvents.ValueChanged)

I also tied an action to the UISlider:

@IBAction func adjustSpeechRate(sender: AnyObject) {

    NSUserDefaults.standardUserDefaults().setFloat(speechRateSlider.value, forKey: "defaultSpeechRate")
    speechRateSlider.setValue(NSUserDefaults.standardUserDefaults().floatForKey("defaultSpeechRate"), animated: true)
    print(NSUserDefaults.standardUserDefaults().floatForKey("defaultSpeechRate"))
}

Given the unexpected behavior across devices and so many versions of iOS floating around, I opted to go this route rather than hard-code it into my app.



来源:https://stackoverflow.com/questions/32761786/ios9-avspeechutterance-rate-for-avspeechsynthesizer-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!