在javascript中将录制的音频文件保存到数据库

时间:2015-06-22 22:21:46

标签: javascript audio

我是JavaScript的新手,我想创建一个.Net网络应用程序,用于记录麦克风中的音频文件(wma)并将其保存到SQL Server数据库中,以便稍后播放,

以下是我使用的示例:GitHub

在该示例中,音频文件是由我不知道* .wma文件在哪里记录的,因此我可以将其流式传输并保存到我的数据库中。

我在哪里可以找到物理音频文件?

<script>
        function __log(e, data) {
            log.innerHTML += "\n" + e + " " + (data || '');
        }

        var audio_context;
        var recorder;

        function startUserMedia(stream) {
            var input = audio_context.createMediaStreamSource(stream);
            __log('Media stream created.');

            // Uncomment if you want the audio to feedback directly
            //input.connect(audio_context.destination);
            //__log('Input connected to audio context destination.');

            recorder = new Recorder(input);
            __log('Recorder initialised.');
        }

        function startRecording(button) {
            recorder && recorder.record();
            button.disabled = true;
            button.nextElementSibling.disabled = false;
            __log('Recording...');
        }

        function stopRecording(button) {
            recorder && recorder.stop();
            button.disabled = true;
            button.previousElementSibling.disabled = false;
            __log('Stopped recording.');

            // create WAV download link using audio data blob
            createDownloadLink();

            recorder.clear();
        }

        function createDownloadLink() {
            recorder && recorder.exportWAV(function (blob) {
                var url = URL.createObjectURL(blob);
                var li = document.createElement('li');
                var au = document.createElement('audio');
                var hf = document.createElement('a');

                au.controls = true;
                au.src = url;
                alert(url);
                hf.href = url;
                hf.download = new Date().toISOString() + '.wav';
                hf.innerHTML = hf.download;
                li.appendChild(au);
                li.appendChild(hf);
                recordingslist.appendChild(li);
            });
        }

        window.onload = function init() {
            try {
                // webkit shim
                window.AudioContext = window.AudioContext || window.webkitAudioContext;
                navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
                window.URL = window.URL || window.webkitURL;

                audio_context = new AudioContext;
                __log('Audio context set up.');
                __log('navigator.getUserMedia ' + (navigator.getUserMedia ? 'available.' : 'not present!'));
            } catch (e) {
                alert('No web audio support in this browser!');
            }

            navigator.getUserMedia({ audio: true }, startUserMedia, function (e) {
                __log('No live audio input: ' + e);
            });
        };
  </script>

0 个答案:

没有答案