AVSpeechSynthesizer错误AudioSession

我正在玩AVSpeechSynthesizer,总是得到这些错误:

ERROR: >aqsrv> 65: Exception caught in (null) - error -66634 ERROR: AVAudioSessionUtilities.h:88: GetProperty_DefaultToZero: AudioSessionGetProperty ('disa') failed with error: '?ytp' 

我的代码是:

 AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init]; [synthesizer setDelegate:self]; speechSpeed = AVSpeechUtteranceMinimumSpeechRate; AVSpeechUtterance *synUtt = [[AVSpeechUtterance alloc] initWithString:[[self text] text]]; [synUtt setRate:speechSpeed]; [synUtt setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:languageCode]]; [synthesizer speakUtterance:synUtt]; 

有谁知道如何解决这些错误?

我得到了上面的代码在模拟器上进行最小的调整。

  1. 你的代码中的[[self text] text]位可能是错误的(这是Exception caught in (null)错误来自的地方)。 下面的代码为我工作。

     AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init]; [synthesizer setDelegate:self]; // set your class to conform to the AVSpeechSynthesizerDelegate protocol float speechSpeed = AVSpeechUtteranceMinimumSpeechRate; AVSpeechUtterance *synUtt = [[AVSpeechUtterance alloc] initWithString:@"hello I am testing"]; [synUtt setRate:speechSpeed]; [synUtt setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:[AVSpeechSynthesisVoice currentLanguageCode]]]; [synthesizer speakUtterance:synUtt]; 

    当我说“工作”时,我的意思是我听到在我的模拟器中发出我的testing句子的声音。

    我仍然看到这个警告:

    2013-09-21 11:37:56.454 Speech [5550:3a03] 11:37:56.454错误:AVAudioSessionUtilities.h:88:GetProperty_DefaultToZero:AudioSessionGetProperty('disa')失败,错误:'?ytp'

  2. Xcode 5似乎有一个很慢的时间试图与传统的#import <AVFoundation/AVFoundation.h>这个语音合成代码,使用新的@import AVFoundation;似乎加快了一点点@import AVFoundation;

我也看到这些错误(使用ARC,但不是muli线程),但只在模拟器上,而不是在真实的设备上。

我正在假设,他们是一个模拟器的限制,可以安全地忽略 – 一切似乎工作正常。

阿里

我在模拟器中得到完全相同的错误日志,但是我在模拟器或iPhone 5设备中的代码没有问题,正如您在别处指出的那样。 区别可能是我没有使用这6个可选的AVSpeechSythesizerDelegates中的任何一个,因此,我没有把它包含在我的类协议中。 因此,为了帮助追踪您的错误,您可以尝试一下。 这里是我的testing代码,它与您的逻辑相同,减去委托和任何AVSpeechUtterance存储分配:

 -(void)tts:(NSString*)text { #define MY_SPEECH_RATE 0.1666 #define MY_SPEECH_MPX 1.55 AVSpeechSynthesizer *textToSpeech = [[AVSpeechSynthesizer new]autorelease]; NSString *language = [AVSpeechSynthesisVoice currentLanguageCode]; if (language==nil) language = @"en-us"; AVSpeechUtterance *speak = [AVSpeechUtterance speechUtteranceWithString:text]; [speak setRate:MY_SPEECH_RATE]; [speak setPitchMultiplier:MY_SPEECH_MPX]; [speak setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:language]]; [textToSpeech speakUtterance:speak]; } 

正如你所看到的,我没有使用ARC,但我不认为这有什么不同。 (也发布在开发者论坛)

我不能相信,但我实际上find了解决scheme:如果你没有耳机插入或任何audio输出源,AVPlayer将无法正常工作,它会打印:

 ERROR: >aqsrv> 65: Exception caught in (null) - error -66634