AVSpeechSynthesizer错误的AudioSession

19

我正在玩弄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];

有人知道如何修复这些错误吗?


我只在iOS模拟器上看到这个问题,而在设备上却没有。你有同样的情况吗? - Josh Brown
2
我也很好奇这是否只是模拟器异常。我在模拟器中使用AVFoundation时遇到过其他异常。 - bollhav
哦,没错,我也是! - h345k34cr
我也遇到了同样的问题——我刚更新为Xcode 5.0.2,但没有解决。当我开启了所有异常(我不得不切换到所有Objective-C异常)时,它也会抛出异常。 - Joe Booth
在使用 Xcode 5.0.2 的模拟器时,我也遇到了同样的错误。我在发布代码中使用它,没有收到任何投诉,并且在 iTunesConnect 中也没有出现崩溃。 - JScarry
4个回答

9

我对上面的代码进行了一些微调,在模拟器上成功运行。

  1. The [[self text] text] bit of your code might be wrong (which is where the Exception caught in (null) error would come from). The code below worked for me.

    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];
    

    And when I say "worked", I mean I heard the voice uttering my test sentence in my simulator.

    I did still see this warning:

    2013-09-21 11:37:56.454 Speech[5550:3a03] 11:37:56.454 ERROR: AVAudioSessionUtilities.h:88: GetProperty_DefaultToZero: AudioSessionGetProperty ('disa') failed with error: '?ytp'

  2. Xcode 5 appears to have a heck of a slow time trying to work with the traditional #import <AVFoundation/AVFoundation.h> with this SpeechSynthesis code, things seemed to speed up quite a bit when using the new @import AVFoundation;.


我的语音发声已经可以了。我只是在想为什么会出现这些错误。@import AVFoundation 对你有用吗?即使加入了这个,我还是有同样的错误。 - h345k34cr
在“@import AVFoundation;”后面加上一个分号,就可以了。 - Michael Dautermann
我在控制台中仍然看到“错误”信息,@h345k34cr;而且@Josh,我正在Xcode5中使用“@import AVFoundation;”。这是最近引入的全新功能。这里有更多相关信息 - Michael Dautermann
我并不认为有什么地方出错了,而更多的是需要初始化一些属性或“物品”,但不幸的是,据我所知,苹果目前没有提供任何语音合成示例代码。我建议你继续使用你现在拥有的内容,当苹果公司完善他们的文档或完成一些示例代码时,这个错误就可以被解决掉。 - Michael Dautermann
@import AVFoundation; 没有解决它。 - Shmidt
显示剩余3条评论

4

我也遇到过这些错误(使用ARC但不是多线程),但只在模拟器上出现,而不是在真实设备上出现。

我认为它们是模拟器的限制,可以安全地忽略 - 其他所有功能似乎都正常工作。

阿里


2

我在模拟器中得到了完全相同的错误日志,但是像你在其他地方指出的那样,在模拟器或iPhone 5设备上代码没有问题。区别可能在于我没有使用这6个可选的AVSpeechSythesizerDelegates之一,因此我没有在我的类协议中包含它。因此,为了帮助跟踪您的错误,您可以尝试不使用它。这是我的测试代码,逻辑上与您的代码相同,但没有委托和任何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,但我认为这并不会有什么影响。(也发布在开发者论坛中)


好的,我的代码也能正常工作。但这些错误日志很烦人,让我觉得有什么问题。 - h345k34cr

-1

我简直不敢相信,但我确实找到了解决这个问题的方法:如果您没有插入耳机或任何音频输出源,AVPlayer将无法工作,并且会打印以下内容:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接