AVSpeechSynthesizer 語言合成器,

來源:互聯網
上載者:User

AVSpeechSynthesizer 語言合成器,

語音合成器的技術是iOS7推出的,可以實現無網路語音功能,支援多種語言

  1、import<AVFoundation/AVFoundation.h>

    定義一個成員變數AVSpeechSynthesizer *_synthesizer,語言合成;

    定義一個成員變數AVSpeechSynthesisVoice *_voice,執行個體化說話的語言(中文、英文)

    

  2、執行個體化說的語言,初始化語言合成器

    //若常值內容為中文則使用  zh_CN ;若常值內容為英文文則使用  en-US ;

    _voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; //zh_CN 中文  en-US 英文

     // 要朗誦,需要一個語音合成器,初始化語言合成器

      _synthesizer = [[AVSpeechSynthesizer alloc] init];

  3、執行個體化發聲對象AVSpeechUtterance,指定要朗讀的內容

   //執行個體化對象AVSpeechUtterance,指定朗讀內容

    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:_textView.text];

  4、指定語言和朗誦的速度

   //指定語言

     utterance.voice = _voice;

   //朗誦語速

    utterance.rate = 0.3; //中文0.1,英文0.3還可以,以實際為準

  5、啟動

          [_synthesizer speakUtterance:utterance];

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.