import VERTC from '@volcengine/rtc';
const COMMAND_KEY = 'ctrl';
const engine = VERTC.createEngine('Your AppID'); // 你的 RTC 应用 APPId
* @brief 发送文本转语音(TTS)指令,让智能体播报指定的文本内容。
EXTERNAL_TEXT_TO_SPEECH = 'ExternalTextToSpeech',
enum INTERRUPT_PRIORITY {
* @brief 高优先级。智能体会终止当前交互,直接播放传入的文本内容。
* @brief 中优先级。智能体会在当前交互结束后,播放传入的文本内容。
* @brief 低优先级。如果此时智能体正在交互,智能体会直接丢弃传入的文本内容。如果未在交互,智能体会播放传入的文本内容
function stringToTLV(inputString: string, type = '') {
const typeBuffer = new Uint8Array(4);
for (let i = 0; i < type.length; i++) {
typeBuffer[i] = type.charCodeAt(i);
const lengthBuffer = new Uint32Array(1);
const valueBuffer = new TextEncoder().encode(inputString);
lengthBuffer[0] = valueBuffer.length;
const tlvBuffer = new Uint8Array(typeBuffer.length + 4 + valueBuffer.length);
tlvBuffer.set(typeBuffer, 0);
tlvBuffer[4] = (lengthBuffer[0] >> 24) & 0xff;
tlvBuffer[5] = (lengthBuffer[0] >> 16) & 0xff;
tlvBuffer[6] = (lengthBuffer[0] >> 8) & 0xff;
tlvBuffer[7] = lengthBuffer[0] & 0xff;
tlvBuffer.set(valueBuffer, 8);
return tlvBuffer.buffer;
* @brief 发送文本转语音(TTS)指令,让智能体播报指定的文本内容,并透传业务自定义信息
function sendTTSMessage({
interruptMode = INTERRUPT_PRIORITY.HIGH,
interruptMode?: INTERRUPT_PRIORITY;
customInfo?: Record<string, unknown>;
engine.sendUserBinaryMessage(
Command: COMMAND.EXTERNAL_TEXT_TO_SPEECH,
InterruptMode: interruptMode,
...(roundId || customInfo
...(roundId ? { RoundID: roundId } : {}),
...(customInfo ? { CustomInfo: customInfo } : {}),
botName: '<BOT_USER_ID>', // 替换为实际 Bot ID
message: '这是业务自定义的播报文本。', // 替换为实际播报文本
interruptMode: INTERRUPT_PRIORITY.HIGH, // 替换为实际优先级
roundId: 11, // 替换为实际 roundId
finish: true, // 替换为实际业务状态
biz: 'demo', // 替换为实际业务字段