mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 00:53:54 +08:00
Translate log messages to Chinese in recorder.js
This commit is contained in:
@@ -102,18 +102,18 @@ export class AudioRecorder {
|
|||||||
this.processPCMBuffer(event.data.buffer);
|
this.processPCMBuffer(event.data.buffer);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
log('Using AudioWorklet to process audio', 'success');
|
log('使用AudioWorklet处理音频', 'success');
|
||||||
const silent = this.audioContext.createGain();
|
const silent = this.audioContext.createGain();
|
||||||
silent.gain.value = 0;
|
silent.gain.value = 0;
|
||||||
audioProcessor.connect(silent);
|
audioProcessor.connect(silent);
|
||||||
silent.connect(this.audioContext.destination);
|
silent.connect(this.audioContext.destination);
|
||||||
return { node: audioProcessor, type: 'worklet' };
|
return { node: audioProcessor, type: 'worklet' };
|
||||||
} else {
|
} else {
|
||||||
log('AudioWorklet not available, using ScriptProcessorNode as fallback', 'warning');
|
log('AudioWorklet不可用,使用ScriptProcessorNode作为后备方案', 'warning');
|
||||||
return this.createScriptProcessor();
|
return this.createScriptProcessor();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`Failed to create audio processor: ${error.message}, trying fallback`, 'error');
|
log(`创建音频处理器失败: ${error.message},尝试后备方案`, 'error');
|
||||||
return this.createScriptProcessor();
|
return this.createScriptProcessor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,10 +136,10 @@ export class AudioRecorder {
|
|||||||
silent.gain.value = 0;
|
silent.gain.value = 0;
|
||||||
scriptProcessor.connect(silent);
|
scriptProcessor.connect(silent);
|
||||||
silent.connect(this.audioContext.destination);
|
silent.connect(this.audioContext.destination);
|
||||||
log('Using ScriptProcessorNode as fallback successfully', 'warning');
|
log('使用ScriptProcessorNode作为后备方案成功', 'warning');
|
||||||
return { node: scriptProcessor, type: 'processor' };
|
return { node: scriptProcessor, type: 'processor' };
|
||||||
} catch (fallbackError) {
|
} catch (fallbackError) {
|
||||||
log(`Fallback also failed: ${fallbackError.message}`, 'error');
|
log(`后备方案也失败: ${fallbackError.message}`, 'error');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ export class AudioRecorder {
|
|||||||
// Encode and send Opus data
|
// Encode and send Opus data
|
||||||
encodeAndSendOpus(pcmData = null) {
|
encodeAndSendOpus(pcmData = null) {
|
||||||
if (!this.opusEncoder) {
|
if (!this.opusEncoder) {
|
||||||
log('Opus encoder not initialized', 'error');
|
log('Opus编码器未初始化', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -174,13 +174,13 @@ export class AudioRecorder {
|
|||||||
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
||||||
try {
|
try {
|
||||||
this.websocket.send(opusData.buffer);
|
this.websocket.send(opusData.buffer);
|
||||||
log(`Sent Opus frame, size: ${opusData.length} bytes`, 'debug');
|
log(`已发送Opus帧,大小: ${opusData.length} 字节`, 'debug');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`WebSocket send error: ${error.message}`, 'error');
|
log(`WebSocket发送错误: ${error.message}`, 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log('Opus encoding failed, no valid data returned', 'error');
|
log('Opus编码失败,未返回有效数据', 'error');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (this.pcmDataBuffer.length > 0) {
|
if (this.pcmDataBuffer.length > 0) {
|
||||||
@@ -196,7 +196,7 @@ export class AudioRecorder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`Opus encoding error: ${error.message}`, 'error');
|
log(`Opus编码错误: ${error.message}`, 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,14 +212,14 @@ export class AudioRecorder {
|
|||||||
const abortMessage = { session_id: wsHandler.currentSessionId, type: 'abort', reason: 'wake_word_detected' };
|
const abortMessage = { session_id: wsHandler.currentSessionId, type: 'abort', reason: 'wake_word_detected' };
|
||||||
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
||||||
this.websocket.send(JSON.stringify(abortMessage));
|
this.websocket.send(JSON.stringify(abortMessage));
|
||||||
log('Sent abort message', 'info');
|
log('已发送中止消息', 'info');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!this.initEncoder()) {
|
if (!this.initEncoder()) {
|
||||||
log('Unable to start recording: Opus encoder initialization failed', 'error');
|
log('无法开始录音: Opus编码器初始化失败', 'error');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
log('Please record at least 1-2 seconds of audio to ensure sufficient data is collected', 'info');
|
log('请至少录制1-2秒音频以确保收集足够的数据', 'info');
|
||||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true, sampleRate: 16000, channelCount: 1 } });
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true, sampleRate: 16000, channelCount: 1 } });
|
||||||
this.audioContext = this.getAudioContext();
|
this.audioContext = this.getAudioContext();
|
||||||
if (this.audioContext.state === 'suspended') {
|
if (this.audioContext.state === 'suspended') {
|
||||||
@@ -227,7 +227,7 @@ export class AudioRecorder {
|
|||||||
}
|
}
|
||||||
const processorResult = await this.createAudioProcessor();
|
const processorResult = await this.createAudioProcessor();
|
||||||
if (!processorResult) {
|
if (!processorResult) {
|
||||||
log('Unable to create audio processor', 'error');
|
log('无法创建音频处理器', 'error');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.audioProcessor = processorResult.node;
|
this.audioProcessor = processorResult.node;
|
||||||
@@ -246,9 +246,9 @@ export class AudioRecorder {
|
|||||||
}
|
}
|
||||||
// Send listening start message
|
// Send listening start message
|
||||||
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
||||||
log(`Sent recording start message`, 'info');
|
log(`已发送录音开始消息`, 'info');
|
||||||
} else {
|
} else {
|
||||||
log('WebSocket not connected, unable to send start message', 'error');
|
log('WebSocket未连接,无法发送开始消息', 'error');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Start visualization
|
// Start visualization
|
||||||
@@ -268,10 +268,10 @@ export class AudioRecorder {
|
|||||||
this.onRecordingStart(recordingSeconds);
|
this.onRecordingStart(recordingSeconds);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
log('Started PCM direct recording', 'success');
|
log('已开始PCM直接录音', 'success');
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`Direct recording start error: ${error.message}`, 'error');
|
log(`直接录音启动错误: ${error.message}`, 'error');
|
||||||
this.isRecording = false;
|
this.isRecording = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -320,15 +320,15 @@ export class AudioRecorder {
|
|||||||
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
|
||||||
const emptyOpusFrame = new Uint8Array(0);
|
const emptyOpusFrame = new Uint8Array(0);
|
||||||
this.websocket.send(emptyOpusFrame);
|
this.websocket.send(emptyOpusFrame);
|
||||||
log('Sent recording stop signal', 'info');
|
log('已发送录音停止信号', 'info');
|
||||||
}
|
}
|
||||||
if (this.onRecordingStop) {
|
if (this.onRecordingStop) {
|
||||||
this.onRecordingStop();
|
this.onRecordingStop();
|
||||||
}
|
}
|
||||||
log('Stopped PCM direct recording', 'success');
|
log('已停止PCM直接录音', 'success');
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`Direct recording stop error: ${error.message}`, 'error');
|
log(`直接录音停止错误: ${error.message}`, 'error');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -356,7 +356,7 @@ export function getAudioRecorder() {
|
|||||||
export async function checkMicrophoneAvailability() {
|
export async function checkMicrophoneAvailability() {
|
||||||
// Check if browser supports getUserMedia API
|
// Check if browser supports getUserMedia API
|
||||||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||||
log('Browser does not support getUserMedia API', 'warning');
|
log('浏览器不支持getUserMedia API', 'warning');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -364,10 +364,10 @@ export async function checkMicrophoneAvailability() {
|
|||||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true, sampleRate: 16000, channelCount: 1 } });
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true, sampleRate: 16000, channelCount: 1 } });
|
||||||
// Immediately stop all tracks to release microphone
|
// Immediately stop all tracks to release microphone
|
||||||
stream.getTracks().forEach(track => track.stop());
|
stream.getTracks().forEach(track => track.stop());
|
||||||
log('Microphone availability check successful', 'success');
|
log('麦克风可用性检查成功', 'success');
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(`Microphone not available: ${error.message}`, 'warning');
|
log(`麦克风不可用: ${error.message}`, 'warning');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user