flutter_tts icon indicating copy to clipboard operation
flutter_tts copied to clipboard

[Android] Number being read individually instead of as one

Open AkshatGiri opened this issue 4 years ago • 4 comments

🐛 Bug Report

I'm passing a string like so "1 5 15" to the tts.speak(). On android it is being read as "One Five One Five".

Expected behavior

It should be read as "One Five Fifteen". That's the behavior on iOS and web. If we pass "15" by itself it is read as expected on android.

Reproduction steps

await _flutterTts.speak("1 5 15");

Configuration

Version: 1.2.0

Platform:

  • [ ] :iphone: iOS
  • [x] :robot: Android

AkshatGiri avatar May 25 '20 08:05 AkshatGiri

@AkshatGiri Which Android API and device/emulator are you using?

dlutton avatar May 25 '20 18:05 dlutton

@dlutton I'm running on Android 10 on a Pixel 2 XL.

AkshatGiri avatar May 25 '20 18:05 AkshatGiri

I am able to reproduce this issue, however I'm not able to locate a reason for the google TTS engine to behave this way. You may want to separate the number values by commas until I'm able to locate both the reason for this and possible solution.

dlutton avatar Jun 03 '20 08:06 dlutton

I had done something like this in case someone else faces the same issue

final numToWord = {
  "0": "Zero",
  "1": "One",
  "2": "Two",
  "3": "Three",
  "4": "Four",
  "5": "Five",
  "6": "Six",
  "7": "Seven",
  "8": "Eight",
  "9": "Nine",
};


Future sayNum(int val) async {
    final valString = val.toString();
    if (valString.length == 1) {
      return await _flutterTts.speak("Single number $valString");
    }

    final splitVal = valString.split("");
    return await _flutterTts.speak(
        "${numToWord[splitVal[0]]} ${numToWord[splitVal[1]]} $valString");
  }

AkshatGiri avatar Jun 10 '20 19:06 AkshatGiri