alphacep / alphacep/vosk-server
Replace deprecated onaudioprocess in Angular client demo
- Vorherrschende Sprache
- Python
- Sterne
- 1.3k
- Forks
- 317
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I've been trying to implement a client in Svelte that communicate to asr_server.py example via websocket, and while I can successfully connect with the following code:
```
const resampler = new Resampler(44100, 16000, 1, 50 * 1024, false); // this is set to 16000 because the model and asr-server are both set that way
const ctx = new AudioContext();
const input = ctx.createMediaStreamSource(stream);
const userSpeechAnalyser = ctx.createAnalyser();
input.connect(userSpeechAnalyser);
const node = input.context.createScriptProcessor(4096, 1, 1);
node.onaudioprocess = (e) => {
var samples = resampler.resampler(e.inputBuffer.getChannelData(0));
var dataview = encodeRAW(samples);
var audioBlob = new Blob([dataview], { type: "audio/raw" });
socket.send(audioBlob);
};
input.connect(node);
node.connect(input.context.destination);
```
I'm told that `node.onaudioprocess` is deprecated. Ideally, this could be updated.
I've looked into how I might do this, but to no avail. First, I tried replacing this code with an AudioWorklet, but AudioWorklets are probably the most convoluted replacements for ScriptProcessorNodes I could possibly imagine, and I haven't been able to get it to work.
Next, I tried using a MediaRecorder, which is able to produce Blobs and send them to the server, but return with empty results. I suspect the issue is that I'm not resampling the audio or something. The code for that is here:
```
const recorder = new MediaRecorder(stream, {
audioBitsPerSecond: 16000,
audioBitrateMode: "constant",
});
recorder.addEventListener("dataavailable", async ({ data }) => {
socket.send(data);
});
recorder.start(1000);
return recorder;
```
I'd appreciate if someone could help figure this out. I don't really care how it's implemented, so long as the method isn't deprecated.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.