macOSようの読み上げアプリを考えているのですがvoiceがnullになってしまい発音されません
書き方の間違っている部分がわかる方がいらっしゃれば教えていただけませんか?
swift
1import Cocoa 2import AVFoundation 3 4class ViewController: NSViewController,AVSpeechSynthesizerDelegate { 5 6 var sound = AVSpeechSynthesizer() 7 var speakString = AVSpeechUtterance() 8 var speech = AVSpeechUtterance(string: "") 9 10 11 @IBAction func A(_ sender: NSButton) { 12 speech = AVSpeechUtterance(string: "hey") 13 speech.voice = AVSpeechSynthesisVoice(identifier: "en-US") 14 sound.speak(speech) 15 print(speech) 16 } 17 18 @IBAction func B(_ sender: NSButton) { 19 } 20 21 @IBOutlet weak var textView: NSScrollView! 22 override func viewDidLoad() { 23 super.viewDidLoad() 24 25// スピーチ 26 sound.delegate = self 27 28 } 29 30 override var representedObject: Any? { 31 didSet { 32 // Update the view, if already loaded. 33 } 34 } 35 36 37} 38 39
[AVSpeechUtterance 0x60000184cb00] String: hey
Voice: (null)
Rate: 0.50
Volume: 1.00
Pitch Multiplier: 1.00
Delays: Pre: 0.00(s) Post: 0.00(s)
解決したのであれば質問をクローズしてください。
あなたの回答
tips
プレビュー