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
+10 -2
View File
@@ -81,25 +81,32 @@ async function startRecord(option) {
};
const socket = new WebSocket("ws://localhost:9090/");
let isServerReady = false;
socket.onopen = function(e) {
socket.send("handshake");
};
socket.onmessage = async (event) => {
// console.log(event.data);
console.log(event.data);
if (isServerReady === false){
isServerReady = true;
return;
}
res = await sendMessageToTab(option.currentTabId, {
type: "transcript",
data: event.data,
});
};
const audioDataCache = [];
const context = new AudioContext();
const mediaStream = context.createMediaStreamSource(stream);
const recorder = context.createScriptProcessor(4096, 1, 1);
recorder.onaudioprocess = async (event) => {
if (!context) return;
if (!context || !isServerReady) return;
const inputData = event.inputBuffer.getChannelData(0);
const audioData16kHz = resampleTo16kHZ(inputData, context.sampleRate);
@@ -114,6 +121,7 @@ async function startRecord(option) {
mediaStream.connect(recorder);
recorder.connect(context.destination);
mediaStream.connect(context.destination);
// }
} else {
window.close();
}