After setVoice it takes a while until speaking starts
🐛 Bug Report
The user should be able to choose the voice. For this I output a list with the voices of the language. In German it takes a while until the language is set and the voice speaks only after 3 seconds. This only happens in German. With English voices this issue does not occur.
Future setVoice(Map voice) async {
await flutterTts
.setVoice({"name": voice['name'], "locale": voice['locale']});
}
await flutterTts.speak(text);
Any ideas?
Thanks
@desmeit is this occurring on Android, iOS, or both? What's the exact name and locale that your setting which takes ~3 seconds?
Hi, thanks for your answer. I tested it on IOS but I can test it tomorrow on Android as well. The names are Helena and Martin de_DE. Anna seems okay.
yes, in Android it takes also a long time until it begins to speak. I think its a general issue and has nothing to do with german voices. It seems that it generally takes a long time to switch to another voice. However, I have seen in other apps that it works without the delay.
@desmeit thanks for the additional information, I'll see if I can troubleshoot this issue.
I have the same problem. On Android it is general a bit slower but on iOS it haas an enormous delay with german voice. The same on a native App (using AVSpeechSynthesizer) works perfect. It happens only with german voice and on device. On simulator everything works fine.
I experienced the same. On simulator it works perfectly and on the iOS device it is totally slow. Does anybody has a workaround?
The problem still exists. You can easily reproduce it with your example app:
- Select fr-FR as language
- Write "Bonjour"
- Tap the "Play" button => it speaks immediately
- Now select "de-DE" as language
- Write "Guten Tag"
- Tap on "Play" button => It takes 2 seconds and then it speaks
This only happens with German voice. As I wrote earlier. When I do the same thing in Swift it works perfect without delay:
func speak(_ phrase:Phrase) { if phrase.speakingText.count > 0 { self.state = .playing speaking = true DispatchQueue.main.async { NotificationCenter.default.post(name: .AudioPlayerSpeakItemNotification, object: self.lesson) }
//print ("speakingAttributedText:",phrase.speakingAttributedText)
let utterance = AVSpeechUtterance(attributedString: phrase.speakingAttributedText)
utterance.voice = AVSpeechSynthesisVoice(language: phrase.locale)
utterance.rate = UserDefaults.standard.speechRate
utterance.pitchMultiplier = UserDefaults.standard.speechPitchMultiplier
synth.speak(utterance)
}
}
Pleas Help!
I see the same problem with German voices, but only on some iOS devices. When the 2-3 second delay happens, it happens every time speak() is called (i.e. not only the first time).
We have the same problem. As we develop an app for German users that can not read, it is critical to us. Interestingly the older German sound packages are working fast, but sound very bad. Any other language works fine.
3 seconds delay:
- {locale: de-DE, name: Anna}
- {locale: de-DE, name: Martin}
- {locale: de-DE, name: Helena}
fast (but old):
- {locale: de-DE, name: Sandy}
- {locale: de-DE, name: Shelley}
- {locale: de-DE, name: Grandma}
- {locale: de-DE, name: Grandpa}
- {locale: de-DE, name: Eddy}
- {locale: de-DE, name: Reed}
- {locale: de-DE, name: Rocko}
- {locale: de-DE, name: Flo}
(edit) It seems to be a known issue, see: https://developer.apple.com/forums/thread/715339
Did anybody resolve the problem yet?
I have some good News!
Under iOS 17 it is better, just a few milliseconds delay. But because I didn't want to release my app only for iOS 17 and above I started to experiment and found a solution:
- I copied the flutter_tts folder into my project and referenced it instead of using the plugin: flutter_tts: path: "./flutter_tts"
- Then in the file SwiftFlutterTtsPlugin.swift I deleted all the delegat functions except public func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance). Because I don't need this functions.
- VOILA => It works. It seems that the delegate makes the problems. It also works if you comment out or delete the following line:
synthesizer.delegate = self
But then it is not possible to be notified when a phrase is finished.
EDIT: It is only the delegate function
public func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance)
When this is commented out, the delay is gone.
@holeg thanks for your input, I'll test around this and maybe we can add a parameter around this to enable or disable it for iOS.