Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS9 AVSpeechUtterance rate for AVSpeechSynthesizer issue

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!

like image 278
User123335511231 Avatar asked Sep 24 '15 12:09

User123335511231


2 Answers

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
like image 200
Ernie Thomason Avatar answered Oct 16 '22 06:10

Ernie Thomason


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.

like image 2
Adrian Avatar answered Oct 16 '22 05:10

Adrian