xfyun-nls
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

XFYun NLS

js-standard-style action license NPM version npm download

讯飞云智能语音处理 Node 模块。

目录

开始

from npm

$ npm install xfyun-nls

在线语音合成

用例

const { XFYunTTS } = require('xfyun-nls');
const path = require('path');
const fs = require('fs');

!(async () => {
  const cachePath = path.join(process.cwd(), new Date().getTime().toString());
  fs.mkdirSync(cachePath);

  const _xfyTTS = new XFYunTTS(
    {
      appId: '5e3b7ffe',
      apiSecret: '8440c6f3dc6e3b864a043dbb6c37afd0',
      apiKey: '1394021f9ef53a9a9400b4d8a5f4652a',
      host: 'tts-api.xfyun.cn',
      uri: '/v2/tts',
      hostUrl: 'wss://tts-api.xfyun.cn/v2/tts'
    } /** XFYunTTS.Config **/,
    cachePath /** catchPath (optional) **/
  );

  // send
  console.log('TTS COMPLETE:', JSON.stringify(await _xfyTTS.send('你好')));
  // more ...
})();

了解更多 TTS Define.

函数

XFYunTTS 有如下方法:

checkConfig(): Promise<boolean>

返回值 Promise<boolean> - 返回讯飞云语音配置密钥是否有效。

const checkRlt = await _XFYunTTS.checkConfig();
console.log(checkRlt ? 'the config is passed' : 'error config');

send(text: string, options?: XFYunTTS.BusinessOption): Promise<XFYunTTS.TTSComplete>

  • text string - 要转换的文本。
  • options XFYunTTS.BusinessOption (optional) - 合成设置。

返回值 Promise<XFYunTTS.TTSComplete> - 转换完成对象。

定义

XFYunTTS.BusinessOption

合成语言的业务参数,有如下参数:

  • tte string - 文本编码格式。
  • aux string - 音频编码。
  • vcn string - 发音人。

更多请看定义 BusinessOption

官方文档参考

XFYunTTS.TTSComplete

合成结果对象,有如下属性:

  • filePath string - 音频文件最终保存路径。
  • suffix string - 文件后缀。
  • rootPath string - 所在父文件夹路径。
  • text string - 合成的原文本。
  • options XFYunTTS.BusinessOption - 合成的高级选项。
  • startTime number - 合成任务开始的时间戳(毫秒)。
  • elapsed number - 合成所耗费的时间(毫秒)。

更多请看定义 TTSComplete

Author

twitter/funnyzak
funnyzak

参考

License

Apache-2.0 License © 2021 funnyzak

Dependencies (4)

Dev Dependencies (15)

Package Sidebar

Install

npm i xfyun-nls

Weekly Downloads

13

Version

0.2.4

License

Apache 2.0

Unpacked Size

34.9 kB

Total Files

7

Last publish

Collaborators

  • funnyzak