dby-ai-speech-node-sdk

1.0.21 • Public • Published

开发环境配置

  1. 需要使用 32 位的 node,版本尽量保证和 Electron 内置的 node 版本一致,防止原生模块无法编译。 Electron 和 node 版本号的对应关系可以在这里查 https://www.npmjs.com/package/electron-releaseshttps://github.com/nodejs/node/blob/master/doc/abi_version_registry.jsonhttps://nodejs.org/zh-cn/download/releases

  2. 需要配置 node-gyp 编译环境,推荐使用 https://www.npmjs.com/package/windows-build-tools


使用方法:

处理 DLL 文件

下载 dll 文件压缩包

下载地址: https://paas-electron-sdk.duobeiyun.com/sdk/win/dby-ai-speech-sdk/dlls-202010281450.zip

把 dll 文件放到指定目录下

把 dllS.zip 解压缩并把解压出来的 dll 文件放置到项目里的某个文件夹内


代码示例

const SDK = require('dby-ai-speech-node-sdk')

const sdk = new SDK(#dllFileDirPath) // #dllFileDirPath 的值为上一步的 dll 所在文件夹的绝对路径

// 初始化 sdk
sdk.init(#dbyAppId, #dbyAppKey, #aiSpeechAppId, #aiSpeechAppKey).then(async () => {

  // 高级功能,提供控制拉流和语音识别的开关
  await sdk.enableRemoteStream(true) // 开启拉流功能
  await sdk.enableAiSpeech(true) // 开启语音识别功能

  // 加入频道
  sdk.joinChannel(#channelId, #uid).then(() => {
    console.log('join channel success!')

    // 处理语音识别结果
    sdk.onUserText((uid, text) => {
      console.log('on user text ', uid, text)
    })
  }).catch((e) => {
    console.log('join channel fail! ', e.message)
  })
})

SDK 接口说明

constructor
概述

SDK 构造函数

参数
参数 说明
dllFileDirPath dll 文件所在文件夹的绝对路径。比如 path.resolve('../../dllfiles')

返回

SDK 实例

init
sdk.init(#dbyAppId, #dbyAppKey, #aiSpeechAppId, #aiSpeechAppKey)
概述

初始化 SDK 实例,填入需要的账号信息

参数
参数 说明
dbyAppId 多贝云 AppId
dbyAppKey 多贝云 AppKey
aiSpeechAppId AISpeech AppId
aiSpeechAppKey AISpeech AppKey

返回

Promise<void>

enableRemoteStream
sdk.enableRemoteStream(true/false)
概述

sdk功能开关,用来控制sdk是否拉取远端音频流。一般情况下不需要调用该接口

参数
参数 说明
enable 是否拉取远端的音频流,默认值为true

返回

Promise<void>

enableAiSpeech
sdk.enableAiSpeech(true/false)
概述

sdk功能开关,用来控制sdk是否开启语音识别功能。sdk默认不开启语音识别功能,一般情况下需要调用该接口开启

参数
参数 说明
enable 是否拉取远端的音频流,默认值为false

返回

Promise<void>

joinChannel
sdk.joinChannel(#channelId, #uid)
概述

加入某个频道

参数
参数 说明
channelId 需要加入的频道 ID
uid 用户的 id

返回

Promise<void>

leaveChannel

sdk.leaveChannel()
概述

离开某个频道

参数

返回

Promise<void>

destroy

sdk.destroy()
概述

销毁 SDK 实例,如果已经加入了频道,需要在 leaveChannel 调用成功之后再调用 destroy

参数

返回

Promise<void>

onUserText

sdk.onUserText((uid, text) => {
  console.log('sdk.onUserText ', uid, text)
})
概述

注册语音识别结果的回调

参数
参数 说明
cb 语音识别结果的回调函数,它有两个参数,第一个是用户 id,第二个是该用户的语音识别出的文字

返回

undefined

Readme

Keywords

none

Package Sidebar

Install

npm i dby-ai-speech-node-sdk

Weekly Downloads

1

Version

1.0.21

License

MIT

Unpacked Size

13.6 kB

Total Files

8

Last publish

Collaborators

  • duobeiyun