使用网络音频API和navigator.getUserMedia录制音频的浏览器Android版 [英] Recording audio in Chrome for Android using web audio API and navigator.getUserMedia

查看:835
本文介绍了使用网络音频API和navigator.getUserMedia录制音频的浏览器Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome浏览器Android版版本30,并在Android 4.1测试版31似乎没有使用HTML5网页音频和navigator.webkitGetUserMedia正确地录制音频。 (铬30+ Android上应该支持这些API。)

Chrome for Android versions 30 and 31 beta on Android 4.1 do not appear to correctly record audio using HTML5 web audio and navigator.webkitGetUserMedia. (Chrome 30+ on Android is supposed to support these APIs.)

该症状是code能够正常工作,其中包括显示提示是否允许麦克风访问,但记录的数据包含了什么,但零。

The symptom is that the code appears to work correctly, including displaying the prompt for whether or not to allow microphone access, but recorded data contains nothing but zeros.

我创建了一个简单的测试用例(去 http://jsfiddle.net/JCFtK/ ,然后点击录制按钮,然后选择相应的选项,以允许它访问您的麦克风)。的code中的关键部分是低于(记录功能的入口点)。

I created a simplified testcase (go to http://jsfiddle.net/JCFtK/, and click Record button, then choose the appropriate option to allow it to access your microphone). The key part of the code is below ('record' function is the entry point).

function processAudioBuffer(e) {
    var floats = e.inputBuffer.getChannelData(0);
    var min = 0, max = 0;
    for (var i = 0; i < floats.length; i++) {
        var current = floats[i];
        min = Math.min(current, min);
        max = Math.max(current, max);
    }
    log('Block min/max: ' + min.toFixed(3) + ', ' + max.toFixed(3));
}

function record() {
    if (!window.AudioContext) {
        window.AudioContext = window.webkitAudioContext;
    }
    if (!navigator.getUserMedia) {
        navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
    }
    data.context = new AudioContext();
    navigator.getUserMedia({audio: true}, function(stream) {
        data.mediaStream = stream;
        startAudio();
    }, function(error) {
        log('Stream get error: ' + error);
    });
}

function startAudio() {
    // Get input media stream.
    data.audioStream = data.context.createMediaStreamSource(data.mediaStream);

    // Set up JS processor.
    data.processor = data.context.createScriptProcessor(2048, 1, 1);
    data.processor.onaudioprocess = processAudioBuffer;

    // You need to connect the output of processor to the audio output or it
    // doesn't work. (In Firefox, connecting it just to a gain node works;
    // in Chrome you have to connect to output like this.)
    data.processor.connect(data.context.destination);

    // Connect input stream to processor, then we're done.
    data.audioStream.connect(data.processor);
    log('Stream connected OK');
}

试验表明最小/最大音频从每个记录块的值。当这是工作 - 因为它在桌面浏览器,例如 - 你会看到的最大/最小值取决于背景噪声。当它不工作,这些值始终是0.000。

The test shows the min/max audio value from each recorded block. When it is working - as it does in desktop Chrome, for instance - you'll see the min/max values vary depending on background noise. When it is not working, these values are always 0.000.

这测试用例工作原理如下:

This testcase WORKS in the following:

  • 在Chrome浏览器30(窗口)
  • 在火狐25(视窗)
  • 在火狐25(安卓4.1)上的索尼Xperia中号
  • 在火狐25(安卓4.1),在三星平板

此测试案例并不以下工作:

This test case DOES NOT WORK in the following:

  • 在Chrome浏览器30(安卓4.1)上的索尼Xperia中号
  • 在Chrome测试版31(安卓4.1)上的索尼Xperia中号
  • 在Chrome浏览器30(安卓4.1),在三星平板

测试用例也没有在其他浏览器,如Safari或IE浏览器,但是这预料,因为它们不支持必要的API。这只是Chrome浏览器Android版,我希望能完成这项工作,但事实并非如此。

The testcase also doesn't work in other browsers such as Safari or IE, but that's expected as they do not support the necessary APIs. It's only Chrome for Android that I was hoping to make this work on, but it doesn't.

我提出这是使用Chrome的问题报告程序(它是私有的,可能是一个黑洞)的问题,但我想我也想在这里问:有没有人知道解决方法,将解决这个问题code所以其实我可以使它在Chrome工作的机器人?

I've filed this as an issue using the Chrome issue reporting process (which is private and possibly a black hole) but I thought I'd also ask here: is anyone aware of workarounds that would fix this code so I can actually make it work on Chrome for Android?

(对于我而言的一个要求是,录制的音频必须去一个JavaScript事件处理程序,例如这里的一个,如不是直接到服务器作为一种形式上传,这很可能会工作已经的一部分。)

(A requirement for my purposes is that the recorded audio must go to a JavaScript event handler such as the one here, and e.g. not directly to the server as part of a form upload, which very possibly might work already.)

我得到的IM pression,这是前沿的东西,没有太多的人试图使用它,但我认为它可能是值得一问。 :)

I get the impression that this is bleeding-edge stuff and not too many people are trying to use it, but I thought it might be worth asking. :)

推荐答案

我们还在继续努力在Android的音频输入;它是在31版的启用,但它不是打开所有设备呢。它在Nexus设备的工作,至少 - N4,N5,N7

We're still working on audio input in Android; it's enabled in version 31, but it's not turned on across all devices yet. It does work on Nexus devices, at least - N4, N5, N7.

这篇关于使用网络音频API和navigator.getUserMedia录制音频的浏览器Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆