
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
humanchat-sdk
Advanced tools
# 数字人集成文档(SDK + iframe)
> 1. **SDK 方式**(推荐):功能全、体验优,支持 H5、微信小程序、支付宝小程序。
> 2. **iframe 方式**(轻量):零开发、三步嵌入,仅支持 H5。
> 如无特殊限制,请优先使用 SDK。
---
## 目录
1. 快速选型
2. SDK 接入(H5 / 小程序)
2.1 安装与初始化
2.2 常用 API
2.3 事件回调
2.4 最佳实践
3. iframe 接入(纯 H5)
3.1 获取嵌入地址
3.2 完整代码示例
3.3 跨域与通信
4. 常见问题(SDK & iframe 通用)
5. 更新日志
6. 技术支持
---
## 1. 快速选型
| 维度 | SDK | iframe |
|---|---|---|
| 支持平台 | H5 + 微信小程序 + 支付宝小程序 | 仅 H5 |
| 功能完整性 | 全部能力(麦克风、波形、外部大脑、样式自定义) | 仅播报 + 简单问答 |
| 接入成本 | 需 npm 安装 + 5 行代码初始化 | 复制 1 段 iframe 即可 |
| 适用场景 | 正式业务、品牌交付、复杂交互 | 活动页、demo、临时页面 |
---
## 2. SDK 接入(H5 / 小程序)
### 2.1 安装与初始化
```bash
# 1. 安装(推荐 npm)
npm i humanchat-sdk --save
<!-- 2. 准备容器(H5 示例) -->
<div id="dh-box" style="width:320px;height:540px;margin:0 auto;"></div>
<div id="wave-box" style="width:300px;height:60px;margin:10px auto;"></div>
// 3. 初始化
import 'humanchat-sdk/index.css';
import XmenAI from 'humanchat-sdk';
const dh = new XmenAI({
token: 'YOUR_TOKEN', // 商务获取
projectId: 'YOUR_PROJECT_ID', // 数字人AI智能体创作平台「项目管理」页复制
container: document.getElementById('dh-box'),
width: 320,
height: 540,
microphone: true, // 需要麦克风问答
wave: document.getElementById('wave-box'),
isUseChat: true, // 使用外部大脑
insertAiAnswer: false, // 隐藏内置输入框
onInitComplete: () => {
setTimeout(() => {
dh.speak('数字人初始化完成!', true, true);
})
},
onStartTalking: () => {
// 开始说话
},
onEndTalking: () => {
// 结束说话
},
onUpperLimit: () => {
// 并发达到上限或者高级口型未加载完成无法问答
},
onReceivedTheIssue: (question) => {
// 调用你的大模型接口
fetch('/api/chat', { method: 'POST', body: JSON.stringify({ q: question }) })
.then(r => r.json())
.then(res => dh.speak(res.answer, true, true));
}
});
小程序仅需把 container 换成 this.selectComponent('#dh-box'),其余完全一致。
| 方法 | 说明 | 示例 |
|---|---|---|
speak(text, begin, finish) | 触发播报 | 见上 |
stopSpeak() | 立即停止当前播报 | dh.stopSpeak() |
app.json 声明 record 权限。3 步完成:① 创建项目 → ② 复制链接 → ③ 粘贴 iframe
| 参数 | 含义 | 示例 |
|---|---|---|
isNesting=true | 必须,背景透明 | …&isNesting=true |
insertAiAnswer=true | 显示内置问答输入框 | …&insertAiAnswer=true |
isUseChat=true | 使用外部大脑 | …&isUseChat=true |
isShowRecordList=true | 显示聊天记录 | …&isShowRecordList=true |
最终示例地址
https://yh.ipavatar.com/yihuaVideoPreview?id=egGXsD&isNesting=true&insertAiAnswer=true&isUseChat=true&isShowRecordList=true
<!-- 1. 嵌入数字人 -->
<iframe id="myIframe"
src="https://yh.ipavatar.com/yihuaVideoPreview?id=egGXsD&isNesting=true&insertAiAnswer=true&isUseChat=true&isShowRecordList=true"
frameborder="0"
style="width:320px;height:540px;margin:0 auto;display:block;">
</iframe>
<script>
// 2. 监听数字人发来的问题
window.addEventListener('message', e => {
if (e.data.type === 'question') {
const userQuestion = e.data.value;
// 调用你的接口
fetch('/api/chat', { method: 'POST', body: JSON.stringify({ q: userQuestion }) })
.then(r => r.json())
.then(res => {
// 3. 把答案回传数字人
document.getElementById('myIframe').contentWindow.postMessage({
answer: res.answer, // 播报文本
begin_sign: true, // 第一句
finish: true // 最后一句
}, '*');
});
}
});
</script>
https://yh.ipavatar.com 跨域调用。| 问题 | 排查要点 |
|---|---|
| 初始化报 “token 无效” | 确认 token 与 projectId 在数字人AI智能体平台「已启用」 |
| 麦克风无权限 | HTTPS / 小程序声明 / 用户授权 |
| 调用 speak 无反应 | 是否触发 onInitComplete;是否触发 onUpperLimit |
| iframe 收不到消息 | 检查是否 HTTPS;后台是否放行跨域 |
| 版本 | 日期 | 说明 |
|---|---|---|
| v1.0.0 | 2025-09-11 | 合并 SDK + iframe 双文档;首次发布 |
文档如有未尽,欢迎邮件或电话,我们 1 个工作日内响应。
FAQs
本款产品专为解决H5页面或小程序嵌入数字人进行实时的语音播报,同时也可以通过麦克风进行实时语音问答。
We found that humanchat-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.