Add non-streaming websocket server for python (#259)
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
# How to use
|
||||
|
||||
```bash
|
||||
git clone https://github.com/k2-fsa/sherpa
|
||||
|
||||
cd sherpa/sherpa/bin/web
|
||||
python3 -m http.server 6009
|
||||
```
|
||||
and then go to <http://localhost:6009>
|
||||
|
||||
You will see a page like the following screenshot:
|
||||
|
||||

|
||||
|
||||
If your server is listening at the port *6006* with address **localhost**,
|
||||
then you can either click **Upload**, **Streaming_Record** or **Offline_Record** to play with it.
|
||||
|
||||
## File descriptions
|
||||
|
||||
### ./css/bootstrap.min.css
|
||||
|
||||
It is downloaded from https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css
|
||||
|
||||
### ./js/jquery-3.6.0.min.js
|
||||
|
||||
It is downloaded from https://code.jquery.com/jquery-3.6.0.min.js
|
||||
|
||||
### ./js/popper.min.js
|
||||
|
||||
It is downloaded from https://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js
|
||||
|
||||
### ./js/bootstrap.min.js
|
||||
|
||||
It is download from https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js
|
||||
@@ -35,8 +35,8 @@ Otherwise, you may get the following error from within you browser:
|
||||
|
||||
|
||||
def cert_gen(
|
||||
emailAddress="https://github.com/k2-fsa/k2",
|
||||
commonName="sherpa",
|
||||
emailAddress="https://github.com/k2-fsa/sherpa-onnx",
|
||||
commonName="sherpa-onnx",
|
||||
countryName="CN",
|
||||
localityName="k2-fsa",
|
||||
stateOrProvinceName="k2-fsa",
|
||||
@@ -70,17 +70,13 @@ def cert_gen(
|
||||
cert.set_pubkey(k)
|
||||
cert.sign(k, "sha512")
|
||||
with open(CERT_FILE, "wt") as f:
|
||||
f.write(
|
||||
crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8")
|
||||
)
|
||||
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8"))
|
||||
with open(KEY_FILE, "wt") as f:
|
||||
f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8"))
|
||||
|
||||
with open(ALL_IN_ONE_FILE, "wt") as f:
|
||||
f.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k).decode("utf-8"))
|
||||
f.write(
|
||||
crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8")
|
||||
)
|
||||
f.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert).decode("utf-8"))
|
||||
print(f"Generated {CERT_FILE}")
|
||||
print(f"Generated {KEY_FILE}")
|
||||
print(f"Generated {ALL_IN_ONE_FILE}")
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
</ul>
|
||||
|
||||
Code is available at
|
||||
<a href="https://github.com/k2-fsa/sherpa"> https://github.com/k2-fsa/sherpa</a>
|
||||
<a href="https://github.com/k2-fsa/sherpa-onnx"> https://github.com/k2-fsa/sherpa-onnx</a>
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
|
||||
@@ -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/
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
<button class="btn btn-block btn-primary" type="button" id="connect">Click me to connect</button>
|
||||
</div>
|
||||
<span class="input-group-text" id="ws-protocol">ws://</span>
|
||||
<input type="text" id="server-ip" class="form-control" placeholder="Sherpa server IP, e.g., localhost" aria-label="sherpa server IP">
|
||||
<input type="text" id="server-ip" class="form-control" placeholder="Sherpa-onnx server IP, e.g., localhost" aria-label="sherpa-onnx server IP">
|
||||
<span class="input-group-text">:</span>
|
||||
<input type="text" id="server-port" class="form-control" placeholder="Sherpa server port, e.g., 6006" aria-label="sherpa server port">
|
||||
<input type="text" id="server-port" class="form-control" placeholder="Sherpa-onnx server port, e.g., 6006" aria-label="sherpa-onnx server port">
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
<button class="btn btn-block btn-primary" type="button" id="connect">Click me to connect</button>
|
||||
</div>
|
||||
<span class="input-group-text" id="ws-protocol">ws://</span>
|
||||
<input type="text" id="server-ip" class="form-control" placeholder="Sherpa server IP, e.g., localhost" aria-label="sherpa server IP">
|
||||
<input type="text" id="server-ip" class="form-control" placeholder="Sherpa-onnx server IP, e.g., localhost" aria-label="sherpa-onnx server IP">
|
||||
<span class="input-group-text">:</span>
|
||||
<input type="text" id="server-port" class="form-control" placeholder="Sherpa server port, e.g., 6006" aria-label="sherpa server port">
|
||||
<input type="text" id="server-port" class="form-control" placeholder="Sherpa-onnx server port, e.g., 6006" aria-label="sherpa-onnx server port">
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
<button class="btn btn-block btn-primary" type="button" id="connect">Click me to connect</button>
|
||||
</div>
|
||||
<span class="input-group-text" id="ws-protocol">ws://</span>
|
||||
<input type="text" id="server-ip" class="form-control" placeholder="Sherpa server IP, e.g., localhost" aria-label="sherpa server IP">
|
||||
<input type="text" id="server-ip" class="form-control" placeholder="Sherpa-onnx server IP, e.g., localhost" aria-label="sherpa-onnx server IP">
|
||||
<span class="input-group-text">:</span>
|
||||
<input type="text" id="server-port" class="form-control" placeholder="Sherpa server port, e.g., 6006" aria-label="sherpa server port">
|
||||
<input type="text" id="server-port" class="form-control" placeholder="Sherpa-onnx server port, e.g., 6006" aria-label="sherpa-onnx server port">
|
||||
</div>
|
||||
|
||||
<form>
|
||||
|
||||
Reference in New Issue
Block a user