0.3.8 • Published 4 years ago
aliyun-nls v0.3.8
AliYun NLS
阿里云智能语音处理 Node 模块。
目录
开始
from npm
$ npm install/aliyun-nls长文本语音合成
用例
const { AliyunTTS } = require(/aliyun-nls');
!(async () => {
const _aliyunTTS = new AliyunTTS(
{
accessKeyId: 'accessKeyId',
accessKeySecret: 'accessKeySecret',
endpoint: 'https://nls-meta.cn-shanghai.aliyuncs.com',
nlsUrl: 'https://nls-gateway.cn-shanghai.aliyuncs.com/rest/v1/tts/async',
apiVersion: '2019-02-28'
},
'app key' /** optional **/
);
// test aliyun api config
console.log((await _aliyunTTS.checkConfig()) ? 'passed' : 'error');
// more ...
})();了解更多 TTS Define.
函数
AliyunTTS 有如下方法:
checkConfig(): Promise<boolean>
返回值 Promise<boolean> - 返回阿里云语音配置密钥是否有效。
const checkRlt = await _aliyunTTS.checkConfig();
console.log(checkRlt ? 'the config is passed' : 'error config');task(text: string, options?: AliyunTTS.TTSOption): Promise<string>
textstring - 要转换的文本。optionsNLSOption (optional) - 高级设置。appKeystring (optional) - 应用 key。
返回值 Promise<string> - 返回转换任务 ID。
status(taskId: string, appKey?: string): Promise<AliyunTTS.TTSComplete>
查询转换状态。
taskIdstring - 任务 ID。appKeystring (optional) - 应用 Key。
返回值 Promise<AliyunTTS.TTSComplete> - 转换状态。
const taskId = await _aliyunTTS.task('你好,世界!', {
/** options **/
});
console.log(taskId);taskSync(text: string, options: AliyunTTS.TTSOption, interval?: number): Promise<AliyunTTS.TTSComplete>;
同步返回合成结果。
textstring - 要转换的文本。optionsNLSOption - 高级设置。intervalnumber (optional) - 检查转换状态的轮训事件间隔(秒)。
返回值 Promise<AliyunTTS.TTSComplete> - 转换状态。
const rlt = await _aliyunTTS.taskSync('你好,世界!', {
format: 'mp3'
sample_rate: 16000,
voice: 'xiaoyun',
volume: 50,
speech_rate: 50,
pitch_rate: 50
/* options */
});
console.log('complete result => ', JSON.stringify(rlt));定义
AliyunTTS.TTSOption
appKey- 应用 Key,可选。format- 音频编码格式,支持 pcm/wav/mp3 格式,默认是 pcm。sample_rate- 音频采样率,支持 16000Hz 和 8000Hz,默认是 16000Hz。voice- 发音人,默认是 xiaoyun。更多发音人请参见接口说明。volume- 音量,范围是 0~100,默认 50。speech_rate- 语速,范围是 0-100,默认是 50。pitch_rate- 语调,范围是 0-100,默认是 50。enable_subtitle- 是否启用句级时间戳功能,默认值为 false。enable_notify- 是否启用回调功能,默认值为 false。notify_url- 回调服务的地址。当 enable_notify 取值为 true 时,本字段必填。URL 支持 HTTP/HTTPS 协议,Host 不能使用 IP 地址。
AliyunTTS.TTSComplete
task_idstring - 任务 ID。audio_addressstring - 合成的音频 URL。notify_customstring - 回调地址。sentencesjson - 句级时间戳对象。appKey: string - 使用的 APP Key。options: AliyunTTS.TTSOption - 合成选项。text: string - 待合成文本。startTime: number - 合成开始时间(毫秒时间戳)。elapsed: number - 合成耗时(毫秒)。
Author
| funnyzak |
参考
License
Apache-2.0 License © 2021 funnyzak