Gathering detailed insights and metrics for electron-duix
Gathering detailed insights and metrics for electron-duix
Gathering detailed insights and metrics for electron-duix
Gathering detailed insights and metrics for electron-duix
npm install electron-duix
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
1,900%
20
Compared to previous week
Last month
1,650%
35
Compared to previous month
Last year
110.8%
584
Compared to previous year
10
1npm i electron-duix -S
创建window窗口需要设置允许渲染进程和worker中使用node
const mainWindow = new BrowserWindow({
...
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
nodeIntegrationInWorker: true,
webSecurity: false,
}
});
1 2const duix = require('electron-duix') 3// 添加事件监听 4duix.on('progress', data => { 5 // 加载进度 0-1 6}) 7duix.on('show', () => { 8 // 数字人已显示 9}) 10duix.on('speakStart', res => { 11 // speak开始 12}) 13duix.on('speakSection', res => { 14 // 播放音频片段 15}) 16duix.on('speakEnd', res => { 17 // speak结束 18}) 19duix.on('openAsrSuccess', () => { 20 // 开启asr成功 21}) 22duix.on('asrClose', () => { 23 // asr已关闭 24}) 25duix.on('asrResult', res => { 26 // asr失败结果 27}) 28duix.on('bye', (res) => { 29 // 会话结束 30}) 31duix.on('error', res => { 32 // 会话异常 33 if (res.code == 5001) { 34 console.info('模型加载失败') 35 } 36}) 37 38const res = await duix.init({ 39 modelDir: 'xxx', 40 appId: 'xxx', 41 appKey: 'xxx', 42 containerLable: '.remote-container' 43}) 44 45if (!res?.err) { 46 duix.start({ conversationId: 'xxx' }) 47}
1duix.init({ 2 modelDir: 'xxx', 3 appId: 'xxx', 4 appKey: 'xxx', 5 containerLable: '.remote-container' 6})
参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
modelDir | string | 是 | 模型存放文件夹,长度不宜过长,请使用英文路径。 |
appId | string | 是 | appId |
appKey | string | 是 | app秘钥 |
containerLable | string | 是 | 数字人容器。数字人将渲染到这个Dom中。 |
1duix.start({ 2 conversationId: '', 3})
参数
key | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
conversationId | number | 是 | 平台会话id |
打断数字人说话
驱动数字人说话,支持文本驱动和音频文件驱动。
1duix.speak({content: '', audio: 'https://your.website.com/xxx/x.wav'})
参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
content | string | 是 | 数字人回答的文本 |
audio | string | 否 | 数字人回答音频地址,可以通过getAnswer 获取平台配置的答案 |
interrupt | boolean | 否 | 是否打断之前说的话 |
数字人回答问题
1duix.answer({question: 'xxx'})
参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
question | string | 是 | 问题文本 |
interrupt | boolean | 否 | 是否打断之前说的话 |
userId | number | 否 | 业务层用户唯一id,开启记忆功能时使用,用来关联用户历史记录. 如果为空,默认使用appId |
isHistory | boolean | 否 | 是否开启历史记录 |
isVector | boolean | 否 | 决策是否带入之前的相似回答 |
开启语音实时识别(注意此方法需在show触发时候调用)。开启语音实时识别后,可通过监听 asrResult
事件,接收识别(文本)结果。
关闭语音实时识别。
停止当前会话。建议在页卸载事件中调用此方法,以防止刷新或关闭网页时当前会话资源未及时释放。
获取本地语音流,方便外部做音频可视化等功能
监听事件。
事件名称,详见下方表格。
回调函数
对于返回Promise
的方法,参数格式为{ err, ...data }
,如果err
不为空,则代表调用失败。
名称 | 描述 |
---|---|
error | 有未捕获错误时触发。 |
bye | 会话结束时触发。 |
show | 出数字人已显示。 |
progress | 数字人加载进度。 |
speakSection | 数字人说话当前的音频和文本片段(answer方法会采用流式获取结果,如果单独调用speak,该事件与speakStart一致) |
speakStart | 驱动数字人说话,到数字人实际说话之间有一点延迟,此事件表示数字人实际开始说话了 |
speakEnd | 数字人说话结束 |
openAsrSuccess | 语音实时识别开启成功后触发 |
asrResult | 语音实时识别结果 |
asrClose | 关闭语音实时识别成功时触发 |
1{ 2 code: '', // 错误码 3 message: '', // 错误信息 4 data: {} // 错误内容 5}
error code
名称 | 描述 | data |
---|---|---|
5001 | 模型加载失败 |
number类型的进度,0-1
1 2{ 3 audio: '', // 音频地址 4 content: '', // 文本内容 5} 6
1 2{ 3 audio: '', // 音频地址 4 content: '', // 文本内容 5} 6
1 2{ 3 audio: '', // 音频地址 4 content: '', // 文本内容 5} 6
字符串类型,asr识别文本结果
0.1.5
No vulnerabilities found.
No security vulnerabilities found.