iOS9 AVSpeechUtterance rate for AVSpeechSynthesizer issue

2 Solutions Collect From Internet About “iOS9 AVSpeechUtterance rate for AVSpeechSynthesizer issue”

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

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.