2017-02-23 2 views
0

내 앱에서 AVSpeechSynthesizer를 사용하고 있습니다. 텍스트 연설은 러시아어입니다. 시스템 언어를 영어로 변경하려고 할 때 문제가 있습니다. 영어 억양으로 발음하는 텍스트는 러시아어 언어처럼 들립니다. 이 문제를 어떻게 관리 할 수 ​​있습니까? 여기 AVSpeechSynthesizer 언어

이 누군가에게 도움이 될 것입니다 몇 가지 코드 어쩌면

utterance.voice = AVSpeechSynthesisVoice(language: "ru-Ru") 
    synthesizer.pauseSpeaking(at: .word) 
    utterance = AVSpeechUtterance(string: "Какой-то текст который нужно произнести") 
    synthesizer.speak(utterance) 

답변

0

이다, 나는 해결책을 찾았지만, 그것이 내가 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) 
} 

} 나를 위해 작동하지 않았다

+0

. 어떤 제안? –

+0

사용하는 언어 키가 맞는지 확실합니까? –

+0

언어 키와 관계없이 시스템 언어와 함께 작동합니다. –

관련 문제