iOS內建TTS技術的實現即語音播報,iostts

來源:互聯網
上載者:User

iOS內建TTS技術的實現即語音播報,iostts

文本轉語音技術, 也叫TTS, 是Text To Speech的縮寫. iOS如果想做有聲書等功能的時候, 會用到這門技術.

一,使用iOS內建TTS需要注意的幾點:

二,程式碼範例, 播放語音

    //語音播報    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"床前明月光,疑是地上霜。"];    utterance.pitchMultiplier=0.8;        //中式發音    AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];    //英式發音//    AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"];        utterance.voice = voice;        NSLog(@"%@",[AVSpeechSynthesisVoice speechVoices]);        AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc]init];        [synth speakUtterance:utterance];

三,AVSpeechSynthesizer介紹

 

這個類就像一個會說話的人, 可以”說話”, 可以”暫停”說話, 可以”繼續”說話, 可以判斷他當前是否正在說話.有以下的方法或者屬性:

 

  • 說話: speakUtterance
  • 控制: continueSpeaking(繼續說), pauseSpeakingAtBoundary(暫停說話), paused(暫停狀態的屬性), speaking(說話的狀態), stopSpeakingAtBoundary(停止說話)
  • 委託: delegate

四,AVSpeechBoundary介紹

 

這是一個枚舉. 在暫停, 或者停止說話的時候, 停下的方式用這個枚舉標示. 包括兩種:

  • AVSpeechBoundaryImmediate: 立即停
  • AVSpeechBoundaryWord : 說完一個整詞再停

五,AVSpeechSynthesizerDelegate介紹

合成器的委託, 對於一些事件, 提供了響應的介面.

  • didCancelSpeechUtterance: 已經取消說話
  • didContinueSpeechUtterance: 已經繼續說話
  • didFinishSpeechUtterance: 已經說完
  • didPauseSpeechUtterance: 已經暫停
  • didStartSpeechUtterance:已經開始
  • willSpeakRangeOfSpeechString:將要說某段話

六,AVSpeechSynthesisVoice介紹

 

AVSpeechSynthesisVoice定義了一系列的聲音, 主要是不同的語言和地區.

 

  • voiceWithLanguage: 根據制定的語言, 獲得一個聲音.
  • speechVoices: 獲得當前裝置支援的聲音
  • currentLanguageCode: 獲得當前聲音的語言字串, 比如”ZH-cn”
  • language: 獲得當前的語言

七,AVSpeechUtterance介紹

 

這個類就是一段要說的話. 主要的屬性和方法有:

 

  • pitchMultiplier: 音高
  • postUtteranceDelay: 讀完一段後的停頓時間
  • preUtteranceDelay: 讀一段話之前的停頓
  • rate: 讀地速度, 系統提供了三個速度: AVSpeechUtteranceMinimumSpeechRate, AVSpeechUtteranceMaximumSpeechRate, AVSpeechUtteranceDefaultSpeechRate
  • speechString: 要讀的字串
  • voice: 使用的聲音, 是AVSpeechSynthesisVoice對象
  • volume: 音量

八,UML關係圖

這些類的關係如下:

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.