我正在编写一个应用程序,允许用户在听到他们想要关注的网络链接时按下按钮。
问题是我正在使用的 for 循环将所有文本添加到话语列表中,并且在继续之前不等待话语完成,这意味着我无法判断他们想要遵循的链接。
我有一堂课叫
演讲
这是 AVSpeechSynthesiser 的代表,并试图创建我自己的方式来确定话语何时结束:
-(id)init {
self = [super init];
if (self) {
_synthesiser = [[AVSpeechSynthesizer alloc]init];
[self setSpeaking:NO];
}
return self;
}
-(void)outputAsSpeech:(NSString *)text
{
[self setSpeaking:YES];
[[self synthesiser]speakUtterance:[[AVSpeechUtterance alloc]initWithString:text]];
}
-(BOOL)isSpeaking
{
return [self speaking];
}
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance
{
[self setSpeaking:NO];
}
而在课堂上
视图控制器
-(void)readBookmarks
{
[[self speech]continueSpeech];
[[self speech]outputAsSpeech:@"Bookmarks,"];
for ([self bookmarksPointer]; [self bookmarksPointer] < [[self bookmarks]count]; _bookmarksPointer++) {
NSDictionary* dictionary = [[self bookmarks]objectAtIndex:[self bookmarksPointer]];
[[self speech]outputAsSpeech:[dictionary objectForKey:@"title"]];
while ([[self speech]isSpeaking]) {}
}
}
这个想法是应用程序应该等到话语发生然后继续。但此刻它读出“书签”并停止,它甚至没有读出第一个书签,我也尝试将 while 循环放在 for 循环的开头。
任何人都可以帮助我,我将非常感激。
谢谢