5

我一直在做一个项目,我需要从 MIC 录制声音并将其上传到 Web 服务器。我想要这个.mp3 格式。为此已经完成了本教程

它在演示结束时运行良好,但是当我使用相同的编码和提供的所有文件时,它在 localhost 和 web 上都显示错误。

Uncaught 无法加载内存初始化程序 Mp3LameEncoder.min.js.mem

我完全按照它们工作并修改了演示页面中的代码,但它不起作用。

我正在使用 ASP.NET C# 并使用 Chrome 作为我的用户代理。

我的文件结构是:

在此处输入图像描述

这是示例代码:

<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>
4

1 回答 1

3

在我的情况下,我需要为我想要提供给 Web 配置的 .mem 文件扩展名添加 MIME 类型:

<system.webServer>
    <staticContent>
        <mimeMap fileExtension=".mem" mimeType="text/html" />
    </staticContent>
</system.webServer>
于 2018-12-14T16:57:52.817 回答