0

目前我有一张带有注释的地图,当用户点击注释时,会播放音频。我想添加一个播放/暂停按钮,但它不起作用,我不确定为什么。

AVS语音合成器

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)anView
{
//Get a reference to the annotation this view is for...
id<MKAnnotation> annSelected = anView.annotation;

//Before casting, make sure this annotation is our custom type
//(and not some other type like MKUserLocation)...
if ([annSelected isKindOfClass:[MapViewAnnotation class]])
{
    MapViewAnnotation *mva = (MapViewAnnotation *)annSelected;

    AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];

    AVSpeechUtterance *utterance =
    [AVSpeechUtterance speechUtteranceWithString:mva.desc];
    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-gb"];

    [utterance setRate:0.35];
    [synthesizer speakUtterance:utterance];
}

按钮

- (IBAction)pauseButtonPressed:(UIButton *)sender 
{
[_synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];

}

现在,当我单击它时,什么也没有发生。

4

3 回答 3

1
use this one for pause

- (IBAction)pausePlayButton:(id)sender
    {
        if([synthesize isSpeaking]) {
            [synthesize pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
            AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@""];
            [synthesize speakUtterance:utterance];
            [synthesize pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];
        }

    }
于 2014-12-06T07:00:46.277 回答
0

为了将来的帮助,当我单击暂停并恢复注释工作时,它不会让我播放另一个注释,因为从技术上讲,第一个注释仍在运行。我添加了一个停止按钮[_synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];来整理它。

于 2014-03-18T11:53:05.423 回答
0

我不认为你在初始化_synthesizer. 尝试做self.synthesizer = [[AVSpeechSynthesizer alloc] init];而不是将合成器分配给局部变量。

我注意到AVSpeechSynthesizer在 7.0 测试版期间很难关闭,但我很难相信这样一个令人震惊的错误会持续这么长时间。

注意:您可能不应该在AVSpeechSynthesizer每次点击注释时重新创建。

NB2:一旦你暂停,我认为你必须打电话continueSpeaking重新启动。

于 2014-03-17T23:09:23.120 回答