wait for server to be ready with models

This commit is contained in:
makaveli10
2023-07-10 22:14:04 +05:30
parent 6a2a070f58
commit e32f597a42
3 changed files with 34 additions and 6 deletions
+6 -2
View File
@@ -45,8 +45,12 @@ function startRecording() {
socket.send("handshake");
};
let isServerReady = false;
socket.onmessage = (event) => {
// console.log(event.data);
if (!isServerReady){
isServerReady = true;
return;
}
const data = event.data;
browser.runtime.sendMessage({ action: "transcript", data })
.catch(function(error) {
@@ -64,7 +68,7 @@ function startRecording() {
recorder = audioContext.createScriptProcessor(4096, 1, 1);
recorder.onaudioprocess = async (event) => {
if (!audioContext || !isCapturing) return;
if (!audioContext || !isCapturing || !isServerReady) return;
const inputData = event.inputBuffer.getChannelData(0);
const audioData16kHz = resampleTo16kHZ(inputData, audioContext.sampleRate);