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. !!
}
}