diff --git a/client/utils.js b/client/utils.js index a19915a..a038e3f 100644 --- a/client/utils.js +++ b/client/utils.js @@ -9,7 +9,6 @@ let websocket; let context; let processor; let globalStream; -let language; let isRecording = false; const websocketAddress = document.querySelector('#websocketAddress'); @@ -48,8 +47,6 @@ function resetWebsocketHandler() { } function connectWebsocketHandler() { - language = selectedLanguage.value !== 'multilingual' ? selectedLanguage.value : null; - if (!websocketAddress.value) { console.log("WebSocket address is required."); return; @@ -126,7 +123,12 @@ function startRecordingHandler() { isRecording = true; context = new AudioContext(); + let onSuccess = async (stream) => { + // Push user config to server + let language = selectedLanguage.value !== 'multilingual' ? selectedLanguage.value : null; + sendAudioConfig(language); + globalStream = stream; const input = context.createMediaStreamSource(stream); const recordingNode = await setupRecordingWorkletNode(); @@ -134,7 +136,6 @@ function startRecordingHandler() { processAudio(event.data); }; input.connect(recordingNode); - sendAudioConfig(); }; let onError = (error) => { console.error(error); @@ -182,7 +183,7 @@ function stopRecordingHandler() { stopButton.disabled = true; } -function sendAudioConfig() { +function sendAudioConfig(language) { let processingArgs = {}; if (selectedStrategy.value === 'silence_at_end_of_chunk') { diff --git a/src/server.py b/src/server.py index 00932df..809c7ad 100644 --- a/src/server.py +++ b/src/server.py @@ -1,4 +1,5 @@ import json +import logging import ssl import uuid @@ -57,6 +58,7 @@ async def handle_audio(self, client, websocket): config = json.loads(message) if config.get("type") == "config": client.update_config(config["data"]) + logging.debug(f"Updated config: {client.config}") continue else: print(f"Unexpected message type from {client.client_id}")