xftts 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 47

xftts #

Xun Fei TTS dart implementation based on: https://www.xfyun.cn/doc/tts/online_tts/API.html.

Usage #

A simple usage example:

import 'package:xftts/xftts.dart';

main() async {
  // retrieve appId/apiKey/apiSecret
  final env = Platform.environment;
  final app = env["APP"] ?? '1';
  final appId = env['XF_TTS_ID$app'];
  final apiKey = env['XF_TTS_KEY$app'];
  final apiSecret = env['XF_TTS_SECRET$app'];
  
  // initiate the class
  final tts = TTS(appId, apiKey, apiSecret);

  // generate mp3
  text = '''
  君不见黄河之水天上来,奔流到海不复回。
 君不见高堂明镜悲白发,朝如青丝暮成雪。
 人生得意须尽欢,莫使金樽空对月。
 天生我材必有用,千金散尽还复来。
  '''

  await tts.generateMp3ForText(text, '/tmp/test.mp3');
}

0.1.2 #

fix a corner case that websocket get no audio data from server

0.1.1 #

strip strengthen and html comments for markdown doc

0.1.0 #

Initial version, provide basic functionality of xunfei TTS service.

example/xftts_example.dart

import 'dart:io';

import 'package:xftts/xftts.dart';

void main() async {
  final env = Platform.environment;
  final app = env["APP"] ?? '1';
  final appId = env['XF_TTS_ID$app'];
  final apiKey = env['XF_TTS_KEY$app'];
  final apiSecret = env['XF_TTS_SECRET$app'];
  final vcn = env['XF_TTS_VCN'] ?? 'xiaoyan';
  final speed = env['XF_TTS_SPEED'] ?? 70;
  final volume = env['XF_TTS_VOLUME'] ?? 60;
  final tts = TTS(appId, apiKey, apiSecret, vcn: vcn, speed: speed, volume: volume);
  final text = '''
  ## Dart 介绍

  作为一门面向对象的语言,dart[1] 支持 mixin,泛型等高阶功能。

  ![](assets/dart.jpg)

  dart 采用了 async/await 的并发模型,每个 future 对象可以看做是一个独立的 coroutine。

  ```dart
  // some stupid code
  void main() {
    print('hello world!');
  }
  ```

  dart 虽然是静态类型,但它的类型模式和 TypeScript 很类似,类型声明虽然推荐但不强制。
  
  这几天使用下来,觉得 dart 做服务端开发似乎也不错,至少语言的表达能力要比 nodejs 背后的javascript 强。
  
  当然,目前使用 dart 的程序员几乎都是 flutter 程序员,但不排除未来会有类似 javascript -> nodejs
这样的前端逆袭后端的事情发生。

  <!-- skip_start -->
  毕竟,后端程序员的能力不断地被云服务商压扁,一个后台工程师辛辛苦苦攒的服务端代码,分分钟被
firebase 这样的怪兽逆袭。
  <!-- skip_end -->
  ''';
  await tts.generateMp3ForMarkdown(text, '/tmp/test.mp3', splitAt: 600);
  print('Done!');
}

Use this package as a library

1. Depend on it

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


dependencies:
  xftts: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


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

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Analysis suggestions

Package not compatible with runtime flutter-web on Web

Because:

  • package:xftts/xftts.dart that imports:
  • package:xftts/src/tts.dart that imports:
  • dart:io

Package not compatible with runtime js

Because:

  • package:xftts/xftts.dart that imports:
  • package:xftts/src/tts.dart that imports:
  • dart:io

Health suggestions

Format lib/src/tts.dart.

Run dartfmt to format lib/src/tts.dart.

Format lib/src/util.dart.

Run dartfmt to format lib/src/util.dart.

Maintenance suggestions

The package description is too short. (-14 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
crypto >=2.1.4 <3.0.0 2.1.5
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
pedantic ^1.8.0
test ^1.6.0