Post

Replies

Boosts

Views

Activity

AVSpeechSynthesizer delegate breaks speech
Setting AVSpeechSynthesizer.delegate = self breaks french hyphenated words. e.g. “parlez-vous” will be pronounced “parlez”, "attendez-vous" will be pronounced "attendez", "est-ce que'il est la?" will be pronounced "est que'il est la?" "Puis-je vous voir demain?" will be pronounced "Puis vous voir demain?" If you listen you can tell that the second word is silent ... like there seems to be the correct space left for it. I have sent feedback FB 11968008 to Apple. No problem in the simulator - this is a device only problem occuring on these devices. iPhone 11 iOS 16.2, iPhone 8 iOS 16.1.2, iPad Air2 iOS 15.7.2, Xcode 14.2 Any thoughts? Example code: import SwiftUI import Speech struct ContentView: View { var synth = SpeechSynthesizer() @State var isDelegateSet = true var sentences: [String] = [ "Parlez-vous ", "attendez-vous ", "est-ce qu'il est la?", "Puis-je vous voir demain?" ] var body: some View { VStack { List { ForEach(sentences.indices, id: \.self) { index in Button(sentences[index]) { synth.toggleAVSpeechSynthesizerDelegate(isDelegateSet: isDelegateSet) synth.speak(string: sentences[index]) } } Toggle("toggle AVSpeechSynthesizer delegate", isOn: $isDelegateSet) Text(isDelegateSet ? "AVSpeechSynthesizer.delegate = self \nSpeech is INCORRECT " : "AVSpeechSynthesizer.delegate = nil \nSpeech is correct") .padding() } } } } class SpeechSynthesizer: NSObject, ObservableObject, AVSpeechSynthesizerDelegate { var synthesizer = AVSpeechSynthesizer() var utterance = AVSpeechUtterance(string: "") override init() { super.init() synthesizer.delegate = self } func speak(string: String) { synthesizer.stopSpeaking(at: .immediate) utterance = AVSpeechUtterance(string: string) utterance.voice = AVSpeechSynthesisVoice(language: "fr-FR") synthesizer.speak(utterance) } func toggleAVSpeechSynthesizerDelegate(isDelegateSet: Bool) { if isDelegateSet { synthesizer.delegate = self } else { synthesizer.delegate = nil } } func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance) { // if synthesizer.delegate = self , phrases are spoken incorrectly. !! // if synthesizer.delegate = nil , phrases are spoken correctly as delegates are not called. !! } }
0
0
592
Jan ’23
AVSpeechSynthesizer is describing certain words rather than just speaking them
Problem: AVSpeechSynthesiser sometimes describes words rather than just speaking them as a real person would. When speaking in English AVSpeechSynthesiser pronounces the word "A" on its own as "Capital A", while the phrase "A little test" is pronounced correctly. A workaround of lowercasing the speech string - so "A" becomes "a" fixes this specific example. (I'm not yet sure if lowercasing sentences could affect pronunciation badly in some instances.) A more serious example: When speaking French the word "allé" on its own is pronounced by AVSpeechSynthesiser as "allé - e accent aigu" (accent aigu = acute accent). And here the problem exists even when the word is part of a sentence! With "Je suis allé au cinéma" (I went to the cinema) AVSpeechSynthesiser says "Je suis allé e accent aigu au cinéma" which is clearly wrong and unhelpful. Is there a way to fix this?
0
0
644
Jun ’22