-
Notifications
You must be signed in to change notification settings - Fork 111
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
Enable writing to a stream? #44
Comments
Yes, you can write data like that, but |
Thanks for your response, does an ArrayBuffer count as a Buffer? That's what I'm attempting to use. |
ArrayBuffer is not Buffer, and I think you need browserify to use Buffer on browser. This is very confusing for users. We have to fix that :( |
I wonder if a better solution would be to use socket.io without socket.io-stream and just send my array buffers to have them assembled for me on the server instead. Forgive me for not knowing this but the emits are sent in order if I do that correct? They cannot get all jumbled up? Or should I change my stream#write calls with socket.io-stream to pass strings and then finagle them a bit on the server after that. |
Socket.io keeps order of sending data. so you can just use socket.io, but splitting data to small chunks and combining them afterwards would be usually troublesome. So basically, this is what socket.io-stream should support. |
I exposed It's just Buffer on node, and you can use it like: sream.write(new ss.Buffer([1,2,3,4,5])); |
I'm making an effort to convert my typed array into Buffer before writing it to the stream. For some reason I don't think Buffer is turning up properly client side.
returns:
on line 2 above. I think I'm compiling properly from console.
Then I copy and paste the contents of that file into my client side javascript. I see your change in there.
I'm not sure what's wrong. |
Sorry, it's not released yet. if you'd like to try, change dependencies on package.json like |
You're right. I was mistaken, I got that working... but... :(
It's not your fault, this whole week has been a bust so far. |
As a contrast, this all works perfectly sans the _convertInt16toBuffer method, with binaryjs, I'd like to move away from binaryjs. It seems socket.io-stream just doesn't quite like my ss.Buffer generated buffer somehow. I've also tried returning buf rather than buf.buffer from _convertFloat32ToInt16 with the same result. |
Hmm, I don't know why. As far as I tested, it seems to work well. |
browserify@9.0.8 /usr/local/lib/node_modules/browserify |
It looks ok. Sorry, I have no idea ... var stream = ss.createStream();
ss(socket).emit('foo', stream);
stream.write(new ss.Buffer([0, 1]));
stream.write(new ss.Buffer([2, 3]));
stream.end(); Works fine with Browserify 9.0.8, on Chrome. What's the difference? |
I dunno man, I'm emitting just the same way. I double checked my convert from arraybuffer to buffer code from somewhere else on the net. I suppose I'm just generating an invalid arraybuffer... or who knows what else. I'm really sorry I'm not more help. I think for now my implementation doesn't work and I'll need to hack with someone on it. Peer programming in my future. |
@Kequc Server code:ss(socket).on('stream_start', function(stream, meta) {
filename = "recordings/"+ new Date().getTime() + ".pcm";
fileWriter = fs.createWriteStream(filename);
stream.pipe(fileWriter);
});
ss(socket).on('close', function() {
if (fileWriter != null) {
fileWriter.end();
}
}); Client code:function onAudio(e) {
if(!bStream || !bStream.writable)
{
return;
};
var left = e.inputBuffer.getChannelData(0);
var canvas = document.getElementById("canvas");
drawBuffer( canvas.width, canvas.height, canvas.getContext('2d'), left );
console.log("onAudio");
reSample(e.inputBuffer,resampleRate,function(reSampledBuffer){
var channel = reSampledBuffer.getChannelData(0);
bStream.write(convertFloat32ToInt16(channel));
});
}
function convertFloat32ToInt16(buffer) {
var l = buffer.length;
var buf = new Int16Array(l);
var return_buf = new ss.Buffer(l);
while (l--) {
buf[l] = Math.min(1, buffer[l])*0x7FFF;
return_buf[l] = buf[l];
if (l % 100 == 0){
console.log(return_buf[l]);
}
}
return return_buf;
} |
@wyvernbai were you ever able to get it working? Got about as far as you, but not able to save as a .wav |
My implementation that works has me sending base64 encoded data (strings) in chunks to the server, then decoding base64 and writing it to a stream. I'm using a version of this library: https://github.com/chris-rudmin/Recorderjs which encodes my audio into the opus audio codec. The library seems to be fluctuating currently, so it is changing, but it works well to ensure I'm sending a smaller amount of data than wav would require. Then on the server I simply put it together using Edit: Specifically I'm using my fork. Which is quite out of date by now, but in case it is useful: https://github.com/Kequc/Recorderjs |
Ahh, that's a good approach. Thanks for the detailed response. I will try On Mon, Aug 8, 2016 at 2:45 PM, Kequc notifications@github.com wrote:
|
I'm trying to write data to the stream as it comes in, but nothing seems to be getting sent from the client to the server. When I attach an 'on data' event listener on the client everything breaks. When I attach an 'on data' event listener on the server it is never triggered.
Error triggered on line 4 above.
I had everything working with Binaryjs, I wonder am I allowed to write to the stream like that with socket.io-stream?
The text was updated successfully, but these errors were encountered: