Skip to content

Instantly share code, notes, and snippets.

@wilforlan
Created March 19, 2020 17:03
Show Gist options
  • Save wilforlan/55765bc036c977f26fb573bf67e2ead4 to your computer and use it in GitHub Desktop.
Save wilforlan/55765bc036c977f26fb573bf67e2ead4 to your computer and use it in GitHub Desktop.
<html>
<script src="./lib/WebAudioRecorder.js"></script>
<script src="./lib/aws-sdk-2.614.0.min.js"></script>
<script>
Mp3LameEncoderConfig = {
memoryInitializerPrefixURL: "lib/",
TOTAL_MEMORY: 1073741824,
}
</script>
<script src="./lib/Mp3LameEncoder.min.js"></script>
<!-- <script src="./lib/Mp3LameEncoder.min.js.mem"></script> -->
<!-- <script src="./lib/WebAudioRecorderMp3.js"></script> -->
<button onclick="startRecorder()"> Starting Recording! </button>
<button onclick="stopRecorder()"> Starting Recording! </button>
<script>
let s3Config = {
region: 'us-east-1',
accessKeyId: '',
secretAccessKey: '',
};
let s3 = new AWS.S3(s3Config);
let recorder;
function startRecorder(params) {
navigator.getUserMedia({ audio: true }, (stream) => {
console.log({ stream })
let audioCtx = new AudioContext();
let sourceNode = audioCtx.createMediaStreamSource(stream);
console.log({ sourceNode })
recorder = new WebAudioRecorder(sourceNode, {
workerDir: "lib/" // must end with slash
});
console.log({ recorder })
recorder.setEncoding('mp3');
recorder.setOptions({
timeLimit: 6000
});
recorder.startRecording()
recorder.onComplete = function(recorder, blob) {
console.log("BLOB:", { blob });
// var params = {
// Bucket: "rtmp-server-ff",
// Key: "thisislekandir/sample-audio-1.mp3",
// Body: blob,//this hast to be a string
// ACL: 'public-read',
// ContentType: 'audio/mpeg',
// };
// console.log({ params })
// s3.putObject(params, function(err,data){
// console.log({ err, data });
// console.log("LINK: ", `https://rtmp-server-ff.s3.amazonaws.com/${params.Key}`);
// // send to audio worker
// });
}
}, (err) => {
console.log({ err })
});
}
function stopRecorder(params) {
recorder.finishRecording();
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment