2017-10-13 65 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 *合成器;'爲我工作 –

相關問題