mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 10:03:54 +08:00
fix:修复“小智服务器测试页面播放语音问题”
This commit is contained in:
@@ -879,6 +879,7 @@
|
|||||||
// 流已结束且没有更多数据
|
// 流已结束且没有更多数据
|
||||||
log("音频播放完成", 'info');
|
log("音频播放完成", 'info');
|
||||||
isAudioPlaying = false;
|
isAudioPlaying = false;
|
||||||
|
this.endOfStream = false;
|
||||||
streamingContext = null;
|
streamingContext = null;
|
||||||
} else {
|
} else {
|
||||||
// 等待更多数据
|
// 等待更多数据
|
||||||
@@ -1409,6 +1410,17 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
websocket.onclose = () => {
|
websocket.onclose = () => {
|
||||||
|
|
||||||
|
// 清理音频缓冲和播放状态
|
||||||
|
audioBufferQueue = [];
|
||||||
|
isAudioBuffering = false;
|
||||||
|
isAudioPlaying = false;
|
||||||
|
streamingContext = null;
|
||||||
|
if (visualizationRequest) {
|
||||||
|
cancelAnimationFrame(visualizationRequest);
|
||||||
|
visualizationRequest = null;
|
||||||
|
}
|
||||||
|
|
||||||
log('已断开连接', 'info');
|
log('已断开连接', 'info');
|
||||||
connectionStatus.textContent = 'ws已断开';
|
connectionStatus.textContent = 'ws已断开';
|
||||||
connectionStatus.style.color = 'red';
|
connectionStatus.style.color = 'red';
|
||||||
@@ -1563,6 +1575,10 @@
|
|||||||
const message = messageInput.value.trim();
|
const message = messageInput.value.trim();
|
||||||
if (message === '' || !websocket || websocket.readyState !== WebSocket.OPEN) return;
|
if (message === '' || !websocket || websocket.readyState !== WebSocket.OPEN) return;
|
||||||
|
|
||||||
|
audioBufferQueue = [];
|
||||||
|
isAudioBuffering = false;
|
||||||
|
isAudioPlaying = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 直接发送listen消息,不需要重复发送hello
|
// 直接发送listen消息,不需要重复发送hello
|
||||||
const listenMessage = {
|
const listenMessage = {
|
||||||
@@ -2382,6 +2398,8 @@
|
|||||||
// 如果收到的是第一个音频包,开始缓冲过程
|
// 如果收到的是第一个音频包,开始缓冲过程
|
||||||
if (audioBufferQueue.length === 1 && !isAudioBuffering && !isAudioPlaying) {
|
if (audioBufferQueue.length === 1 && !isAudioBuffering && !isAudioPlaying) {
|
||||||
startAudioBuffering();
|
startAudioBuffering();
|
||||||
|
} else if (isAudioPlaying && streamingContext) {
|
||||||
|
streamingContext.decodeOpusFrames([opusData]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log('收到空音频数据帧,可能是结束标志', 'warning');
|
log('收到空音频数据帧,可能是结束标志', 'warning');
|
||||||
|
|||||||
Reference in New Issue
Block a user