Ios7 未调用AVSpeechSynthesizer委托方法DidStartSpeechTerrance
我无法使用AVSpeech合成器和语音(ios 7.1.1) AVSpeechSynthesizer在处理程序类中初始化,委托为self:Ios7 未调用AVSpeechSynthesizer委托方法DidStartSpeechTerrance,ios7,delegates,avspeechsynthesizer,Ios7,Delegates,Avspeechsynthesizer,我无法使用AVSpeech合成器和语音(ios 7.1.1) AVSpeechSynthesizer在处理程序类中初始化,委托为self: self.synthesizer = [[AVSpeechSynthesizer alloc] init]; self.synthesizer.delegate = self; 我在委托中实现了以下方法: -(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeech
self.synthesizer = [[AVSpeechSynthesizer alloc] init];
self.synthesizer.delegate = self;
我在委托中实现了以下方法:
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
NSLog(@"Finish");
}
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance{
NSLog(@"Start");
}
通过这个方法调用我的演讲:
- (void)speak:(NSString *)spokenWord{
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:spokenWord];
[self.synthesizer speakUtterance:utterance];
}
然后我反复调用该方法,例如
[AVhandler speak:_word];
[AVhandler speak:_word];
[AVhandler speak:_word];
我希望在日志中看到:
开始
完成
开始
完成
开始
完成等
但我看到的是:
开始
完成
完成
完成
完成
为什么不调用DidStartPeechutterance
谢谢。回答有点晚,抱歉。为了解决这个问题,还提出:
synthesizer.delegate = self;
在下面的-(空白)中
- (void)speak:(NSString *)spokenWord{
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:spokenWord];
[self.synthesizer speakUtterance:utterance];
synthesizer.delegate = self;
}
在最后一步中,如下所示:
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
NSLog(@"Finish");
synthesizer.delegate = self;
}
另外,不要忘记在.h文件中添加对AVSpeechSynthesizerDelegate协议的引用,例如:
@interface ViewController : UIViewController <AVSpeechSynthesizerDelegate>
@界面ViewController:UIViewController
然后你可以把你的合成器;仅在ViewDidLoad方法中
希望能有帮助