Skip to main content

PilotKit

核心容器组件,集成 Provider 和数字人渲染,是所有 Widget 组件的根组件。

基本用法

<script setup lang="ts">
import {PilotKit, ControlPanel} from '@bdky/aaas-pilot-kit-vue3-widget';
</script>

<template>
<PilotKit
token="your-token"
figureId="your-figure-id"
ttsPer="your-tts-per"
:agentConfig="{robotId: 'your-robot-id'}"
>
<ControlPanel />
</PilotKit>
</template>

使用 Ref

通过 ref 可以访问控制器方法:

<script setup lang="ts">
import {ref} from 'vue';
import {PilotKit, type IPilotKitRef} from '@bdky/aaas-pilot-kit-vue3-widget';

const pilotKitRef = ref<IPilotKitRef | null>(null);

function handleSendMessage() {
pilotKitRef.value?.input('你好');
}

function handleInterrupt() {
pilotKitRef.value?.interrupt();
}
</script>

<template>
<PilotKit ref="pilotKitRef" v-bind="props">
<button @click="handleSendMessage">发送消息</button>
<button @click="handleInterrupt">打断</button>
</PilotKit>
</template>

Props

必填属性

属性类型说明
tokenstring认证 Token
figureIdstring数字人形象 ID
ttsPerstringTTS 音色 ID

Agent 配置

属性类型说明
agentConfig{robotId: string; token?: string}Agent 配置,与 agentService 二选一
agentServicetypeof BaseAgentService自定义 AgentService 类
agentConfig vs agentService
  • 使用百度默认 Agent:配置 agentConfig
  • 使用私有 Agent API:提供自定义 agentService,详见 自定义 AgentService

行为配置

属性类型默认值说明
prologuestring-开场白,SDK 就绪后自动播报
interruptiblebooleanfalse是否允许打断播报
timeoutSecnumber120无操作超时时间(秒)
typeDelaynumber100中文打字机效果延迟(ms)
enTypeDelaynumber50英文打字机效果延迟(ms)
minSplitLennumber10流式文本最小分割长度

渲染配置

属性类型默认值说明
rendererMode'cloud-native' | 'standard''standard'渲染模式
scaleXnumber1水平缩放
scaleYnumber1垂直缩放
translateXnumber0水平偏移
translateYnumber0垂直偏移

样式属性

属性类型说明
classstring自定义类名
styleCSSProperties自定义样式
backgroundUrlstring背景图片 URL
autoMountboolean是否自动挂载,默认 true

事件

事件类型说明
@ready() => voidSDK 就绪
@needManualActivation() => void需要手动激活(iOS iframe)
@asrStart() => voidASR 开始
@asrMessage(payload) => voidASR 识别结果
@renderStart(payload) => void开始播报
@inactivity(payload) => void用户无操作超时
@busy(payload) => void系统繁忙
@interrupt(payload) => void播报被打断
@conversationChange(payload) => void对话内容变化
@isRenderingChange(isRendering) => void播报状态变化
@replyStart(payload) => void回复开始
@ttft(payload) => void首字延迟指标
事件 Payload 类型

事件回调的 Payload 类型定义详见 Vue 3 SDK Composables 文档

Ref 方法

通过 ref 可以访问以下方法:

方法类型说明
input(text: string) => void发送文字输入
mute(muted: boolean) => void设置静音状态
interrupt() => void打断当前播报
dispose() => void销毁实例
playPrologue() => void播放开场白
playFromFullText(text: string) => void播放完整文本
playFromStreamText(text: string) => void流式播放文本
keepAlive() => void保持连接活跃
checkAudioDevice() => Promise<Result>检测音频设备
activateManually() => Promise<void>手动激活(iOS)
getIsReady() => boolean获取就绪状态
getIsMuted() => boolean获取静音状态
getIsRendering() => boolean获取播报状态

Provide/Inject

PilotKit 内部创建了 PilotKitContext,子组件可以通过 usePilotKitContext 访问:

<script setup lang="ts">
import {usePilotKitContext} from '@bdky/aaas-pilot-kit-vue3-widget';

const pilotKit = usePilotKitContext();

function sendMessage() {
pilotKit?.input('你好');
}
</script>

<template>
<button @click="sendMessage">发送消息</button>
</template>

样式定制

CSS 类名

类名说明
.apk-pilot-kit根容器
.apk-pilot-kit__mask遮罩层(children 渲染位置)

背景图片

使用 backgroundUrl 设置背景:

<template>
<PilotKit
backgroundUrl="https://example.com/background.jpg"
...
/>
</template>

相关