1.0.1 • Published 6 months ago
xfsdk v1.0.1
XFSDK
把迅飞语音听写(流式版)WebAPI封装成XFSDK。使用 webpack 打包 JSSDK 的工程。
命令
# 安装依赖
yarn install xfsdk or npm install xfsdk
# 本地开发调试
yarn dev or npm run dev
# 本地分析打包文件
npm run preview --report
# 打包,产出 dist
yarn build or npm run build
使用
npm
import { Voice } from 'xfsdk';
// or
const { Voice } = require('xfsdk');
// 实例化迅飞语音听写(流式版)WebAPI
//appId,appsecret,appkey在控制台-我的应用-语音听写(流式版)页面获取
const voice = new Voice({
appId: '你的APPID',
appkey: '你的APPKEY',
appsecret: '你的APPSECRET',
onWillStatusChange: function (oldStatus, newStatus) {
//可以在这里进行页面中一些交互逻辑处理:注:倒计时(语音听写只有60s),录音的动画,按钮交互等!
},
onTextChange: function (text) {
// 获取语音转成的文字
}
});
// 开始识别
startBtn['onclick'] = function () {
voice.start();
};
// 关闭识别
closeBtn['onclick'] = function () {
voice.stop();
};
CDN
<script src="xfsdk.min.js"></script>
<script>
// 实例化迅飞语音听写(流式版)WebAPI
const voice = new XFSDK.Voice({
appId: '你的APPID',
appkey: '你的APPKEY',
appsecret: '你的APPSECRET',
onWillStatusChange: function (oldStatus, newStatus) {
//可以在这里进行页面中一些交互逻辑处理:注:倒计时(语音听写只有60s),录音的动画,按钮交互等!
},
onTextChange: function (text) {
// 获取语音转成的文字
}
});
// 开始识别
startBtn['onclick'] = function () {
voice.start();
};
// 关闭识别
closeBtn['onclick'] = function () {
voice.stop();
};
</script>