本文介绍了Swift:如何将文本到语音生成的音频转换为.mp3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have converted text to speech using the AVSpeechSynthesizer. When clicked on Play, converted speech plays. I don't know the extension of this audio file.
My goal is to convert this created audio file to .mp3. I have searched in Google but I didn't find anything. Any help is appreciated.

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

My code is here: Convert text to speech

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)

推荐答案

一种简单的策略是先将输出从AVSpeechSynthesizer保存到目录,然后更改其格式.
但是,据我所知AVSpeechSynthesizer不允许您保存输出.我建议您检查以下帖子:将音频流保存到mp3文件(iOS )
引用 IanStallings :

A simple strategy would be saving your output from AVSpeechSynthesizer to a directory first, then changing its format.
But, as far as I know AVSpeechSynthesizer does not let you save your outputs.I would suggest you to check the following post: Save audio stream to mp3 file (iOS)
Quoting from IanStallings:

还有另一个: AVSpeechSynthesizer输出为文件吗?
同样,引用 Bh​​umit Mehta :

这篇关于Swift:如何将文本到语音生成的音频转换为.mp3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:44
查看更多