Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/546669204/xf-js
讯飞SDK-WEBJS 包含 iat 和 tts 语音听写,语音合成
https://github.com/546669204/xf-js
Last synced: 12 days ago
JSON representation
讯飞SDK-WEBJS 包含 iat 和 tts 语音听写,语音合成
- Host: GitHub
- URL: https://github.com/546669204/xf-js
- Owner: 546669204
- License: apache-2.0
- Created: 2019-11-28T10:39:27.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-28T10:43:32.000Z (about 5 years ago)
- Last Synced: 2024-11-07T11:23:48.527Z (2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xf-js 讯飞SDK
适用于 浏览器 的讯飞SDK js
采用最新的流式接口 websocket包含
1. 语音听写
2. 语音合成## 安装
```
npm i xf-js
```## 使用
```javascript
import * as xfjs from "xf-js";//使用语音听写
var iat = new xfjs.iat({
appId:"",//传入AppId
authUrl:"",//AuthUrl 认证url 自己拼接
})//绑定 onaudioprocess
使用createScriptProcessor创建出来的
var p = ctx.createScriptProcessor();
p.onaudioprocess = (e)=>{
iat.onaudioprocess(e);
};iat.start();//启动听写
iat.stop((str)=>{
//结果回调
// str 内容为转义 结果
});//停止//如果时文件内存想要转义
var reader = new FileReader();
reader.onload = async (event)=>{
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var audioBuffer = await audioCtx.decodeAudioData(event.target.result);
var ff = audioBuffer.getChannelData(0);
iat.sendData(ff)
iat.start();
var b = new Date();
iat.hook.onSendData = ()=>{
b = new Date();
}
iat.hook.onSetResult = (e)=>{
//实时结果返回
}
//监听转义结束
var a = setInterval(() => {
if((new Date().getTime() - b.getTime()) >1000){
clearInterval(a);
notify.close();
iat.stop((e)=>{
iat.hook.onSendData = null;
iat.hook.onSetResult = null;
});
}
}, 100);
}
reader.readAsArrayBuffer(file); //传入file对象//使用语音合成
xfjs.tts({
appId:"",//传入AppId
authUrl:"",//AuthUrl 认证url 自己拼接
text:"语音合成内容"
}).then(blob=>{
new Audio(URL.createObjectURL(blob)).play();
})
```