2017-10-13 18 views
1

这是我的用于文本到语音转换的代码。一切正常工作在iOS 11以下。但在iOS 11委托方法没有被调用。AVSpeechSynthesizer代表没有在iOS中调用11

AVSpeechSynthesizerDelegate准确设置。 (正如它是工作在下面的iOS 11)

在按钮抽头

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init]; 
synthesizer.delegate = self; 

AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:stringToSpeech]; 
[utterance setRate:AVSpeechUtteranceDefaultSpeechRate]; 
[utterance setPitchMultiplier:1]; 
[utterance setVolume:1]; 
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; 
[synthesizer speakUtterance:utterance]; 

这些是委托方法我已经实现。

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

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

有人遇到过这个问题吗? 任何帮助将不胜感激。

余米iOS上测试11.0.3,和Xcode 9.0

回答

2

synthesizer对象必须是对工作:)属性。

要么让你AVSpeechSynthesizer实例,这是synthesizer像这样:

@property (strong, nonatomic) AVSpeechSynthesizer *synthesizer; 

或类似这样与读写。

@property (readwrite, strong, nonatomic) AVSpeechSynthesizer *synthesizer; 

让我知道这是否工作。

+0

我应该试试这个。谢谢 ! 它的工作 –

+0

@MZubairShamshad哪种类型的财产使用解决您提到的两种类型之间的问题? –

+0

@AanchalChaurasia'@property(strong,nonatomic)AVSpeechSynthesizer *合成器;'为我工作 –