I would like to be able to use avspeechsynthiesizer to create a sound file that can be played in other functions. Just like I could by importing a sound into Xcode. So I would like to use the button in my code below to save a sound. Then have it stored function playsound.
@IBAction func do(_ sender: Any) {
let utterance = AVSpeechUtterance(string: "Hello")
utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")
let synthesizer = AVSpeechSynthesizer()
synthesizer.delegate = self
synthesizer.speak(utterance)
}
func playSound() {
//like to insert the sound here.
let url = Bundle.main.url(forResource: "", withExtension: "")!
do {
player = try AVAudioPlayer(contentsOf: url)
guard let player = player else { return }
player.prepareToPlay()
player.play()
} catch let error as NSError {
print(error.description)
}}