ある多分それが誰かのために参考になる、私は解決策を見つけたが、それは私が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)
}
}
それは私のために動作しませんでした。助言がありますか? –
あなたが使用する言語キーが正しいと確信していますか? –
言語キーに関係なく、システム言語で動作します。 –