npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electron-duix

v0.1.9

Published

electron duix sdk

Downloads

3

Readme

硅基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' 
})

参数

| 名称| 类型 |必填 | 描述 | | :-----------------| :-------------- | :----------------------------------------------------------- | :------ | | modelDir | string | 是 | 模型存放文件夹,长度不宜过长,请使用英文路径。 | | appId | string | 是 | appId | | appKey | string | 是 | app秘钥 | | containerLable | string | 是 | 数字人容器。数字人将渲染到这个Dom中。 |

start(option:object): Promise

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

参数

| key | 类型 | 必填 | 默认值 | 说明 | | ----------- | ------- | ---- | ------ | ------------------------------------------------------------ | | conversationId| number | 是 | | 平台会话id|

break()

打断数字人说话

speak(option: Object): Promise

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

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

参数

| 名称| 类型 |必填 | 描述 | | :-----------------| :-------------- | :----------------------------------------------------------- | ------ | | content | string | 是 | 数字人回答的文本 | | audio | string | 否 | 数字人回答音频地址,可以通过getAnswer获取平台配置的答案| | interrupt | boolean | 否 | 是否打断之前说的话 |

answer(option: Object): Promise

数字人回答问题

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

参数

| 名称| 类型 |必填 | 描述 | | :-----------------| :-------------- | :----------------------------------------------------------- | ------ | | question | string | 是 | 问题文本 | | interrupt | boolean | 否 | 是否打断之前说的话 | | userId | number | 否 | 业务层用户唯一id,开启记忆功能时使用,用来关联用户历史记录. 如果为空,默认使用appId | | isHistory | boolean | 否 | 是否开启历史记录 | | isVector | boolean | 否 | 决策是否带入之前的相似回答 |

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. 优化渲染逻辑,解决音画不同步问题。