在我的应用程序中,我使用的是AVSpeechSynthesizer,文本语音是俄语,问题是当我将系统语言更改为英语时,文本发音带有英语口音,听起来像俄语的转录。我该如何处理这个问题?
下面是一些代码
utterance.voice = AVSpeechSynthesisVoice(language: "ru-Ru")
synthesizer.pauseSpeaking(at: .word)
utterance = AVSpeechUtterance(string: "Какой-то текст который нужно произнести")
synthesizer.speak(utterance)发布于 2017-02-23 16:32:05
也许它会对某些人有帮助,我找到了解决方案,但它看起来像是在说话之前我改变了AppLanguage的变通办法,这是代码
UserDefaults.standard.set(["ru"], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
utterance.voice = AVSpeechSynthesisVoice(identifier: "ru-RU")同步之后,AVSpeechSynthesisVoice.currentLanguageCode()变成了"ru“,忽略了系统语言
以下是土耳其语的完整代码示例
导入UIKit
导入AVFoundation
类ViewController: UIViewController {
let synthesizer : AVSpeechSynthesizer = AVSpeechSynthesizer()
var utterance : AVSpeechUtterance = AVSpeechUtterance(string: "")
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.set(["tr"], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: .interruptSpokenAudioAndMixWithOthers)
utterance.voice = AVSpeechSynthesisVoice(identifier: "tr-TR")
synthesizer.pauseSpeaking(at: .word)
testSpeech()
}
private func testSpeech() {
utterance = AVSpeechUtterance(string: "Çeviri için deney metni")
speak()
}
private func speak() {
if synthesizer.isSpeaking {
synthesizer.pauseSpeaking(at: .immediate)
return
}
synthesizer.speak(utterance)
}}
https://stackoverflow.com/questions/42409968
复制相似问题