# How to nest avspeechsynthisizier into sound file (swif3)

**URL:** <https://forums.kodeco.com/t/how-to-nest-avspeechsynthisizier-into-sound-file-swif3/33085>\
**Category:** Swift\
**Created:** [August 8, 2017, 3:35pm UTC](https://forums.kodeco.com/t/how-to-nest-avspeechsynthisizier-into-sound-file-swif3/33085 "2017-08-08T15:35:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zalubski](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/zalubski/32/81494_2.png) [@zalubski](https://forums.kodeco.com/u/zalubski)\
**Post date:** [August 8, 2017, 3:35pm UTC](https://forums.kodeco.com/t/how-to-nest-avspeechsynthisizier-into-sound-file-swif3/33085/1 "2017-08-08T15:35:12Z")

</div>

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)
}}

```

---

<div class="post-metadata">

**Author:** ![nikita\_gaydukov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/nikita_gaydukov/32/77683_2.png) [@nikita\_gaydukov](https://forums.kodeco.com/u/nikita_gaydukov)\
**Post date:** [August 10, 2017, 7:41pm UTC](https://forums.kodeco.com/t/how-to-nest-avspeechsynthisizier-into-sound-file-swif3/33085/2 "2017-08-10T19:41:49Z")

</div>

Hi @zalubski

AVSpeachSynthesizer doesn’t have an API for that, i suggest you to take a look at this answer - [ios - AVSpeechSynthesizer utterance to audio file - Stack Overflow](https://stackoverflow.com/questions/20601824/avspeechsynthesizer-utterance-to-audio-file). It looks quite tricky, but i guess you don’t have much options here.

Nikita

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [January 22, 2018, 7:35am UTC](https://forums.kodeco.com/t/how-to-nest-avspeechsynthisizier-into-sound-file-swif3/33085/3 "2018-01-22T07:35:19Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
