0

I'm making a command line tool. I got this to work great in the Xcode macOS playground:

import AVFoundation

let synthesizer = AVSpeechSynthesizer()

func say(_ line:String) {
    let utterance = AVSpeechUtterance(string: line)
    utterance.postUtteranceDelay = 2
    let voice = AVSpeechSynthesisVoice(language: "en-GB")
    utterance.voice = voice
    synthesizer.speak(utterance)
}

say("hello")

However, it's silent in macOS cmd line project or as a compiled file outside of Xcode: swiftc -o main main.swift && ./main (no compile or runtime errors).

How do I make it work, i.e. say "hello", as command line tool as a compiled file outside of Xcode?

0 Answers0