setVoice then synthesizeToFile causes iOS emulator to crash
🐛 Bug Report
On iOS, calling setVoice then synthesizeToFile causes the iOS emulator to crash (haven't yet tested on a real iOS device). I created a very simple app on top of the flutter create app to test this...
Usually this happens on the second call to the method:
void makeTts() async { FlutterTts tts = FlutterTts(); setState(() { path = ''; }); final dir = await getApplicationDocumentsDirectory(); try { await tts.setLanguage(locale); if (voiceName.isNotEmpty) { String name = voiceName.split('|').first; String lang = voiceName.split('|').last; if (lang == locale) { log.d(name); await tts.setVoice({'name': name, 'locale': locale}); } } await tts.synthesizeToFile(controller.text, 'text.caf'); } catch (e) { log.e(e); } path = '${dir.path}/text.caf'; setState(() {}); }
The error is: flutter_tts/SwiftFlutterTtsPlugin.swift:210: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.apple.coreaudio.avfaudio Code=1768846202 "(null)" UserInfo={failed call=ExtAudioFileWrite(_imp->_extAudioFile, buffer.frameLength, buffer.audioBufferList)} Lost connection to device.
Expected behavior
I would expect the file to be generated again without the app crashing.
Reproduction steps
Using a dropdown, select the voice and use the value to call setVoice. Synthesize your text to a file, Select a different voice and try to synthesize to the file...
Configuration
Version: FlutterTts 3.8.3
Platform:
- [x] :iphone: iOS
SynthesizeToFile doesn't work on iOS simulator in my experience; test on a real device.
I ended up just changing my code so that it didn't synthesize to a file but called speak() in the end.