Swift:如何将文本转语音生成的音频转换为 .mp3?

Swift: How to Convert Text-to-Speech Generated Audio to .mp3?

我已经使用 AVSpeechSynthesizer 将文本转换为语音。单击播放时,将播放转换后的语音。我不知道此音频文件的扩展名。
我的目标是将此创建的音频文件转换为 .mp3。我在 Google 中搜索过,但没有找到任何内容。任何帮助表示赞赏。

我的代码在这里:将文本转换为语音

text = UserDefaults.standard.string(forKey: "TextString")!
voice = selectCountryDic["Clanguage"]!
let speechText = AVSpeechUtterance(string:text)
speechText.voice = AVSpeechSynthesisVoice(language:voice)

let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(speechText)

2021-02-20更新:
现在这是可能的。请查看主题:AVSpeechSynthesizer output as file?

2017年答案(已过时):
一个简单的策略是先将 AVSpeechSynthesizer 的输出保存到一个目录,然后更改其格式。
但是,据我所知,AVSpeechSynthesizer 不允许您保存输出。 我建议您检查以下 post:Save audio stream to mp3 file (iOS)
引自 IanStallings:

Unfortunately no, there is no public API available to capture the speaker output, and looking over the docs for AVSpeechSynthesizer and related classes I don't see a way to capture any audio from it. You may want to look at 3rd party libraries to help with this.

还有一个:AVSpeechSynthesizer output as file?
再次引用 Bhumit Mehta:

As of now AVSpeechSynthesizer does not support this. There is no way to get the audio file using AVSpeechSynthesizer. I tried this a few weeks ago for one of my apps and found out that it is not possible, Also nothing has changed for AVSpeechSynthesizer in iOS 8.