dlutton / flutter_tts

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

Audio playing doen't work when Internet goes off #136

Open chazgps opened 4 years ago

chazgps commented 4 years ago

🐛 Bug Report

I call the speak method inside build method in response to app state change. If the Internet connection is down, the audio isn't played and nothing happens. To work properly, I must turn on Internet on my device.

Reproduction steps

To reproduce the problem:

  1. Start your app
  2. Initialize TTS
  3. Turn off Internet on device
  4. call the speak method

Nothing happens.

Version: 0.1.x Flutter: 1.17.5 Dart: 2.8.4

Platform:

dlutton commented 4 years ago

Do you have the google TTS engine installed on the device?

chazgps commented 4 years ago

Sure, I do, I said that works properly when Internet is turned on the device!

I call the "speak" method during the "build" method execution. If I turn off the Internet, the "speak" method doen't work anymore.

I've tried to put the "speak" method calling into a isolate, to free the main isolate (UI) from speech synthesis but the plugin doen't work from a isolate:

My isolate:

Future<void> speak(String text){ FlutterTts _flutterTts = FlutterTts(); _flutterTts.setLanguage('pt-BR'); _flutterTts.setVolume(1.0); _flutterTts.setPitch(1.0); _flutterTts.speak(text); }

and the result when running it with 'compute':

E/flutter (10437): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized. E/flutter (10437): If you're running an application and need to access the binary messenger beforerunApp()has been called (for example, during plugin initialization), then you need to explicitly call theWidgetsFlutterBinding.ensureInitialized()first. E/flutter (10437): If you're running a test, you can call theTestWidgetsFlutterBinding.ensureInitialized()as the first line in your test'smain()method to initialize the binding. E/flutter (10437): #0 defaultBinaryMessenger.<anonymous closure> (package:flutter/src/services/binary_messenger.dart:76:7) E/flutter (10437): #1 defaultBinaryMessenger (package:flutter/src/services/binary_messenger.dart:89:4) E/flutter (10437): #2 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:140:62) E/flutter (10437): #3 MethodChannel.setMethodCallHandler (package:flutter/src/services/platform_channel.dart:375:5) E/flutter (10437): #4 new FlutterTts (package:flutter_tts/flutter_tts.dart:109:14) E/flutter (10437): #5 speak (package:sepvol/pages/separa_volume_page.dart:426:28) E/flutter (10437): #6 _IsolateConfiguration.apply (package:flutter/src/foundation/_isolates_io.dart:75:34) E/flutter (10437): #7 _spawn.<anonymous closure> (package:flutter/src/foundation/_isolates_io.dart:83:65) E/flutter (10437): #8 Timeline.timeSync (dart:developer/timeline.dart:163:22) E/flutter (10437): #9 _spawn (package:flutter/src/foundation/_isolates_io.dart:80:18) E/flutter (10437): #10 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:304:17) E/flutter (10437): #11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

chazgps commented 4 years ago

My main():

`void main() async { WidgetsFlutterBinding.ensureInitialized();

final PackageInfo packageInfo = await PackageInfo.fromPlatform(); final App app = App(); app.version= packageInfo.version; `final MultiProvider providers = MultiProvider( providers: [ ChangeNotifierProvider.value( value: app, ), ChangeNotifierProvider.value( value: Repository.instance, ), ], child: MyApp(), ); runApp(providers); }

dlutton commented 4 years ago

Are you using a specific device/emulator and certain API level? As long as I have the TTS engine installed on my device, I can run the speak method successfully with the internet off.

aarzhou commented 4 years ago

I am having the same issue. I am using Samsung Table A. I downloaded both Google and Samsung Text-to-speech engine (seems that the tablet comes with Google English-US pre-downloaded, because I don't see the download button there -- unlike other languages). But when I turn off the wifi, it will throw an exception saying:

[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: SocketException: Connection failed (OS Error: Network is unreachable, errno = 101), address = 192.168.0.101, port = 3000

I use everything as default. Simply initialize tts and call speak:

FlutterTts tts = FlutterTts();
await tts.speak("Hello");

Is there anyway to force it use a downloaded voice engine?

Thanks very much!