0.1.9 • Published 1 year ago

electron-duix v0.1.9

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

硅基electron-duix使用文档

安装

npm i electron-duix -S

注意

创建window窗口需要设置允许渲染进程和worker中使用node

 const mainWindow = new BrowserWindow({
    ...
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      nodeIntegrationInWorker: true,
      webSecurity: false,
    }
  });

快速开始

const duix = require('electron-duix')
// 添加事件监听
duix.on('progress', data => {
 // 加载进度 0-1
})
duix.on('show', () => {
  // 数字人已显示
})
duix.on('speakStart', res => {
 // speak开始
})
duix.on('speakSection', res => {
  // 播放音频片段
})
duix.on('speakEnd', res => {
  // speak结束
})
duix.on('openAsrSuccess', () => {
  // 开启asr成功
})
duix.on('asrClose', () => {
  // asr已关闭
})
duix.on('asrResult', res => {
  // asr失败结果
})
duix.on('bye', (res) => {
  // 会话结束
})
duix.on('error', res => {
  // 会话异常
  if (res.code == 5001) {
    console.info('模型加载失败')
  }
})

const res = await duix.init({
  modelDir: 'xxx',
  appId: 'xxx',
  appKey: 'xxx',
  containerLable: '.remote-container'
})

if (!res?.err) {
  duix.start({ conversationId: 'xxx' })
}

方法

init(option: object): Promise

duix.init({
  modelDir: 'xxx',
  appId: 'xxx',
  appKey: 'xxx',
  containerLable: '.remote-container' 
})

参数

名称类型必填描述
modelDirstring模型存放文件夹,长度不宜过长,请使用英文路径。
appIdstringappId
appKeystringapp秘钥
containerLablestring数字人容器。数字人将渲染到这个Dom中。

start(option:object): Promise

duix.start({
  conversationId: '',    
})

参数

key类型必填默认值说明
conversationIdnumber平台会话id

break()

打断数字人说话

speak(option: Object): Promise

驱动数字人说话,支持文本驱动和音频文件驱动。

duix.speak({content: '', audio: 'https://your.website.com/xxx/x.wav'})

参数

名称类型必填描述
contentstring数字人回答的文本
audiostring数字人回答音频地址,可以通过getAnswer获取平台配置的答案
interruptboolean是否打断之前说的话

answer(option: Object): Promise

数字人回答问题

duix.answer({question: 'xxx'})

参数

名称类型必填描述
questionstring问题文本
interruptboolean是否打断之前说的话
userIdnumber业务层用户唯一id,开启记忆功能时使用,用来关联用户历史记录. 如果为空,默认使用appId
isHistoryboolean是否开启历史记录
isVectorboolean决策是否带入之前的相似回答

openAsr():Promise

开启语音实时识别(注意此方法需在show触发时候调用)。开启语音实时识别后,可通过监听 asrResult 事件,接收识别(文本)结果。

closeAsr():Promise

关闭语音实时识别。

stop()

停止当前会话。建议在页卸载事件中调用此方法,以防止刷新或关闭网页时当前会话资源未及时释放。

getLocalStream()

获取本地语音流,方便外部做音频可视化等功能

on(eventname, callback)

监听事件。

参数
eventname

事件名称,详见下方表格。

callback

回调函数

返回格式说明

对于返回Promise的方法,参数格式为{ err, ...data },如果err不为空,则代表调用失败。

事件

名称描述
error有未捕获错误时触发。
bye会话结束时触发。
show出数字人已显示。
progress数字人加载进度。
speakSection数字人说话当前的音频和文本片段(answer方法会采用流式获取结果,如果单独调用speak,该事件与speakStart一致)
speakStart驱动数字人说话,到数字人实际说话之间有一点延迟,此事件表示数字人实际开始说话了
speakEnd数字人说话结束
openAsrSuccess语音实时识别开启成功后触发
asrResult语音实时识别结果
asrClose关闭语音实时识别成功时触发

error

{
  code: '', // 错误码  
  message: '', // 错误信息
  data: {} // 错误内容
}

error code

名称描述data
5001模型加载失败

progress

number类型的进度,0-1

speakSection

{
  audio: '', // 音频地址
  content: '', // 文本内容
}

speakStart

{
  audio: '', // 音频地址
  content: '', // 文本内容
}

speakEnd

{
  audio: '', // 音频地址
  content: '', // 文本内容
}

asrResult

字符串类型,asr识别文本结果

常见问题

版本记录

0.1.5

  1. 优化渲染逻辑,解决音画不同步问题。
0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago