Compare commits
2 Commits
9066e5b1f2
...
3dbe3105af
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dbe3105af | ||
|
|
638d5fc005 |
@@ -33,6 +33,7 @@
|
|||||||
"react": "^19.2.6",
|
"react": "^19.2.6",
|
||||||
"react-dom": "^19.2.6",
|
"react-dom": "^19.2.6",
|
||||||
"sodium-native": "^4.3.2",
|
"sodium-native": "^4.3.2",
|
||||||
|
"tone": "^15.1.22",
|
||||||
"ws": "^8.20.1",
|
"ws": "^8.20.1",
|
||||||
"zod": "^4.4.3"
|
"zod": "^4.4.3"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ const state = {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
state.opusDecoder = new AudioDecoder({
|
state.opusDecoder = new AudioDecoder({
|
||||||
output: (audioData) => playAudioData(audioData),
|
output: (audioData) => playAudioDataDirect(audioData),
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
console.error('Opus decode error:', error);
|
console.error('Opus decode error:', error);
|
||||||
showError(`Opus decode error: ${error.message}`);
|
showError(`Opus decode error: ${error.message}`);
|
||||||
@@ -458,34 +458,8 @@ const state = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function decodeOpus(opusBuffer) {
|
function playAudioDataDirect(audioData) {
|
||||||
if (!state.isListening || !state.opusDecoderReady) {
|
if (!state.audioContextListen || !state.isListening) {
|
||||||
if (state.isListening) {
|
|
||||||
state.opusDecodeQueue.push(opusBuffer);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const chunk = new EncodedAudioChunk({
|
|
||||||
type: 'key',
|
|
||||||
timestamp: 0,
|
|
||||||
data: opusBuffer,
|
|
||||||
});
|
|
||||||
state.opusDecoder.decode(chunk);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Opus decode chunk error:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function processOpusQueue() {
|
|
||||||
while (state.opusDecodeQueue.length > 0 && state.opusDecoderReady) {
|
|
||||||
const buffer = state.opusDecodeQueue.shift();
|
|
||||||
decodeOpus(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function playAudioData(audioData) {
|
|
||||||
if (!state.audioContextListen) {
|
|
||||||
audioData.close();
|
audioData.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -517,6 +491,32 @@ const state = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decodeOpus(opusBuffer) {
|
||||||
|
if (!state.isListening || !state.opusDecoderReady) {
|
||||||
|
if (state.isListening) {
|
||||||
|
state.opusDecodeQueue.push(opusBuffer);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const chunk = new EncodedAudioChunk({
|
||||||
|
type: 'key',
|
||||||
|
timestamp: 0,
|
||||||
|
data: opusBuffer,
|
||||||
|
});
|
||||||
|
state.opusDecoder.decode(chunk);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Opus decode chunk error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function processOpusQueue() {
|
||||||
|
while (state.opusDecodeQueue.length > 0 && state.opusDecoderReady) {
|
||||||
|
const buffer = state.opusDecodeQueue.shift();
|
||||||
|
decodeOpus(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function playPcm(arrayBuffer) {
|
function playPcm(arrayBuffer) {
|
||||||
if (!state.audioContextListen) return;
|
if (!state.audioContextListen) return;
|
||||||
const bytes = new Uint8Array(arrayBuffer);
|
const bytes = new Uint8Array(arrayBuffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user