Giter VIP home page Giter VIP logo

soundrecorder's Introduction

SoundRecorder

Some web applications require an MP3 recorder to record sound directly from the user. The sound is converted to mono MP3 format with an adjustable sample rate and bit rate to reduce the output file size.

A page can contain several MP3 recorders that can be used interchangeably. The recording process can be paused and can be resumed to continue the recording process.

Reqirement

  1. Lame
  2. jQuery 1.11.1

Example

<html>
<head>
    <title>MP3 Recorder</title>
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/css.css">
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" src="js/lame.js"></script>
	<script type="text/javascript" src="js/js.js"></script>
</head>

<body>
<style type="text/css">
.audio-tool-wrapper {
	display:flex;
	justify-content:center;
}

.audio-tool-wrapper > span {
	width:100px;
	margin:8px;
	text-align:center;
	position:relative;
	display:block;
}
</style>

<h1>MP3 Recorder</h1>
	<div class="audio-recorder" data-question-id="12" data-audio-index="1">
    	<div class="audio-tool-wrapper">
        	<span><a class="audio-tool tool-browse" title="Pilih File Suara"><span></span></a></span>
        	<span><a class="audio-tool tool-record" title="Rekam Langsung"><span></span></a></span>
        	<span><a class="audio-tool tool-play" title="Dengarkan"><span></span></a></span>
        	<span><a class="audio-tool tool-stop" title="Hentikan"><span></span></a></span>
        	<span><a class="audio-tool tool-upload" title="Unggah Suara"><span></span></a></span>
        	<span><a class="audio-tool tool-download" title="Unduh Suara"><span></span></a></span>
        	<span><a class="audio-tool tool-delete" title="Hapus Suara"><span></span></a></span>
            <span><span class="tool-timer"><i></i></span></span>
        </div>
    </div>
	<div class="audio-recorder" data-question-id="12" data-audio-index="2">
    	<div class="audio-tool-wrapper">
        	<span><a class="audio-tool tool-browse"><span></span></a></span>
        	<span><a class="audio-tool tool-record"><span></span></a></span>
        	<span><a class="audio-tool tool-play"><span></span></a></span>
        	<span><a class="audio-tool tool-stop"><span></span></a></span>
        	<span><a class="audio-tool tool-upload"><span></span></a></span>
        	<span><a class="audio-tool tool-download"><span></span></a></span>
        	<span><a class="audio-tool tool-delete"><span></span></a></span>
            <span><span class="tool-timer"><i></i></span></span>
        </div>
    </div>
<script type="text/javascript">

var audioRecorder = {
	initialized:false,
	recorder:[]
};
var params = {
	bitrate:32,
	sampleRate:44100,
	timeLimit:1800,
	uploadSound:function(audio, duration, index, questionID, audioIndex){
		console.log(audio.src);
		audioRecorder.recorder[index].beforeUpload();
		setTimeout(function(){
			audioRecorder.recorder[index].afterUpload();
		}, 2000);
		var url = audio.src;
		$.ajax({
			url:'upload-sound.php',
			type:'POST',
			dataType:"json",
			data:{
				sound_data:url,
				question_id:questionID,
				audio_index:audioIndex
			},
			success: function(data)
			{
				console.log('Uploaded');
			}
		});     
	},
	downloadSound:function(audio, duration, index, questionID, audioIndex)
	{
		console.log(audio.src);

		//Create a URL to the blob.
		/*
		var url = window.URL.createObjectURL(blob);
		window.open(url);
		*/

	},
	nullAudio:function()
	{
		alert('Belum ada audio cuyy! Selesaikan rekaman dulu...');
	},
	stillRecording:function()
	{
		alert('Masih merekam cuyy! Selesaikan dulu yach...');
	},
	stillPlaying:function()
	{
		alert('Masih memutar cuyy! Ga boleh merekam dulu... Pause dulu kek, atau tunggu selesai...');
	},
	overLimit:function()
	{
		alert('Melebihi batas');
	},
	log:function(text)
	{
		console.log(text);
	}
};

$(document).ready(function(e) {

	$(document).on('click', '.audio-recorder .tool-browse', function(e)
	{
		var audioController = $(this).closest('.audio-recorder');
		var idx = audioController.attr("data-index") || "";
		if(idx == "")
		{
			var index = audioRecorder.recorder.length;
			audioRecorder.recorder.push(new MP3Recorder(audioController, index, 'browse', params));
		}
		
	});
	
	$(document).on('click', '.audio-recorder .tool-record', function(e)
	{		
		var audioController = $(this).closest('.audio-recorder');
		var idx = audioController.attr("data-index") || "";
		if(idx == "")
		{
			var index = audioRecorder.recorder.length;
			audioRecorder.recorder.push(new MP3Recorder(audioController, index, 'record', params));
		}
	})	
});

</script>
</body>
</html>

soundrecorder's People

Contributors

kamshory avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.