Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught could not load memory initializer Mp3LameEncoder.min.js.mem

I have been working on a project where I need to record a voice from MIC and upload it to web server. I want this in .mp3 format. For this have gone through this tutorial.

It works fine at their end with a demo but when I used the same coding and all files provided it shows me error at localhost as well as on web.

Uncaught could not load memory initializer Mp3LameEncoder.min.js.mem

I worked exactly according to them and modified the codes at in demo page but it does not work.

I am working in ASP.NET C# and using Chrome as my user agent.

My file structure is:

enter image description here

Here is sample code:

<script>
    (function () {
        var audioContext, gumStream, recorder, input, encodingType, encodeAfterRecord = true, startRecording, stopRecording;

        URL = window.URL || window.webkitURL;

        var AudioContext = window.AudioContext || window.webkitAudioContext;

        //window.AudioContext = window.AudioContext || window.webkitAudioContext;

        navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;


        startRecording = function () {
            var constraints = { audio: true, video: false };
            navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
                audioContext = new AudioContext();
                gumStream = stream;
                input = audioContext.createMediaStreamSource(stream);
                //input.connect(audioContext.destination);
                encodingType = 'mp3';
                recorder = new WebAudioRecorder(input, {
                    workerDir: '/vendors/_war/',
                    encoding: encodingType,
                    numChannels:2
                });

                recorder.onComplete = function (recorder, blob) {
                    createDownloadLink(blob, recorder.encoding);
                    alert('recording done');
                }

                recorder.setOptions({
                    timeLimit: 120,
                    encodeAfterRecord: encodeAfterRecord,
                    ogg:{ quality: 0.5},
                    mp3: { bitRate: 160 }
                });

                recorder.startRecording();
            }).catch(function (err) {
                alert('Exception: ' + err);
            });
        };

        stopRecording = function () {
            gumStream.getAudioTracks()[0].stop();
            recorder.finishRecording();
        };

        $('#recordButton').on('click', function () {
            startRecording();
        });
        $('#stopButton').on('click', function () {
            stopRecording(true);
        });
    }).call(this);
    function createDownloadLink(blob, encoding) {

        var url = URL.createObjectURL(blob);
        var au = $('#au'); //document.createElement('audio');
        //var li = document.createElement('li');
        //var link = document.createElement('a');

        //add controls to the &amp;amp;lt;audio&amp;amp;gt; element
        au.controls = true;
        au.src = url;

        //link the a element to the blob
        //link.href = url;
        //link.download = new Date().toISOString() + '.' + encoding;
        //link.innerHTML = link.download;

        //add the new audio and a elements to the li element
        //li.appendChild(au);
        //li.appendChild(link);

        //add the li element to the ordered list
        //var recordingsList = $('#recordingsList');
        //recordingsList.appendChild(li);
    }
</script>
like image 498
Solved C Avatar asked Oct 17 '22 09:10

Solved C


1 Answers

In my case I needed to add MIME types for .mem file extension that I wanted to serve to web config:

<system.webServer>
    <staticContent>
        <mimeMap fileExtension=".mem" mimeType="text/html" />
    </staticContent>
</system.webServer>
like image 157
Solved C Avatar answered Nov 04 '22 19:11

Solved C