Created
March 2, 2016 12:20
-
-
Save dblencowe/b9d7fcc9f86d94c726db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
| <title></title> | |
| <style type='text/css'> | |
| ul { list-style: none; } | |
| #recordingslist audio { display: block; margin-bottom: 10px; } | |
| </style> | |
| </head> | |
| <body> | |
| <button id="record">record</button> | |
| <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/binaryjs/0.2.1/binary.min.js"></script> | |
| <script> | |
| navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia; | |
| window.URL = window.URL || window.webkitURL; | |
| function onError(error) { | |
| console.log(error); | |
| } | |
| function initializeRecorder(stream) { | |
| AudioContext = window.AudioContext || window.webkitAudioContext; | |
| window.context = new AudioContext(); | |
| var audioInput = window.context.createMediaStreamSource(stream); | |
| var bufferSize = 2048; | |
| // create a javascript node | |
| var recorder = window.context.createScriptProcessor(bufferSize, 1, 1); | |
| // specify the processing function | |
| recorder.onaudioprocess = recorderProcess; | |
| // connect stream to our recorder | |
| audioInput.connect(recorder); | |
| // connect our recorder to the previous destination | |
| recorder.connect(window.context.destination); | |
| } | |
| function convertFloat32ToInt16(buffer) { | |
| l = buffer.length; | |
| buf = new Int16Array(l); | |
| while (l--) { | |
| buf[l] = Math.min(1, buffer[l])*0x7FFF; | |
| } | |
| return buf.buffer; | |
| } | |
| function recorderProcess(e) { | |
| var left = e.inputBuffer.getChannelData(0); | |
| window.Stream.write(convertFloat32ToInt16(left)); | |
| } | |
| $('#record').on('mousedown', function (){ | |
| var session = { | |
| audio: true, | |
| video: false | |
| }; | |
| var recordRTC = null; | |
| navigator.getUserMedia(session, initializeRecorder, onError); | |
| window.client = new BinaryClient('ws://localhost:9001'); | |
| window.client.on('open', function() { | |
| window.Stream = client.createStream(); | |
| }); | |
| }).on('mouseup', function (){ | |
| window.context.close(); | |
| window.client.close(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment