@tyrchen/xftts

0.1.1 • Public • Published

Xunfei TTS

This small buggy library is to support websocket interface of Xunfei TTS. It is only used for my pet projects, not scalable, nor robust. Use it at your own risk.

Usage

yarn add @tyrchen/xftts

Once you have added the package into your project, you could use it like this:

const { TTS } = require('@tyrchen/xftts');

const env = process.env;
const app = env.APP || '1';
const appId = env[`XF_TTS_ID${app}`];
const apiSecret = env[`XF_TTS_SECRET${app}`];
const apiKey = env[`XF_TTS_KEY${app}`];
const filename = '/tmp/test.mp3';
const text = `作为一门面向对象的语言,dart 支持 mixin,泛型等高阶功能。dart 采用了 async/await 的并发模型,
每个 future 对象可以看做是一个独立的 coroutine。dart 虽然是静态类型,但它的类型模式和 TypeScript 很类似,
类型声明虽然推荐但不强制。这几天使用下来,觉得 dart 做服务端开发似乎也不错,至少语言的表达能力要比 nodejs 背后的
javascript 强。当然,目前使用 dart 的程序员几乎都是 flutter 程序员,但不排除未来会有类似 javascript -> nodejs
这样的前端逆袭后端的事情发生。毕竟,后端程序员的能力不断地被云服务商压扁,一个后台工程师辛辛苦苦攒的服务端代码,分分钟被
firebase 这样的怪兽逆袭。`;

async function main() {
    try {
        const tts = new TTS(appId, apiKey, apiSecret, { speed: 70 });
        await tts.generate(text, filename);
        console.log('generated: ', filename);
        process.exit(0);
    } catch (error) {
        console.error(error);
        process.exit(0);
    }
}

main()

You could find the API id, key and secret from Xunfei web console. Note that the websocket protocol has a max size 8k of the payload, so make sure you split your text if the source is too long.

Readme

Keywords

Package Sidebar

Install

npm i @tyrchen/xftts

Weekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

7.05 kB

Total Files

4

Last publish

Collaborators

  • tyrchen