@coze/realtime-api 1.0.4-beta.1 → 1.0.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/README.zh-CN.md +106 -0
- package/dist/cjs/{index.js → index.cjs} +306 -34
- package/dist/esm/{index.mjs → index.js} +306 -34
- package/dist/types/client.d.ts +7 -2
- package/dist/types/event-handler.d.ts +5 -0
- package/dist/types/index.d.ts +23 -1
- package/dist/types/utils.d.ts +11 -0
- package/dist/umd/index.js +305 -33
- package/package.json +13 -13
- /package/dist/cjs/{index.js.LICENSE.txt → index.cjs.LICENSE.txt} +0 -0
- /package/dist/esm/{index.mjs.LICENSE.txt → index.js.LICENSE.txt} +0 -0
package/README.md
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
7
7
|
[](https://github.com/coze-dev/coze-js/pulls)
|
8
8
|
|
9
|
+
English | [简体中文](./README.zh-CN.md)
|
10
|
+
|
9
11
|
A powerful real-time communication SDK for voice interactions with Coze AI bots.
|
10
12
|
|
11
13
|
## Features
|
@@ -58,6 +60,10 @@ const client = new RealtimeClient({
|
|
58
60
|
audioMutedDefault: false, // Optional: Initial audio state (default: false)
|
59
61
|
suppressStationaryNoise: false, // Optional: Enable stationary noise suppression(default: false)
|
60
62
|
suppressNonStationaryNoise: false, // Optional: Enable non-stationary noise suppression(default: false)
|
63
|
+
videoConfig: { // Optional: Video configuration
|
64
|
+
videoOnDefault: true, // Optional: Whether to turn on video by default, defaults to true
|
65
|
+
renderDom: 'local-player' // Optional: The DOM element to render the video stream to
|
66
|
+
},
|
61
67
|
});
|
62
68
|
|
63
69
|
// Essential Setup
|
@@ -77,7 +83,9 @@ const operations = {
|
|
77
83
|
disconnect: () => client.disconnect(),
|
78
84
|
interrupt: () => client.interrupt(),
|
79
85
|
toggleMicrophone: (enabled: boolean) => client.setAudioEnable(enabled),
|
80
|
-
checkConnection: () => client.isConnected
|
86
|
+
checkConnection: () => client.isConnected,
|
87
|
+
// get rtc engine instance, for detail visit https://www.volcengine.com/docs/6348/104478#rtcengine
|
88
|
+
getRtcEngine: () => client.getRtcEngine(),
|
81
89
|
};
|
82
90
|
|
83
91
|
// Event Handling
|
package/README.zh-CN.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Coze 实时语音 API
|
2
|
+
|
3
|
+
[](https://www.npmjs.com/package/@coze/realtime-api)
|
4
|
+
[](https://www.npmjs.com/package/@coze/realtime-api)
|
5
|
+
[](https://github.com/coze-dev/coze-js/blob/main/LICENSE)
|
6
|
+
[](https://www.typescriptlang.org/)
|
7
|
+
[](https://github.com/coze-dev/coze-js/pulls)
|
8
|
+
|
9
|
+
[English](./README.md) | 简体中文
|
10
|
+
|
11
|
+
一个强大的实时语音 SDK,用于与 Coze AI Bot 进行语音交互。
|
12
|
+
|
13
|
+
## 特性
|
14
|
+
1. 精准的语音识别:利用大语言模型进行 ASR(自动语音识别),我们的系统提供上下文理解能力。它可以参考之前提到的术语,理解说话风格和引用,并在噪音、专业术语和中英混合语音等挑战性场景下提供更高的识别准确率。
|
15
|
+
|
16
|
+
2. 强大的 AI 代理能力:作为 AI 代理开发平台,Coze 提供全面的代理功能,包括:
|
17
|
+
- 记忆系统(文件存储、数据库、变量)
|
18
|
+
- 知识集成(文本、表格、图像)
|
19
|
+
- 技能(插件、触发器)
|
20
|
+
- 工作流编排(任务流、图像处理流程)
|
21
|
+
|
22
|
+
3. 低延迟:使用 RTC(实时通信)技术实现,最大限度地减少通信管道中的延迟。
|
23
|
+
|
24
|
+
4. 自然语音合成:使用由大语言模型驱动的高级 TTS(文本转语音)模型,我们的系统:
|
25
|
+
- 智能预测情感语境和语调
|
26
|
+
- 生成超自然、高保真、个性化的语音输出
|
27
|
+
- 在自然度、音质、韵律、呼吸模式和情感表达方面表现出色
|
28
|
+
- 无缝处理中英混合内容
|
29
|
+
- 提供类人的语气词和情感细微差别表达
|
30
|
+
|
31
|
+

|
32
|
+
|
33
|
+
## 安装
|
34
|
+
|
35
|
+
```bash
|
36
|
+
npm install @coze/realtime-api
|
37
|
+
# 或
|
38
|
+
yarn add @coze/realtime-api
|
39
|
+
```
|
40
|
+
|
41
|
+
## 快速开始
|
42
|
+
|
43
|
+
```ts
|
44
|
+
import { RealtimeClient, EventNames, RealtimeUtils } from "@coze/realtime-api";
|
45
|
+
|
46
|
+
// 初始化客户端
|
47
|
+
const client = new RealtimeClient({
|
48
|
+
baseURL: "https://api.coze.cn",
|
49
|
+
accessToken: "your_access_token",
|
50
|
+
// 或者
|
51
|
+
// accessToken: async () => {
|
52
|
+
// // 如果令牌过期则刷新
|
53
|
+
// return 'your_oauth_token';
|
54
|
+
// },
|
55
|
+
botId: "your_bot_id",
|
56
|
+
voiceId: "your_voice_id", // 可选:指定音色 ID
|
57
|
+
conversationId: "conversation_id", // 可选:用于对话连续性
|
58
|
+
debug: true, // 可选:启用调试日志
|
59
|
+
allowPersonalAccessTokenInBrowser: true, // 可选:在浏览器中启用 PAT 令牌使用
|
60
|
+
audioMutedDefault: false, // 可选:初始音频状态(默认:false)
|
61
|
+
suppressStationaryNoise: false, // 可选:启用静态噪声抑制(默认:false)
|
62
|
+
suppressNonStationaryNoise: false, // 可选:启用非静态噪声抑制(默认:false)
|
63
|
+
});
|
64
|
+
|
65
|
+
// 基本设置
|
66
|
+
async function initializeVoiceChat() {
|
67
|
+
// 1. 验证设备权限
|
68
|
+
const result = await RealtimeUtils.checkDevicePermission();
|
69
|
+
if (!result.audio) {
|
70
|
+
throw new Error("需要麦克风访问权限");
|
71
|
+
}
|
72
|
+
|
73
|
+
// 2. 建立连接
|
74
|
+
await client.connect();
|
75
|
+
}
|
76
|
+
|
77
|
+
// 核心操作
|
78
|
+
const operations = {
|
79
|
+
disconnect: () => client.disconnect(),
|
80
|
+
interrupt: () => client.interrupt(),
|
81
|
+
toggleMicrophone: (enabled: boolean) => client.setAudioEnable(enabled),
|
82
|
+
checkConnection: () => client.isConnected,
|
83
|
+
// 获取 RTC 引擎实例,详情请访问 https://www.volcengine.com/docs/6348/104478#rtcengine
|
84
|
+
getRtcEngine: () => client.getRtcEngine(),
|
85
|
+
};
|
86
|
+
|
87
|
+
// 事件处理
|
88
|
+
function setupEventListeners() {
|
89
|
+
// 监听所有事件
|
90
|
+
client.on(EventNames.EventNames, console.log);
|
91
|
+
|
92
|
+
// 仅客户端事件
|
93
|
+
client.on(EventNames.ALL_CLIENT, console.log);
|
94
|
+
|
95
|
+
// 仅服务器端事件
|
96
|
+
client.on(EventNames.ALL_SERVER, console.log);
|
97
|
+
|
98
|
+
// 特定事件处理
|
99
|
+
client.on(EventNames.CONNECTED, (event) => {
|
100
|
+
console.log("连接已建立:", event);
|
101
|
+
});
|
102
|
+
}
|
103
|
+
```
|
104
|
+
|
105
|
+
## 示例
|
106
|
+
查看完整的示例,请参考我们的[实时语音控制台DEMO](../../examples/realtime-console)。
|