版本号 |
更新点 |
更新时间 |
说明 |
v2.0.0.1 |
主线base版本 |
2024.03.18 |
支持IOS 9.0+ |
sdk+demo 下载
一、SDK 接入
1、设置Frameworks, Libraries, and Embedded Content
1.1、动态库版本
1.2、静态库版本
2、工程配置
2.1、设置Bitcode
将Bitcode 设置为NO
2.2、排除Architectures
将模拟器架构排除:x86_64/i386
2.3、配置Info.plist
Key |
Value |
Privacy - Microphone Usage Description |
使用麦克风 |
Privacy - Camera Usage Description |
使用摄像头 |
二、SDK调用以及API说明
1、类引用说明
// 云上数字人主view
#import <DigitalHumanCloud/DigitalHumanCloudView.h>
// 云上数字人类型定义类
#import <DigitalHumanCloud/DigitalHumanCloudDefines.h>
2、数字人配置
@interface DigitalHumanCloudSettings : DHObject
参数名 |
类型 |
参数说明 |
默认值 |
webSocketUrl |
string |
websocket协议地址 |
wss://digitalhuman.baidu.com/cloud/digital-human-demonstration |
appId |
string |
登录信息 |
-- |
appKey |
string |
|
-- |
token |
string |
|
-- |
projectId |
string |
|
-- |
showWidget |
boolean |
是否展示widget |
true |
widgetUrl |
string |
widget地址 |
https://digitalhuman.baidu.com/cloud/view |
resolutionWidth |
int |
数字人的大小 |
720 |
resolutionHeight |
int |
|
1280 |
videoBitRate |
int |
数字人的码率 |
2000 |
showControlBar |
boolean |
是否展示控件 |
true |
pressPickAudioEnabled |
boolean |
按键拾音 |
false |
showReplyTitle |
boolean |
是否展示数字人回复话术 |
true |
showQueryTitle |
boolean |
是否展示asr结果 |
true |
showTextAssist |
boolean |
是否展示文本辅助输入框 |
true |
usingAudio |
boolean |
是否开启拾音功能 |
true |
usingVideo |
boolean |
是否开启摄像头 |
false |
ttsSpeed |
int |
语速 |
5 |
debug |
boolean |
开启debug模式 |
false |
enqueue |
boolean |
是否需要排队 |
false |
调用示例:
DigitalHumanCloudSettings *settings = [[DigitalHumanCloudSettings alloc]initWithDictionary:parameters];
settings.webSocketUrl = @"wss://digitalhuman.baidu.com/cloud/digital-human-demonstration";
3、数字人初始化
- (instancetype)initWithFrame:(CGRect)frame andSettings:(DigitalHumanCloudSettings *)settings andBackground:(UIImageView * __nullable)backgroundImage
参数名 |
类型 |
参数说明 |
默认值 |
frame |
CGRect |
|
|
settings |
DigitalHumanCloudSettings |
|
|
backgroundImage |
|
|
|
调用示例
_cloudView = [[DigitalHumanCloudView alloc] initWithFrame:self.view.frame andSettings:_settings andBackground:nil];
_cloudView.delegate = self;
[self.view addSubview:_cloudView];
3.1、回调及监听
@protocol DigitalHumanCloudDelegate <NSObject>
@required
- (void)onDigitalHumanCloudEventUpdate:(DigitalHumanCloudEvent)event obj:(id __nullable)data;
@optional
- (void)onMessage:(NSString *)message;
@optional
- (void)onCommand:(NSString *)message;
@optional
- (void)onCameraRecord:(UIImage *)image;
@optional
- (void)onNetworkStatus:(long)latency;
@optional
- (void)onMeidaStatus:(NSInteger)connecStates;
参数名 |
说明 |
- (void)onDigitalHumanCloudEventUpdate:(DigitalHumanCloudEvent)event obj:(id __nullable)data |
数字人sdk状态变化回调,参考 DigitalHumanCloudEvent 取值 |
(void)onMessage:(NSString *)message |
数字人websocket消息返回 |
(void)onCommand:(NSString *)message |
数字人指令返回 |
(void)onCameraRecord:(UIImage *)image |
相机数据回传 |
(void)onNetworkStatus:(long)latency |
网络状态监听 |
(void)onMeidaStatus:(NSInteger)connecStates |
RTC 网络状态监听 |
DigitalHumanCloudEvent
类型 |
描述 |
DH_CLOUD_LIB_INIT |
数字人SDK启动事件 |
DH_CLOUD_LIB_HEARTBEAT |
数字人SDK心跳事件 |
DH_CLOUD_LIB_ERROR |
数字人SDK错误事件 |
DH_CLOUD_LIB_LOADING |
数字人SDK加载中事件 |
DH_CLOUD_LIB_QUEUING |
数字人SDK排队事件 |
DH_CLOUD_LIB_WS_SUCCESS |
数字人SDK WS连接成功事件 |
调用示例
@interface CloudController () <DigitalHumanCloudDelegate>
- (void)onMessage:(NSString *)message {
}
- (void)onCommand:(NSString *)message {
}
- (void)onDigitalHumanCloudEventUpdate:(DigitalHumanCloudEvent)event obj:(id _Nullable)data {
switch (event) {
case DH_CLOUD_LIB_INIT: {
break;
}
case DH_CLOUD_LIB_HEARTBEAT:
break;
case DH_CLOUD_LIB_ERROR: {
break;
}
case DH_CLOUD_LIB_LOADING:
break;
case DH_CLOUD_LIB_WS_SUCCESS:
break;
default:
break;
}
}
- (void)onNetworkStatus:(long)latency {
}
- (void)onMeidaStatus:(NSInteger)connecStates {
}
4、数字人接口
4.1、驱动数字人
4.1.1、文本问询驱动
4.1.1.1、方式一
- (void)textQuery:(NSString *)message;
4.1.1.2、方式二
- (void)textQuery:(NSString * __nullable)requestId andMessage:(NSString *)message;
参数 |
描述 |
requestId |
uuid |
message |
询问内容 |
4.1.2、文本驱动
4.1.2.1、方式一
- (void)textRender:(NSString *)message;
参数 |
描述 |
message |
驱动数字人(message为drml) |
4.1.2.2、方式二
- (void)textRender:(NSString * __nullable)requestId andMessage:(NSString *)message;
参数 |
描述 |
requestId |
uuid |
message |
驱动数字人(message为drml) |
4.2、暂停数字人
调用示例
4.3、恢复数字人
调用示例
4.4、给数字人发送消息
4.4.1、方式一
- (void)sendMessage:(NSString *)action andBody:(NSString *)body;
参数 |
描述 |
action |
消息类型 |
body |
内容 |
调用方式
[_cloudView sendMessage:@"TEXT_RENDER" andBody:message];
4.4.2、方式二
- (void)sendMessage:(NSString * __nullable)requestId andAction:(NSString *)action andBody:(NSString *)body;
参数 |
描述 |
requestId |
uuid |
action |
消息类型 |
body |
内容 |
[_cloudView sendMessage:uuid andAction:@"TEXT_RENDER" andBody:message]
4.5、给数字人发送指令
- (void)sendCommand:(NSString *)command andContent:(NSString *)content
参数 |
描述 |
command |
类型 |
content |
内容 |
调用示例
[_cloudView sendCommand:@"RTC_STATUS" andContent:@"YES"];
4.6、数字人静音开关
YES: 静音
调用示例
4.7、数字人暂停拉流
- (void)subscribeStreaming:(BOOL)subscribe byUserId:(NSString * __nullable)userId;
参数 |
描述 |
subscribe |
是否暂停拉流; |
userId |
用户流,不传则为默认流 |
YES :暂停拉流
调用示例
[_cloudView subscribeStreaming:YES byUserId:userId];
4.8、数字人暂停拉音频流
- (void)subscribeAudio:(BOOL)subscribe;
参数 |
描述 |
subscribe |
是否暂停拉流;YES :暂停拉流 |
调用示例
[_cloudView subscribeAudio:YES];
4.9、切换听筒和扬声器
- (void)switchLoudSpeaker:(BOOL)speakLoud;
NO: 听筒
调用示例
[_cloudView switchLoudSpeaker:YES];
4.10、人脸识别验证
调用示例
[_cloudView faceRecognition];
4.11、设置本地视频预览容器
- (void)initLocalPreview:(UIImageView *)view
调用示例
_localPreviewView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
_localPreviewView.layer.zPosition = 100;
[_cloudView initLocalPreview:_localPreviewView];
5、数字人登出销毁
调用示例
[_cloudView destroy];
[_cloudView removeFromSuperview];
_cloudView = nil;
_cloudView.delegate = nil;