LoginSignup
20
22

More than 5 years have passed since last update.

AVSpeechSynthesizerによる音声合成

Last updated at Posted at 2014-02-03

アプリで音声合成できないかなーとと思っていろいろ調べていたら、iOS7で標準搭載になったAVSpeechSynthesizer使えば簡単にできそうだったので試してみました。

Swift

AVFoundationを追加します。

import AVFoundation

あとは読み上げをしたいコントローラーに下記のように、読み上げる言葉と音声を指定してあげればOKです

let speech = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: "こんにちは")
utterance.voice = AVSpeechSynthesisVoice(language: "ja-JP")
utterance.rate = 0.3
speech.speakUtterance(utterance)

ちゃんと漢字混じりでも発音してくれます。これは簡単に使えますね。

RubyMotion

  app.frameworks += ['AVFoundation']
speech = AVSpeechSynthesizer.alloc.init
utterance = AVSpeechUtterance.speechUtteranceWithString("こんにちは")
utterance.voice = AVSpeechSynthesisVoice.voiceWithLanguage("ja-JP")
utterance.rate = 0.2
speech.speakUtterance(utterance)

参考

20
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
22