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.