flutter_tts icon indicating copy to clipboard operation
flutter_tts copied to clipboard

After setVoice it takes a while until speaking starts

Open desmeit opened this issue 3 years ago • 12 comments

🐛 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 avatar Jun 14 '22 09:06 desmeit

@desmeit is this occurring on Android, iOS, or both? What's the exact name and locale that your setting which takes ~3 seconds?

dlutton avatar Jun 14 '22 18:06 dlutton

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.

desmeit avatar Jun 14 '22 18:06 desmeit

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 avatar Jun 15 '22 10:06 desmeit

@desmeit thanks for the additional information, I'll see if I can troubleshoot this issue.

dlutton avatar Jun 15 '22 18:06 dlutton

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.

holeg avatar Jul 10 '22 16:07 holeg

I experienced the same. On simulator it works perfectly and on the iOS device it is totally slow. Does anybody has a workaround?

alibasta avatar Jan 25 '23 19:01 alibasta

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!

holeg avatar Feb 05 '23 14:02 holeg

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).

matthias-twaiv avatar Feb 22 '23 00:02 matthias-twaiv

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

ColinSeanKavanagh avatar Mar 17 '23 12:03 ColinSeanKavanagh

Did anybody resolve the problem yet?

holeg avatar Jul 11 '23 11:07 holeg

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:

  1. I copied the flutter_tts folder into my project and referenced it instead of using the plugin: flutter_tts: path: "./flutter_tts"
  2. 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.
  3. 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 avatar Sep 27 '23 08:09 holeg

@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.

dlutton avatar Sep 27 '23 19:09 dlutton