loushou / flutter_tts_improved

A fork of the Flutter_TTS (https://github.com/dlutton/flutter_tts) plugin, that uses the progress reporters of the Utterance APIs, on both Android and iOS.
MIT License
10 stars 5 forks source link

flutter_tts_improved support on gphonex86arm mobile emulator #6

Open starzar opened 3 years ago

starzar commented 3 years ago

For crossplatform apps (Android/Windows desktop) , Android Studio(Windows10/64bit) runs scripts on Windows/Gphonex86arm mobile emulator.

On running a Flutter_tts_improved package script for a text-to-speech supported crossplatform app, the Gphonex86arm mobile emulator doesn't recognise tts supported languages and voices .

On trying to switch to the Pixel-android emulator ,AndroidStudio defaults to Gphonex86arm emulator.

Is there any way to run the tts engine without having to uninstall the Windows/ Gphonex86arm emulator ?

ERROR :

W/TextToSpeech( 6955): isLanguageAvailable failed: not bound to TTS engine
W/TextToSpeech( 6955): getVoices failed: not bound to TTS engine
D/TTS     ( 6955): getVoices: Attempt to invoke interface method 'java.util.Iterator java.util.Set.iterator()' on a null object reference

CODE :

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_tts_improved/flutter_tts_improved.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  u/override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  FlutterTtsImproved tts = FlutterTtsImproved();

  u/override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    await tts.setLanguage("en-US");
    await tts.setSpeechRate(1.0);
    await tts.setVolume(1.0);
    await tts.setPitch(1.0);

    print('VOICES: ${await tts.getVoices}');
    print('LANGUAGES: ${await tts.getLanguages}');

    tts.setProgressHandler((String words, int start, int end, String word) async{

      setState(() {
        _platformVersion = word;
      });
      print('PROGRESS: $word => $start - $end');
    });
  }

  u/override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(bottom: 20),
                child: RaisedButton(
                  onPressed: () {
                    tts.speak('say something that we can debug please');
                  },
                  child: Text('Say Something...'),
                ),
              ),
              Text('Running on: $_platformVersion\n'),
            ],
          ),
        ),
      ),
    );
  }
}
starzar commented 3 years ago

I do not have access to an Android phone right now,so just wanted to confirm if it was possible to run tts on an emulator.