- 文档首页
实时音视频
AI 音视频互动方案
开发指南
暂停或恢复 AI 播报
暂停或恢复 AI 播报
在 AI 进行语音播报时,您可以通过服务端 API 或客户端发送指令,随时暂停或恢复其音频播放,实现类似音乐播放器的暂停/继续效果。
- 生效范围:该功能仅在 AI 正在进行 TTS 语音播报时生效,且仅对当前正在进行的对话轮次有效。当用户打断并开始新一轮对话时,上一轮的暂停状态会自动失效。
- 功能互斥:开启音频快速发送(AgentConfig.Burst)功能后,暂停或恢复 AI 音频播放功能将失效。
您可以根据业务需求,选择通过服务端 API 或客户端 SDK 发送指令来控制 AI 的播报状态。
通过调用 UpdateVoiceChat 接口,将 Command 设置为 AudioCtrl,并通过 AudioConfig.Action 来控制暂停或恢复播放。
"RoomId": "Your_RoomId",
"TaskId": "Your_TaskId",
- userId:填入 AI 的 ID(即 StartVoiceChat 配置的 AgentConfig.UserId)。
-
public void pauseAudio(String botUserId) {
JSONObject json = new JSONObject();
JSONObject audioConfig = new JSONObject();
audioConfig.put("Action", "pause");
json.put("Command", "AudioCtrl");
json.put("AudioConfig", audioConfig);
} catch (JSONException e) {
byte[] buildBinary = buildBinaryMessage("ctrl", json.toString());
rtcRoom.sendUserBinaryMessage(botUserId, buildBinary, MessageConfig.RELIABLE_ORDERED);
private byte[] buildBinaryMessage(String magic_number, String content) {
byte[] prefixBytes = magic_number.getBytes(StandardCharsets.UTF_8);
byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
ByteBuffer buffer = ByteBuffer.allocate(prefixBytes.length + 4 + contentBytes.length);
buffer.order(ByteOrder.BIG_ENDIAN);
buffer.put(prefixBytes);
buffer.putInt(contentBytes.length);
buffer.put(contentBytes);
void sendPauseMessage(const std::string &botUserId) {
nlohmann::json json_data;
json_data["Command"] = "AudioCtrl";
json_data["AudioConfig"]["Action"] = "pause";
std::string message = json_data.dump();
std::string magic = "ctrl";
uint32_t msg_len = message.size();
std::vector<uint8_t> buffer;
buffer.insert(buffer.end(), magic.begin(), magic.end());
buffer.push_back((msg_len >> 24) & 0xFF);
buffer.push_back((msg_len >> 16) & 0xFF);
buffer.push_back((msg_len >> 8) & 0xFF);
buffer.push_back(msg_len & 0xFF);
buffer.insert(buffer.end(), message.begin(), message.end());
rtcRoom_->sendUserBinaryMessage(botUserId.c_str(), buffer.size(), buffer.data());
const message = JSON.stringify({
AudioConfig: { Action: 'pause' }
engine.sendUserBinaryMessage(
stringToTLV(message, 'ctrl')
暂停和恢复播放功能本身不依赖于字幕。若希望在暂停/恢复时,字幕也能同步暂停和恢复渲染,您必须在调用 StartVoiceChat 接口时,将 SubtitleConfig.SubtitleMode 设置为 2(音频帧对齐字幕)。详情请参见音频和字幕同步(音频帧对齐字幕)。
最近更新时间:2026.07.19 13:52:11