2014-01-13 65 views
4

您好,我瞭解TTS僅在iOS 7中可用,但我過去通過檢查該類是否可用,並設法保留了以前版本的兼容性,但使用AVSpeechSynthesizer它似乎不工作,你能幫我使用iOS 7的TTS,並通過在iOS 6中禁用它來保持兼容性,非常感謝。使用iOS 7上的AVSpeechSynthesizer,但保留兼容性iOS 6

這裏是我的代碼,但它似乎沒有工作

if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)) { 
    if([AVSpeechSynthesizer class]) { 
     AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init]; 
     AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text]; 
     utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; 
     utterance.rate = AVSpeechUtteranceDefaultSpeechRate/2; 
     utterance.pitchMultiplier = 0.9; 
     utterance.preUtteranceDelay = 0; 
     utterance.postUtteranceDelay = 0; 
     [synth speakUtterance:utterance]; 
    } else { 
     // Feature not available, do something else 
    } 
} 

我已經在我的項目鏈接avfoundation並設置部署目標iOS 6中,它似乎只工作在iOS 7設備乳寧時如果它的iOS 6崩潰了。

這裏是錯誤消息我得到

dyld: Symbol not found: _AVSpeechUtteranceDefaultSpeechRate 
+1

你有沒有薄弱的聯繫框架? – rmaddy

+0

非常感謝你,在模擬器中它似乎工作! –

+1

轉到「構建階段」並將「AVFundation」從必需變爲可選...和Voila! – TonyMkenu

回答

6

該框架必須是弱鏈接。請執行以下操作:

  1. 單擊項目導航您的項目文件(左側)在編輯器中打開您的項目
  2. 點擊構建階段在編輯器中標籤
  3. 展開鏈接二進制與圖書館部分
  4. 設置AVFoundation.framework要求可選

Setting AVFoundation.framework from Required to Optional

此外,你可能想用one that's safer更新您的版本檢查(和蘋果推薦)。

+0

您播下了我們的通訊?爲什麼你的答案不同? :) – TonyMkenu

+2

@TonyMkenu正如我所看到的,堆棧溢出的重點是有人來找到他們問題的答案。如果這個問題沒有真正的答案,並且只有評論,有人可能會錯過這個問題的解決方案。 –

+0

你也有權!快樂的編碼! :) – TonyMkenu