Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active December 1, 2018 23:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koze/6036c1dbda277ba2c6daf77d552537c2 to your computer and use it in GitHub Desktop.
Save Koze/6036c1dbda277ba2c6daf77d552537c2 to your computer and use it in GitHub Desktop.
AVSpeechSynthesizer on swift playground.
import UIKit
import AVFoundation
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
let string = "あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモーリオ市、郊外のぎらぎらひかる草の波。またそのなかでいっしょになったたくさんのひとたち、ファゼーロとロザーロ、羊飼のミーロや、顔の赤いこどもたち、地主のテーモ、山猫博士のボーガント・テストゥパーゴなど、いまこの暗い巨きな石の建物のなかで考えていると、みんなむかし風のなつかしい青い幻燈のように思われます。"
let synthesizer = AVSpeechSynthesizer()
let voice = AVSpeechSynthesisVoice(language: "ja_JP")
let utterance = AVSpeechUtterance(string: string)
utterance.voice = voice
synthesizer.speakUtterance(utterance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment