flutter_tts icon indicating copy to clipboard operation
flutter_tts copied to clipboard

setVoice then synthesizeToFile causes iOS emulator to crash

Open bcaspe opened this issue 2 years ago • 2 comments

🐛 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

bcaspe avatar Oct 10 '23 19:10 bcaspe

SynthesizeToFile doesn't work on iOS simulator in my experience; test on a real device.

Colton127 avatar Oct 12 '23 20:10 Colton127

I ended up just changing my code so that it didn't synthesize to a file but called speak() in the end.

bcaspe avatar Nov 29 '23 22:11 bcaspe