English 中文(简体)
正在录制 html5 音频
原标题:Recording html5 audio

能否用 html5 记录声音? 我已经下载了最新的铬的金丝雀版本 并使用以下代码 :

navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.getUserMedia; navigator.getUserMedia({audio: true}, gotAudio, noStream);

这促使用户允许录音, 如果您说“ 是 ”, 那么如果您说“ 是 ”, 有一条信息显示铬正在录音。 但是, 是否有可能用原始数据访问音频缓冲? 我似乎无法找到如何操作 。 有建议表明 Havn 尚未被执行, 但是是否有人知道它现在是否真的可以在任何浏览器上完成, 并提供指示?

最佳回答

您可以在这里找到我的示例, 但是它不起作用( 部分) 。 因为 AUDIO 的录音还没有被安装到铬中 。 这就是为什么你会发现404个错误, 也就是说找不到 BLOB 。

下面还有一张表格 是因为我的目标是把BLOB 发送到php文件上, 但是由于工作不起作用, 我无法尝试。 省省吧, 您可以稍后使用 。

<audio></audio>
<input onclick="startRecording()" type="button" value="start recording" />
<input onclick="stopRecording()" type="button" value="stop recording and play" />
<div></div>
<!--
<form enctype="multipart/form-data">
<input name="file" type="file" />
<input type="button" value="Upload" />
</form>
-->

<script>
  var onFailed = function(e) {
    console.log( sorry :( , e);
  };

window.URL = window.URL || window.webkitURL;
navigator.getUserMedia  = navigator.getUserMedia || navigator.webkitGetUserMedia ||
                          navigator.mozGetUserMedia || navigator.msGetUserMedia || 
var localStream

var audio = document.querySelector( audio );
var stop = document.getElementById( stop );


    function startRecording(){
        if (navigator.getUserMedia) {
          navigator.getUserMedia({audio: true, video: false, toString : function() {return "video,audio";}}, function(stream) {
            audio.src = window.URL.createObjectURL(stream);
        document.getElementsByTagName( div )[0].innerHTML = audio.src;
            localStream = stream;
          }, onFailed);
        } else {
            alert( Unsupported );
          //audio.src =  someaudio.ogg ; // fallback.
        }
    }



    function stopRecording(){
        localStream.stop();
        audio.play();
    }


    function sendAudio(){

    }
</script>

注释:一些信息及火狐:https://hacks.mozilla.org/2012/07/getusermedia-is-ready-to-roll/

问题回答

Webkit 和 Chrome 音频API 支持记录,然而,随着它们的API 的演变,很难维持使用它们的代码。

一个名为Sink.js 的开放源码项目允许记录,也允许你推动原始样本:https://github.com/jussi-kalliokoski/sink.js/ 。由于该项目相当活跃,他们得以在Webkit和Chrome的变化中保持前列。

现在可以使用音频背景 API 访问音频缓冲, 并获取ChannelData () 。

这里的 gitHub 是一个直接以 MP3 格式记录音频并将其保存在网络服务器上的项目 : https://github.com/nusofthq/Recordmp3js

在记录器.js中,您可以看到音频缓冲器是如何单独通过像这样的频道访问的:

this.node.onaudioprocess = function(e){
      if (!recording) return;
      worker.postMessage({
        command:  record ,
        buffer: [
          e.inputBuffer.getChannelData(0),
          //e.inputBuffer.getChannelData(1)
        ]
      });
    }

For a more detailed explanation of the implementation you can read the following blogpost: http://nusofthq.com/blog/recording-mp3-using-only-html5-and-javascript-recordmp3-js/





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签