dlutton / flutter_tts

Flutter Text to Speech package
MIT License
617 stars 258 forks source link

voice is duplicated on web #537

Open Ammarmahmoud1995 opened 1 month ago

Ammarmahmoud1995 commented 1 month ago

🐛 Bug Report

I have this flutter code that I use to call tts to speak a String , The problem is that on web and if the site is loaded for the first time , It would restart the voice automatically immediately after the first time , so I have to hear it 2 times ! (it works perfectly in iOS , android)

  Future speak({required String textToSpeak}) async {
   // 
        homecontroller. isTTSspeaking = true ;

homecontroller.update();
if(defaultTargetPlatform == TargetPlatform.iOS  && !kIsWeb) 
await homecontroller.flutterTts.setIosAudioCategory(IosTextToSpeechAudioCategory.ambient,
     [
          IosTextToSpeechAudioCategoryOptions.allowBluetooth,
          IosTextToSpeechAudioCategoryOptions.allowBluetoothA2DP,
          IosTextToSpeechAudioCategoryOptions.mixWithOthers
     ],
     IosTextToSpeechAudioMode.voicePrompt
);

    await homecontroller. flutterTts.setVolume(volume);
    await  homecontroller. flutterTts.setSpeechRate(homecontroller.voiceRate);
    await  homecontroller. flutterTts.setPitch(pitch);
    await  homecontroller. flutterTts.speak(textToSpeak);
      homecontroller.isTTSspeaking = false ;

  }

am calling it here , and am using 1 second delay so the tts finish the last call in the previous page

  @override
  void initState() {
    super.initState();
       _setAwaitOptions();
 print("init state is called");
    if( extractLatexSymbols(homecontroller.selectedsectionAI.text!) ) {
isLatexThere = true ;

    }else{
  isLatexThere = false ;    
    }

         Future.delayed(Duration(seconds: 1),(){
 speak(textToSpeak: homecontroller.selectedsectionAI.text?? "") ;
    }) ;

Platform: