在iOS的7.1音频失真与WebAudio API [英] Distorted audio in iOS 7.1 with WebAudio API

查看:710
本文介绍了在iOS的7.1音频失真与WebAudio API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 7.1中,我不断收到一个嗡嗡/噪音/声音失真使用网络音频API播放音频时。这听起来扭曲这样 ,到位的normal~~MD~~aux喜欢这个

On iOS 7.1, I keep getting a buzzing / noisy / distorted sound when playing back audio using the Web Audio API. It sounds distorted like this, in place of normal like this.

同样的文件中使用HTML5音频时的罚款。这一切工作正常,在桌面上(火狐,Chrome,Safari浏览器。)

The same files are fine when using HTML5 audio. It all works fine on desktop (Firefox, Chrome, Safari.)

编辑:


  • 音频在iPhone模拟器版本的iOS 7.1,8.1,8.2扭曲。在嗡嗡的声音往往开始前我甚至播放什么。

  • 音频失真上运行iOS 7.1,在这两个Chrome和Safari物理iPhone。

  • 音频是在运行iOS 8.1的物理iPhone,在这两个Chrome和Safari的罚款。

即:嗡嗡的声音是在iOS 7.1。只要。

i.e.: the buzzing audio is on iOS 7.1. only.

结果
Howler.js不是问题。问题是仍然存在使用像这样的纯JS:


Howler.js is not the issue. The problem is still there using pure JS like so:

var context;
var sound;
var extension = '.' + ( new Audio().canPlayType( 'audio/ogg' ) !== '' ? 'ogg' : 'mp3');


/** Test for WebAudio API support **/
try {
    // still needed for Safari
    window.AudioContext = window.AudioContext || window.webkitAudioContext;

    // create an AudioContext
    context = new AudioContext();
} catch(e) {
    // API not supported
    throw new Error( 'Web Audio API not supported.' );
}

function loadSound( url ) {
    var request = new XMLHttpRequest();
    request.open( 'GET', url, true );
    request.responseType = 'arraybuffer';

    request.onload = function() {
        // request.response is encoded... so decode it now
        context.decodeAudioData( request.response, function( buffer ) {
        sound = buffer;
        }, function( err ) {
            throw new Error( err );
        });
    }

    request.send();
}

function playSound(buffer) {
    var source = context.createBufferSource();
    source.buffer = buffer;
    source.connect(context.destination);
    source.start(0);
}

loadSound( '/tests/Assets/Audio/En-us-hello' + extension );


$(document).ready(function(){ 

    $( '#clickme' ).click( function( event ) {
        playSound(sound);
    });


}); /* END .ready() */

这code的真人版,请访问:网络音频API - 世界您好

A live version of this code is available here: Web Audio API - Hello world

结果
谷歌并没有带来的任何结果,这样一个扭曲的声音发出在iOS 7.1。


Google did not bring up any result about such a distorted sound issue on iOS 7.1.

有没有其他人碰到这个问题?我是否应该提交错误报告给苹果?

Has anyone else run into it? Should I file a bug report to Apple?

推荐答案

我认为问题是由于重置audioContext.sampleRate道具,这似乎在浏览器/ OS播放记录在不同的采样率的东西发生后,引起的。

I believe the issue is caused due to resetting the audioContext.sampleRate prop, which seem to happen after the browser/OS plays something recorded in a different sampling rate.

我已经设计了以下解决方法,这基本上默默地​​扮演着录的采样率,该装置目前确实在播放短WAV文件:

I've devised the following workaround, which basically silently plays a short wav file recorded in the sampling rate that the device currently does playback on:

"use strict";

var getData = function( context, filePath, callback ) {
    var source = context.createBufferSource(),
        request = new XMLHttpRequest();

    request.open( "GET", filePath, true );

    request.responseType = "arraybuffer";

    request.onload = function() {
        var audioData = request.response;

        context.decodeAudioData(
            audioData,
            function( buffer ) {
                source.buffer = buffer;

                callback( source );
            },
            function( e ) {
                console.log( "Error with decoding audio data" + e.err );
            }
        );
    };

    request.send();
};

module.exports = function() {
    var AudioContext = window.AudioContext || window.webkitAudioContext,
        context = new AudioContext();

    getData(
        context,
        "path/to/short/file.wav",
        function( bufferSource ) {
            var gain = context.createGain();
            gain.gain.value = 0;
            bufferSource.connect( gain );
            gain.connect( context.destination );
            bufferSource.start( 0 );
        }
    );
};

显然,如果某些设备具有不同的采样率,则需要检测和使用一个特定的文件,每速度。

Obviously, if some of the devices have different sampling rates, you would need to detect and use a specific file for every rate.

这篇关于在iOS的7.1音频失真与WebAudio API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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