Add non-streaming websocket server for python (#259)

This commit is contained in:
Fangjun Kuang
2023-08-11 15:56:24 +08:00
committed by GitHub
parent 6c0f002825
commit b094868fb8
24 changed files with 1247 additions and 92 deletions

View File

@@ -60,6 +60,7 @@ const soundClips = document.getElementById('sound-clips');
const canvas = document.getElementById('canvas');
const mainSection = document.querySelector('.container');
recordBtn.disabled = true;
stopBtn.disabled = true;
window.onload = (event) => {
@@ -95,9 +96,10 @@ clearBtn.onclick = function() {
};
function send_header(n) {
const header = new ArrayBuffer(4);
new DataView(header).setInt32(0, n, true /* littleEndian */);
socket.send(new Int32Array(header, 0, 1));
const header = new ArrayBuffer(8);
new DataView(header).setInt32(0, expectedSampleRate, true /* littleEndian */);
new DataView(header).setInt32(4, n, true /* littleEndian */);
socket.send(new Int32Array(header, 0, 2));
}
// copied/modified from https://mdn.github.io/web-dictaphone/

View File

@@ -88,6 +88,7 @@ const canvas = document.getElementById('canvas');
const mainSection = document.querySelector('.container');
stopBtn.disabled = true;
recordBtn.disabled = true;
let audioCtx;
const canvasCtx = canvas.getContext('2d');

View File

@@ -74,9 +74,11 @@ connectBtn.onclick = function() {
};
function send_header(n) {
const header = new ArrayBuffer(4);
new DataView(header).setInt32(0, n, true /* littleEndian */);
socket.send(new Int32Array(header, 0, 1));
const header = new ArrayBuffer(8);
// assume the uploaded wave is 16000 Hz
new DataView(header).setInt32(0, 16000, true /* littleEndian */);
new DataView(header).setInt32(4, n, true /* littleEndian */);
socket.send(new Int32Array(header, 0, 2));
}
function onFileChange() {