Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express');
  2. var app = express();
  3. var http = require('http').Server(app);
  4. var io = require('socket.io')(http);
  5. var fs = require('fs');
  6.     //var decodeWav = require('audio-decode-wav');
  7.     //var btoa = require('btoa');
  8.     //var audio = decodeWav(raw);
  9.     //var base64 = btoa(audio.sample);
  10.  
  11. app.use(express.static(__dirname + '/public'));
  12.  
  13. app.get('/', function(req, res){
  14.   res.sendFile(__dirname + '/index.html');
  15. });
  16.  
  17. io.on('connection', function(socket){
  18.       var raw = fs.readFileSync('file.wav');
  19.       // console.log(raw);
  20.       // <Buffer 52 49 46 46 fa 05 02 00 57 41 56 45 66 6d 74 20 10 00 00 00 01 00 01 00 44 ac 00 00 88 58 01 00 02 00 10 00 64 61 74 61 d6 05 02 00 e3 ff c9 ff e4 ff ... >
  21.  
  22.       for (var i = 0; i < raw.length; i++) {
  23.         var audio = raw[i];
  24.         //console.log(raw[i]);
  25.         // 118, 252, 141, 252, 164, 252, 232, 252, 139, 253, 76, 254, 228, 254, 86, 255, 201, 255, 0, 0, 17, 0, 54, 0, 121, 0, 158, ...
  26.  
  27.         io.emit('binary', audio);
  28.       }
  29. });
  30.  
  31. http.listen(8888, function(){
  32.   console.log('\n\tServer listening on: http://localhost:8888/\n');
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement