flutter_tts 0.1.0

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

Text To Speech

pub package

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.1.0

  • Updating version for improved maintenance score
  • Updating package description for improved maintenance score

0.0.8

  • Adding analysis_options.yaml for improved health score
  • Fixing info/errors from flutter analyze

0.0.7

  • Updating SDK version in pubspec.yaml
  • Adding package link to README
  • Fixing language string warning received from xcode

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 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_tts/flutter_tts.dart';

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 language;

  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();
  }

  List<DropdownMenuItem<String>> getDropDownMenuItems() {
    var items = new List<DropdownMenuItem<String>>();
    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 == true
                          ? null
                          : () => _speak(),
                      color: Colors.green,
                      splashColor: Colors.greenAccent),
                  new IconButton(
                      icon: new Icon(Icons.stop),
                      onPressed: isStopped == true ? 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 == true
                          ? null
                          : () => _speak(),
                      color: Colors.green,
                      splashColor: Colors.greenAccent),
                  new IconButton(
                      icon: new Icon(Icons.stop),
                      onPressed: isStopped == true ? 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.1.0

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.1.0 Sep 18, 2018 Go to the documentation of flutter_tts 0.1.0 Download flutter_tts 0.1.0 archive
0.0.8 Sep 17, 2018 Go to the documentation of flutter_tts 0.0.8 Download flutter_tts 0.0.8 archive
0.0.7 Aug 22, 2018 Go to the documentation of flutter_tts 0.0.7 Download flutter_tts 0.0.7 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
Popularity:
Describes how popular the package is relative to other packages. [more]
89
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.58.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8