2

当我使用 AVSpeechSynthesizer 朗读一串汉字时,它会在朗读几个字符后停止工作,但是会调用“didFinishSpeechUtterance”或“didCancelSpeechUtterance”委托。然后 CPU 使用率变为 99%。当我查看线程堆栈时,我发现一个线程正在递归调用函数。

原谅我糟糕的英语。下面是我的代码。

开发环境:Xcode 7.0 iPhone ios9

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>

NSString* testContent = @"叶玄又对雪仪道。\
“好的,主人!”雪仪螓首微颔,纤手一挥,一个3D虚拟屏幕便出现在他的面前:\
气血:312(-0);\
精神:353(-0);\
力量:193(+270);\
敏捷:160(+270);\
法力:103(练气后期);\
武技:十字拳(3级)、工字伏虎拳(3级)、虎鹤双形拳(3级)、佛山无影脚(5级)、金刚不坏神功(5级)、隔山打牛、辟邪剑法(4级)、傲寒六诀(4级)、冰心诀(2级)\
";

@interface ViewController ()<AVSpeechSynthesizerDelegate>
@property (nonatomic, strong) AVSpeechSynthesizer* ttsEngine;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.ttsEngine = [[AVSpeechSynthesizer alloc] init];
    self.ttsEngine.delegate = self;
}

- (IBAction)startPlay:(id)sender {
    AVSpeechUtterance* utterance = [AVSpeechUtterance speechUtteranceWithString:testContent ];
    NSLog(@"%f", AVSpeechUtteranceDefaultSpeechRate);
    utterance.rate = 0.7;
    AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-TW"];
    [utterance setVoice:voice];

    [self.ttsEngine speakUtterance:utterance];

}

- (void) speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance
{
    NSLog(@"didFinishSpeechUtterance");
}

- (void) speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance *)utterance
{
    NSLog(@"didCancelSpeechUtterance");
}


@end

AVSpeechSynthesizer 将在说出“主人!”后停止。

递归调用线程栈:

#65 0x00000001024b90f4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#66 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#67 0x00000001024b90f4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#68 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#69 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#70 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#71 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#72 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#73 0x00000001024b90f4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#74 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#75 0x00000001024b90f4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#76 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#77 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#78 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#79 0x00000001024b90f4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#80 0x00000001024b8ff4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#81 0x00000001024b90f4 in ___lldb_unnamed_function634$$TTSSpeechBundle ()
#82 0x00000001024b38d0 in mosyntaccphr_TreatSyntTree ()
#83 0x00000001024b2a0c in mosynt_DoAccentPhrasing ()
#84 0x00000001024276d0 in fe_phrasing_Process_Mosynt ()
#85 0x0000000102429e80 in fe_phrasing_Process ()
#86 0x00000001025aec94 in ___lldb_unnamed_function1254$$TTSSpeechBundle ()
#87 0x00000001025ad500 in ___lldb_unnamed_function1251$$TTSSpeechBundle ()
#88 0x00000001025ad404 in ttseg_Synthesize ()
#89 0x00000001025becac in ___lldb_unnamed_function1317$$TTSSpeechBundle ()
#90 0x00000001025bee9c in ve_ttsProcessText2Speech ()
#91 0x00000001023dc778 in TTSVocalizerProcessText ()
#92 0x00000001023df618 in ___lldb_unnamed_function100$$TTSSpeechBundle ()
#93 0x00000001023d92a4 in TTSPlaybackPerform ()
#94 0x00000001023decac in ___lldb_unnamed_function93$$TTSSpeechBundle ()
#95 0x000000019b693b3c in _pthread_body ()
#96 0x000000019b693aa0 in _pthread_start ()
4

0 回答 0