flutter_tts 0.0.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 83

Text To Speech

A flutter text to speech plugin (Swift,Java)

Features

  • [x] Android & iOS
    • [x] speak
    • [x] stop
    • [x] get languages
    • [x] set language
    • [x] is language available
    • [x] set speech rate
    • [x] set speech volume
    • [x] set speech pitch

Usage

Example

To use this plugin :

  dependencies:
    flutter:
      sdk: flutter
    flutter_tts:
  • instantiate a FlutterTts instance
FlutterTts flutterTts = new FlutterTts();

speak, stop, getLanguages, setLanguage, setSpeechRate, setVolume, setPitch, isLanguageAvailable

Future _speak() async{
    var result = await flutterTts.speak("Hello World");
    if (result == 1) setState(() => ttsState = TtsState.playing);
}

Future _stop() async{
    var result = await flutterTts.stop();
    if (result == 1) setState(() => ttsState = TtsState.stopped);
}

List<dynamic> languages = await flutterTts.getLanguages;

await flutterTts.setLanguage("en-US");

await flutterTts.setSpeechRate(1.0);

await flutterTts.setVolume(1.0);

await flutterTts.setPitch(1.0);

await flutterTts.isLanguageAvailable("en-US");

Listening for platform calls

flutterTts.setStartHandler(() {
  setState(() {
    ttsState = TtsState.playing;
  });
});

flutterTts.setCompletionHandler(() {
  setState(() {
    ttsState = TtsState.stopped;
  });
});

flutterTts.setErrorHandler((msg) {
  setState(() {
    ttsState = TtsState.stopped;
  });
});

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

ChangeLog

0.0.6

  • Android: Upgrading Gradle 4.1 to 4.4
  • Android: Setting minSdk version to 21
  • Android: Adding try/catch to getAvailableLanguages & getDefaultVoice methods (Issues with API 21 & 22)

0.0.5

  • Adding IOS/Android isLanguageAvailable
  • Rename setRate to setSpeechRate

0.0.4

  • Simplify podspec for Cocoapods 1.5.0

0.0.3

  • Adding IOS/Android speech pitch and volume

0.0.2

  • Flutter formatting and fixing pubspec sdk versioning

0.0.1

  • first POC :
    • methods : speak, stop, setRate, setLangauge, getLanguages
    • a globalHandler for completion

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_tts/flutter_tts.dart';
import 'dart:async';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

enum TtsState { playing, stopped }

class _MyAppState extends State<MyApp> {
  FlutterTts flutterTts;
  List<dynamic> languages;

  String _newVoiceText;

  TtsState ttsState = TtsState.stopped;

  get isPlaying => ttsState == TtsState.playing;
  get isStopped => ttsState == TtsState.stopped;

  @override
  initState() {
    super.initState();
    initTts();
  }

  initTts() async {
    flutterTts = new FlutterTts();

    flutterTts.setStartHandler(() {
      setState(() {
        ttsState = TtsState.playing;
      });
    });

    flutterTts.setCompletionHandler(() {
      setState(() {
        ttsState = TtsState.stopped;
      });
    });

    flutterTts.setErrorHandler((msg) {
      setState(() {
        ttsState = TtsState.stopped;
      });
    });

    languages = await flutterTts.getLanguages;
    if (languages != null) setState(() => languages);
  }

  Future _speak() async {
    var result = await flutterTts.speak(_newVoiceText);
    if (result == 1) setState(() => ttsState = TtsState.playing);
  }

  Future _stop() async {
    var result = await flutterTts.stop();
    if (result == 1) setState(() => ttsState = TtsState.stopped);
  }

  @override
  void dispose() {
    super.dispose();
    flutterTts.stop();
  }

  String language;

  List<DropdownMenuItem<String>> getDropDownMenuItems() {
    List<DropdownMenuItem<String>> items = new List();
    for (String type in languages) {
      items.add(new DropdownMenuItem(value: type, child: new Text(type)));
    }
    return items;
  }

  void changedDropDownItem(String selectedType) {
    setState(() {
      language = selectedType;
      flutterTts.setLanguage(language);
    });
  }

  void _onChange(String text) {
    setState(() {
      _newVoiceText = text;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Flutter TTS'),
          ),
          body: languages != null
              ? _buildRowWithLanguages()
              : _buildRowWithoutLanguages()),
    );
  }

  Widget _buildRowWithoutLanguages() => new Column(children: <Widget>[
        new Container(
            alignment: Alignment.topCenter,
            padding: new EdgeInsets.only(top: 25.0, left: 25.0, right: 25.0),
            child: new TextField(
              onChanged: (String value) {
                _onChange(value);
              },
            )),
        new Container(
            padding: new EdgeInsets.only(top: 200.0),
            child: new Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  new IconButton(
                      icon: new Icon(Icons.play_arrow),
                      onPressed: _newVoiceText == null || isPlaying
                          ? null
                          : () => _speak(),
                      color: Colors.green,
                      splashColor: Colors.greenAccent),
                  new IconButton(
                      icon: new Icon(Icons.stop),
                      onPressed: isStopped ? null : () => _stop(),
                      color: Colors.red,
                      splashColor: Colors.redAccent),
                ]))
      ]);

  Widget _buildRowWithLanguages() => new Column(children: <Widget>[
        new Container(
            alignment: Alignment.topCenter,
            padding: new EdgeInsets.only(top: 25.0, left: 25.0, right: 25.0),
            child: new TextField(
              onChanged: (String value) {
                _onChange(value);
              },
            )),
        new Container(
            padding: new EdgeInsets.only(top: 200.0),
            child: new Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  new IconButton(
                      icon: new Icon(Icons.play_arrow),
                      onPressed: _newVoiceText == null || isPlaying
                          ? null
                          : () => _speak(),
                      color: Colors.green,
                      splashColor: Colors.greenAccent),
                  new IconButton(
                      icon: new Icon(Icons.stop),
                      onPressed: isStopped ? null : () => _stop(),
                      color: Colors.red,
                      splashColor: Colors.redAccent),
                  new DropdownButton(
                    value: language,
                    items: getDropDownMenuItems(),
                    onChanged: changedDropDownItem,
                  )
                ]))
      ]);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_tts: "^0.0.6"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


      import 'package:flutter_tts/flutter_tts.dart';
  
Version Uploaded Documentation Archive
0.0.6 May 6, 2018 Go to the documentation of flutter_tts 0.0.6 Download flutter_tts 0.0.6 archive
0.0.5 May 1, 2018 Go to the documentation of flutter_tts 0.0.5 Download flutter_tts 0.0.5 archive
0.0.4 Apr 19, 2018 Go to the documentation of flutter_tts 0.0.4 Download flutter_tts 0.0.4 archive
0.0.3 Apr 17, 2018 Go to the documentation of flutter_tts 0.0.3 Download flutter_tts 0.0.3 archive
0.0.2 Apr 14, 2018 Go to the documentation of flutter_tts 0.0.2 Download flutter_tts 0.0.2 archive
0.0.1 Apr 14, 2018 Go to the documentation of flutter_tts 0.0.1 Download flutter_tts 0.0.1 archive

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3
  • Flutter: 0.5.4

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
67 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
83
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <=2.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.10
meta 1.1.5
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6 2.0.7