iOS- AVSpeechSynthesizer——iOS7語音合成器

來源:互聯網
上載者:User

語音合成器的技術是iOS7推出的,可以實現無網路語音功能,支援多種語言  1. 定義一個成員變數,記錄語音合成器 AVSpeechSynthesizer   #import <AVFoundation/AVFoundation.h>      1 @interfaceViewController () 2  3 { 4  5     // 合成器 6  7     AVSpeechSynthesizer *_synthesizer; 8  9     10 11     // 執行個體化說話的語言,說中文、英文12 13     AVSpeechSynthesisVoice *_voice;14 15 }      2. 定義語音對象 AVSpeechSynthesisVoice,指定說話的語言       zh_CN 中文     en-US 英文   1 - (void)viewDidLoad 2 { 3     [super viewDidLoad]; 4  5     // 執行個體化說話的語言,說中文 6     _voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; 7      8     // 要朗誦,需要一個語音合成器 9     _synthesizer = [[AVSpeechSynthesizer alloc] init];10 }        3. 執行個體化發聲對象 AVSpeechUtterance,指定要朗讀的內容     1      // 朗誦文字框中的內容2     // 執行個體化發聲的對象,及朗讀的內容3     AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:_textView.text];     4.指定語音,和朗誦速度                         中文朗誦速度:0.1還能夠接受     英文朗誦速度:0.3還可以 1  utterance.voice = _voice;2 3   utterance.rate = 0.3;     5.啟動                             1    [_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.