本文介绍了AVSpeechSynthesizer与ios8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI有没有人在iOS 8上试过AvSpeechSynthesizer?
我在Xcode 6上做了快速的应用程序,但没有音频出来,我在Xcode 5上运行同样的工作并且没有任何障碍。

HI did anyone tried AvSpeechSynthesizer on iOS 8 ?I did quick app on Xcode 6 but no audio comes out, I ran the same on on the Xcode 5 and works without a hitch.

示例代码来自

NSString *string = @"Hello, World!";
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:string];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];

AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
[speechSynthesizer speakUtterance:utterance];

Xcode6的错误?

Bug with Xcode6?

==编辑===
看起来像iOS 8 sim的bug /问题,带有Xcode6的iOS7.1 Sim工作正常..

== Edit ===Looks like bug/issue with iOS 8 sim, iOS7.1 Sim with Xcode6 works fine..

推荐答案

是的,这是一个错误。从iOS8 GM开始,似乎首次尝试让AVSpeechSynthesizer说AVSpeechUtterance会导致沉默。

Yup, its a bug. As of iOS8 GM, it seems the first attempt to get AVSpeechSynthesizer to speak an AVSpeechUtterance will result in silence.

我的解决方法是让AVSpeechSynthesizer在初始化后立即说一个单字符的话语。这将是静默的,之后您的AVSpeechSynthesizer将正常工作。

My workaround is to make AVSpeechSynthesizer speak a single-character utterance immediately after it is initialized. This will be silent, and afterwards your AVSpeechSynthesizer will work as normal.

AVSpeechUtterance *bugWorkaroundUtterance = [AVSpeechUtterance speechUtteranceWithString:@" "];
bugWorkaroundUtterance.rate = AVSpeechUtteranceMaximumSpeechRate;
[self.speechSynthesizer speakUtterance:bugWorkaroundUtterance];

这篇关于AVSpeechSynthesizer与ios8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 13:59