Fixess
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "global.h"
|
||||
|
||||
static pthread_t selfTID{pthread_self()};
|
||||
void throwJS(const char* msg, bool err) {
|
||||
EM_ASM({
|
||||
@@ -13,16 +14,13 @@ void fireEv(const char *type, const char *content, int index) {
|
||||
static ProxyingQueue pq{};
|
||||
auto proxy{[index, type, content](){
|
||||
EM_ASM({
|
||||
console.log("Event type ", UTF8ToString($1), ", content " , UTF8ToString($2), ", sending to ", objs[$0]);
|
||||
objs[$0].dispatchEvent(new CustomEvent(UTF8ToString($1), {"detail" : UTF8ToString($2)}));
|
||||
},index, type, content);
|
||||
}};
|
||||
if(selfTID == pthread_self()) {
|
||||
emscripten_console_log("Self dispatch");
|
||||
proxy();
|
||||
return;
|
||||
}
|
||||
emscripten_console_log("Thread dispatch");
|
||||
pq.proxySync(selfTID, proxy);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class Recognizer extends EventTarget {
|
||||
async getNode(ctx, channelIndex = 0) {
|
||||
if(typeof this.node === "undefined") {
|
||||
let msgChannel = new MessageChannel()
|
||||
ctx.AudioWorklet.addModule("../src/processor.js")
|
||||
await ctx.audioWorklet.addModule(processorUrl)
|
||||
this.node = new AudioWorkletNode(ctx, 'BRProcessor', { channelCountMode: "max", numberOfInputs: 1, numberOfOutputs: 1 })
|
||||
this.node.port.postMessage({cmd : "init", ptr: this.ptr, channel: channelIndex}, [msgChannel.port1])
|
||||
msgChannel.port1.onmessage = (ev) => {
|
||||
|
||||
@@ -1,28 +1,26 @@
|
||||
// A copy and pass processor, check if already registered
|
||||
if(typeof BRProcessor === "undefined") {
|
||||
var BRProcessor = class extends AudioWorkletProcessor {
|
||||
constructor(options) {
|
||||
super(options)
|
||||
this.done = false
|
||||
this.port.onmessage = (ev) => {
|
||||
switch(ev.cmd) {
|
||||
case "init":
|
||||
this.recognizerPort = ev.ports[0]
|
||||
this.wasmMem = new Float32Array(WebAssembly.Memory.buffer).subarray(ev.ptr, ev.ptr+512)
|
||||
this.channel = ev.channel;
|
||||
break
|
||||
case "deinit":
|
||||
this.done = true
|
||||
}
|
||||
// A copy and pass processor
|
||||
registerProcessor("BRProcessor", class extends AudioWorkletProcessor {
|
||||
constructor(options) {
|
||||
super(options)
|
||||
this.done = false
|
||||
this.port.onmessage = (ev) => {
|
||||
switch(ev.cmd) {
|
||||
case "init":
|
||||
this.recognizerPort = ev.ports[0]
|
||||
this.wasmMem = new Float32Array(WebAssembly.Memory.buffer).subarray(ev.ptr, ev.ptr+512)
|
||||
this.channel = ev.channel
|
||||
|
||||
break
|
||||
case "deinit":
|
||||
this.done = true
|
||||
}
|
||||
}
|
||||
process(inputs, outputs, params) {
|
||||
if(this.done) return false;
|
||||
this.wasmMem.set(inputs[0].getChannelData(this.channel));
|
||||
this.recognizerPort.postMessage(".")
|
||||
outputs = inputs
|
||||
return true
|
||||
}
|
||||
}
|
||||
registerProcessor("BRProcessor", BRProcessor)
|
||||
}
|
||||
process(inputs, outputs, params) {
|
||||
if(this.done) return false;
|
||||
this.wasmMem.set(inputs[0].getChannelData(this.channel));
|
||||
this.recognizerPort.postMessage(".")
|
||||
outputs = inputs
|
||||
return true
|
||||
}
|
||||
})
|
||||
File diff suppressed because one or more lines are too long
@@ -8,7 +8,6 @@
|
||||
|
||||
const model = await BrRec.makeModel("en-model.tzst","model","en0.0.1")
|
||||
let ctx = new AudioContext()
|
||||
|
||||
const recognizer = await BrRec.makeRecognizer(model, ctx.sampleRate)
|
||||
recognizer.addEventListener("result", e => {
|
||||
console.log("Result: ",e.details)
|
||||
@@ -16,7 +15,6 @@
|
||||
recognizer.addEventListener("partialResult", e => {
|
||||
console.log("Partial result: ",e.details)
|
||||
})
|
||||
|
||||
let micNode = ctx.createMediaStreamSource(await navigator.mediaDevices.getUserMedia({
|
||||
video: false,
|
||||
audio: {
|
||||
|
||||
Reference in New Issue
Block a user