Flutter tts全新庫,親測有效

推薦原文: http://tryenough.com/flutter_tts_new

A new Flutter plugin.

Github

Getting Started

English Document (中文文檔在下面)

Use this package as a library

  1. Depend on it 導入
    Add this to your package's pubspec.yaml file:

dependencies:
flutter_plugin_tts: ^1.0.2

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

  1. Import it 導入頭文件
    Now in your Dart code, you can use:
Import 'package:flutter_plugin_tts/flutter_plugin_tts.dart';

Example of use:

@override
  Widget build(BuildContext context) {
    Return MaterialApp(
      Home: Scaffold(
        appBar: AppBar(
          Title: const Text('Plugin example app'),
        ),
        Body: ListView(
          Children: <Widget>[
            RaisedButton(child: const Text('set to Chinese'), onPressed: () {
              FlutterPluginTts.setLanguage('zh-CN').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('set to English'), onPressed: () {
              FlutterPluginTts.setLanguage('en-AU').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('set to Japanese'), onPressed: () {
              FlutterPluginTts.setLanguage('ja-JP').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('play Chinese'), onPressed: () {
              FlutterPluginTts.speak ('Hello, World');
            }),
            RaisedButton(child: const Text('playing English'), onPressed: () {
              FlutterPluginTts.speak('hello,world');
            }),
            RaisedButton(child: const Text('playing Japanese'), onPressed: () {
              FlutterPluginTts.speak('こんにちは, world');
            }),
            RaisedButton(child: const Text), onPressed: () {
              FlutterPluginTts.speak('Hello, World. I am testing a long sentence. You can stop my play by clicking the play pause button below. If I don't stop it means there is still a problem with this stop function. Please Continue to repair. La la la la!');
            }),
            RaisedButton(child: const Text), onPressed: () {
              FlutterPluginTts.stop();
            }),
            RaisedButton(child: const Text('play pause, start new sentence immediately'), onPressed: () {
              FlutterPluginTts.stop();
              FlutterPluginTts.speak('hello,world');
            }),
            RaisedButton(child: const Text('Chinese usability'), onPressed: () {
              FlutterPluginTts.isLanguageAvailable('zh-CN').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('English usability'), onPressed: () {
              FlutterPluginTts.isLanguageAvailable('en-US').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('Japanese usability'), onPressed: () {
              FlutterPluginTts.isLanguageAvailable('ja-JP').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('setSpeechRate = 1'), onPressed: () {
              FlutterPluginTts.setSpeechRate(0.5);
            }),
            RaisedButton(child: const Text('setSpeechRate = 0.5'), onPressed: () {
              FlutterPluginTts.setSpeechRate(0.25);
            }),
            RaisedButton(child: const Text('setSpeechRate = 2'), onPressed: () {
              FlutterPluginTts.setSpeechRate(1);
            }),
          ],
        ),
      ),
    );
  }

Welcome everyone to support my website [website] (https://tryenough.com),

中文文檔

一個支持tts的flutter庫

使用步驟:

導入庫

import 'package:flutter_plugin_tts/flutter_plugin_tts.dart';

使用例子:

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: ListView(
          children: <Widget>[
            RaisedButton(child: const Text('設置成漢語'), onPressed: () {
              FlutterPluginTts.setLanguage('zh-CN').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('設置成英語'), onPressed: () {
              FlutterPluginTts.setLanguage('en-AU').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('設置成日語'), onPressed: () {
              FlutterPluginTts.setLanguage('ja-JP').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('播放漢語'), onPressed: () {
              FlutterPluginTts.speak('你好,世界');
            }),
            RaisedButton(child: const Text('播放英語'), onPressed: () {
              FlutterPluginTts.speak('hello,world');
            }),
            RaisedButton(child: const Text('播放日語'), onPressed: () {
              FlutterPluginTts.speak('こんにちは、世界');
            }),
            RaisedButton(child: const Text('播放長句子'), onPressed: () {
              FlutterPluginTts.speak('你好,世界。我正在測試播放很長的句子,你可以點擊下方的播放暫停按鈕來終止我的播放,如果我沒有停止那就意味着這個停止功能還有問題。請你繼續修復。啦啦啦啦!');
            }),
            RaisedButton(child: const Text('播放暫停'), onPressed: () {
              FlutterPluginTts.stop();
            }),
            RaisedButton(child: const Text('播放暫停,立刻開始新句子'), onPressed: () {
              FlutterPluginTts.stop();
              FlutterPluginTts.speak('hello,world');
            }),
            RaisedButton(child: const Text('中文可用性'), onPressed: () {
              FlutterPluginTts.isLanguageAvailable('zh-CN').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('英文可用性'), onPressed: () {
              FlutterPluginTts.isLanguageAvailable('en-US').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('日文可用性'), onPressed: () {
              FlutterPluginTts.isLanguageAvailable('ja-JP').then((v){
                debugPrint('r = $v');
              });
            }),
            RaisedButton(child: const Text('設置語速爲1正常'), onPressed: () {
               FlutterPluginTts.setSpeechRate(0.5);
            }),
            RaisedButton(child: const Text('設置語速爲0.5'), onPressed: () {
               FlutterPluginTts.setSpeechRate(0.25);
            }),
            RaisedButton(child: const Text('設置語速爲2'), onPressed: () {
               FlutterPluginTts.setSpeechRate(1);
            }),
          ],
        ),
      ),
    );
  }

歡迎大家支持我的網站 網站,

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章