-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Streaming encoder #23
Comments
Yes, it's possible, just need to make I'm not sure if we want to use that method for normal recordings, because it would require to send every encoded chunk back to the main thread and copy it to the buffer, it might introduce additional delay. But should be ok to make it optional. |
Ok, I understand. |
Hi there, I took a stab at making this work and I wanted to check with you if this is the right way to do it. case "data":
if (!vmsg_encode(msg.data)) return postMessage({type: "error", data: "vmsg_encode"});
const blob = vmsg_flush();
if (!blob) {
return postMessage({type: "error", data: "vmsg_flush"});
}
postMessage({
type: "blob",
data: blob
});
FFI.vmsg_reset()
break; This will return the blob for that specific buffer each time. The changes that I've made are: WASM_EXPORT
int vmsg_encode(vmsg *v, int nsamples) {
if (nsamples > MAX_SAMPLES)
return -1;
if (fix_mp3_size(v) < 0)
return -1;
uint8_t *buf = v->mp3 + v->size;
int n = lame_encode_buffer_ieee_float(v->gfp, v->pcm_l, NULL, nsamples, buf, BUF_SIZE);
if (n < 0)
return n;
v->size += n;
return v->size;
} And the new method: WASM_EXPORT
int vmsg_reset(vmsg *v, int rate) {
if (v) {
lame_close(v->gfp);
v->size = 0;
v->gfp = lame_init();
if (!v->gfp) {
vmsg_free(v);
return -1;
}
lame_set_mode(v->gfp, MONO);
lame_set_num_channels(v->gfp, 1);
lame_set_in_samplerate(v->gfp, rate);
lame_set_VBR(v->gfp, vbr_default);
lame_set_VBR_quality(v->gfp, 5);
if (lame_init_params(v->gfp) < 0) {
vmsg_free(v);
return -1;
}
}
return 0;
} This basically looks like init but without the memory allocation. |
@onel did you get it working ? i am also interested in this for live speech to text (on the server) |
Damn. I want this too. What if we fake it and just swap the encoder with a new one every few seconds? I'm fine with lots of relatively short mp3s. |
Ah I think I'll simply use MediaRecorder. It should record as .webm, right? |
First of all, thanks for this great library.
I have a question: is there a way to do encoding of a specific audio buffer and only get that back, and not the whole recording?
For example, sending a Float32Array, vmsg encodes it and then sends it back.
Right now I think during a recording, everything is held in memory and returned when calling
vmsg_flush()
.This would be useful for longer recordings where you want to encode something and maybe upload it and not keep it in memory.
I've tried to do something similar, by calling
vmsg_init
,vmsg_encode
and thenvmsg_flush
, inside thedata
event listener for the worker. I don't think this is the right way to do it.Is there a way to do that? A change would also need to be made inside
vmsg.c
, right?Thanks
The text was updated successfully, but these errors were encountered: