Reputation: 21
I am having trouble wth AVSpeechSynthesizer and utterances (ios 7.1.1)
The AVSpeechSynthesizer is initialised in a handler class with the delegate as self:
self.synthesizer = [[AVSpeechSynthesizer alloc] init];
self.synthesizer.delegate = self;
I have the following methods implemented in the delegate:
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
NSLog(@"Finish");
}
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance{
NSLog(@"Start");
}
and my speech is called via this method:
- (void)speak:(NSString *)spokenWord{
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:spokenWord];
[self.synthesizer speakUtterance:utterance];
}
I then call the method repeatedly e.g.
[AVhandler speak:_word];
[AVhandler speak:_word];
[AVhandler speak:_word];
I would expect to see in the log: Start Finish Start Finish Start Finish etc
But instead I see: Start Finish Finish Finish Finish
Why is the didStartSpeechUtterance not being called?
Thanks.
Upvotes: 2
Views: 1554
Reputation: 1
Also don't forget to add a reference to the AVSpeechSynthesizerDelegate Protocol in your .h file, such as:
@interface ViewController : UIViewController <AVSpeechSynthesizerDelegate>
Then you can put your synthesizer.delegate = self; in your ViewDidLoad method only.
Hope it helps.
Upvotes: 0
Reputation: 528
Answer is a little late, apologies. To resolve this, also put:
synthesizer.delegate = self;
in the -(void) as below
- (void)speak:(NSString *)spokenWord{
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:spokenWord];
[self.synthesizer speakUtterance:utterance];
synthesizer.delegate = self;
}
and in the didFinish as below:
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance {
NSLog(@"Finish");
synthesizer.delegate = self;
}
Upvotes: 1