I have come across this question several times. Given the frequency of changes in iOS recently, I set the default baud rate based on the version of iOS in which the user works in AppDelegate.swift , for example:
// 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") }
In my settings scene, I added a slider to adjust the speed:
@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 associated the action with 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 on different devices and many versions of iOS floating around, I decided to take this route, rather than hard code it into my application.
Adrian
source share