[Mac OS] Crash with Out Of Bound exception
🐛 Bug Report
On Mac OS when I'm trying to play Il mattino ha l' oro in bocca. the plugin crash with out of bound exception.
After debugging it appears that the system sends negative length within the range for the last character:

Unfortunately, I haven't found any documentation about the negative values and I wonder why it doesn't happen for other languages (well, not yet).
Expected behavior
It doesn't crash
Reproduction steps
Just try to play the phrase from the description on Mac OS.
Configuration
Version: 1.2.7
Platform:
- [ ] :iphone: iOS
- [ ] :robot: Android
- [*] Mac OS 10.15.6 (Catalina)
Stacktrace
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString substringWithRange:]: Range {29, 18446744073709551586} out of bounds; string length 30'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff39542b57 __exceptionPreprocess + 250
1 libobjc.A.dylib 0x00007fff723b35bf objc_exception_throw + 48
2 CoreFoundation 0x00007fff395f159e -[__NSCFString characterAtIndex:].cold.1 + 0
3 CoreFoundation 0x00007fff395f16ac -[__NSCFString hasPrefix:].cold.1 + 0
4 CoreFoundation 0x00007fff394b4720 -[NSConstantDictionary objectForKey:] + 0
5 flutter_tts 0x0000000110a1283c $s11flutter_tts16FlutterTtsPluginC17speechSynthesizer_28willSpeakRangeOfSpeechString9utteranceySo08AVSpeechG0C_So8_NSRangeVSo0O9UtteranceCtF + 844
6 flutter_tts 0x0000000110a12a5d $s11flutter_tts16FlutterTtsPluginC17speechSynthesizer_28willSpeakRangeOfSpeechString9utteranceySo08AVSpeechG0C_So8_NSRangeVSo0O9UtteranceCtFTo + 109
7 AXSpeechImplementation 0x00007fff2c3bd06d -[AVSpeechSynthesizer(Implementation) _handleSpeechWordCallback:wordRange:channel:] + 760
8 libdispatch.dylib 0x00007fff735016c4 _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x00007fff73502658 _dispatch_client_callout + 8
10 libdispatch.dylib 0x00007fff7350dcab _dispatch_main_queue_callback_4CF + 936
11 CoreFoundation 0x00007fff39505e81 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
12 CoreFoundation 0x00007fff394c5c87 __CFRunLoopRun + 2028
13 CoreFoundation 0x00007fff394c4e3e CFRunLoopRunSpecific + 462
14 HIToolbox 0x00007fff380f1abd RunCurrentEventLoopInMode + 292
15 HIToolbox 0x00007fff380f17d5 ReceiveNextEventCommon + 584
16 HIToolbox 0x00007fff380f1579 _BlockUntilNextEventMatchingListInModeWithFilter + 64
17 AppKit 0x00007fff36737039 _DPSNextEvent + 883
18 AppKit 0x00007fff36735880 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1352
19 AppKit 0x00007fff3672758e -[NSApplication run] + 658
20 AppKit 0x00007fff366f9396 NSApplicationMain + 777
do you have the code snippet you're running when receiving this error and the language this is crashing with?
I've faced it the first time with Italian Il mattino ha l' oro in bocca. The code snippet is quite simple:
class TtsService {
var tts = FlutterTts();
Future speak(
{@required String text,
double rate = 0.5,
double pitch = 0.5,
@required Language language}) async {
await tts.setSpeechRate(rate);
await tts.setPitch(pitch);
await tts.setLanguage(language.ttsCode);
await tts.speak(text);
return;
}
}
ttsCode for Italian is it in my case.
I was able to recreate the issue. It's interesting that removing ha from your sentence results in a successful utterance. I'll continue to look into the issue.
Hey ;)
Got the same issue in prod with someone having the Mac M1 with the latest IOS 14.5 (it's funny in my crashlytics log he is consider as an iPad) with version 3.0.0 of TtsFlutter
Fatal Exception: NSInvalidArgumentException
-[__NSCFString substringWithRange:]: Range {37, 18446744073709551578} out of bounds; string length 45
0 CoreFoundation (Missing)
3 CoreFoundation (Missing)
4 Runner SwiftFlutterTtsPlugin.swift - Line 381 specialized SwiftFlutterTtsPlugin.speechSynthesizer(_:willSpeakRangeOfSpeechString:utterance:) + 381
5 Runner <compiler-generated> - Line 0 @objc SwiftFlutterTtsPlugin.speechSynthesizer(_:willSpeakRangeOfSpeechString:utterance:)
My app is reading sentence in Thai. (I don't have the sentence he was reading). Did you find any issue or fix for this ?
Thanks
@JobiJoba it's an issue that was addressed in the ios forums. I'll have to see if there is a work around until it's fixed.
ok 👍
I try on a Mac M1 without the beta version of iOS and it crash also but play the sentence...
I do experience the same thing on my M1 Macbook as well as on several iPad Air 2020 .