dlutton / flutter_tts

Flutter Text to Speech package
MIT License
602 stars 253 forks source link

[Error]: SetProgressHanlder call back doesn't corresspond to the current spoken word in Android real devices #265

Open duy1998 opened 3 years ago

duy1998 commented 3 years ago

πŸ› Bug Report

Expected behavior

I see a problem with setHandlerProgress call back in the Android real devices. Value's callback doesn't correspond to the spoken word. It invokes a callback so far before speaking.

I'm trying to highlight the spoken text after speak but failed with the long text.

Configuration

[βœ“] Flutter (Channel stable, 2.2.2, on macOS 11.3.1 20E241 darwin-x64, locale en-VN) β€’ Flutter version 2.2.2 at /Users/dinhcongduy1998yahoo.com.vn/Downloads/flutter β€’ Framework revision d79295af24 (9 weeks ago), 2021-06-11 08:56:01 -0700 β€’ Engine revision 91c9fc8fe0 β€’ Dart version 2.13.3

[βœ“] Android toolchain - develop for Android devices (Android SDK version 31.0.0) β€’ Android SDK at /Users/dinhcongduy1998yahoo.com.vn/Library/Android/sdk β€’ Platform android-31, build-tools 31.0.0 β€’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) β€’ All Android licenses accepted.

[βœ“] Xcode - develop for iOS and macOS β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Xcode 12.5.1, Build version 12E507 β€’ CocoaPods version 1.10.1

[βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[βœ“] Android Studio (version 2020.3) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[βœ“] VS Code (version 1.59.0) β€’ VS Code at /Applications/Visual Studio Code.app/Contents β€’ Flutter extension version 3.25.0

[βœ“] Connected device (3 available) β€’ M2101K7AG (mobile) β€’ d71ebe2b β€’ android-arm64 β€’ Android 11 (API 30) β€’ sdk gphone x86 (mobile) β€’ emulator-5554 β€’ android-x86 β€’ Android 11 (API 30) (emulator) β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 92.0.4515.131

Version: 3.2.2

Platform:

dlutton commented 3 years ago

@duy1998 did you have an example you can provide of this failing?

acapper commented 1 year ago

I was able to replicate this using this text.

Version flutter_tts: ^3.5.3

String text = '''
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.''';

FlutterTts flutterTts = FlutterTts();
flutterTts.speak(text);

Usually starts around "Richard McClintock". I am also using a real device and not an emluator.

dlutton commented 1 year ago

thanks @acapper I'll take a look into this issue.

acapper commented 1 year ago

Great. I did a bit of digging myself but there's not a lot to go on. Breaking that text into smaller sections seems to work which to me suggests it's not the text. Also the max length is 4000 and that text is only about a 1000.

I also added some logging locally and noticed that the events in the kotlin file all seem to happen at once before the method that it invokes seems to create an events.

I saw places online mentioning it might be to do with background and UI threads but I'm not familiar enough with Android to test those.

One idea that I did have was to use the frames to delay the event being emitting. As the frame value provides the number of frames since the start of the speech. If a second frame counter was made the event could be emitted only when the seconds frame counter was greater than the onRangeStart frames.