我正在做一个文字朗读任务。在其中我面临的问题是,例如,如果我得到文本:Hello everyone. 2 minutes to go.
然后使用下面的代码进行语音合成器,它将整个文本视为一个句子,并且在Hello everyone.
. 它把整个文本说成一个句子,就像没有. (full stop)
后面一样Hello everyone
。仅当标点符号后有数字时才会发生这种情况 . (full stop)
let utterance = AVSpeechUtterance(string: "Hello everyone. 2 minutes to go.")
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
utterance.rate = AVSpeechUtteranceDefaultSpeechRate
synthesizer.speak(utterance)
如果您担心我如何初始化会话和合成器,那么这里是下面的代码:
let synthesizer = AVSpeechSynthesizer()
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayback, with: .duckOthers)
try session.setActive(true)
} catch {
print(error.localizedDescription)
}