带有WebAudio API的iOS 7.1中的音频失真

带有WebAudio API的iOS 7.1中的音频失真,第1张

概述在iOS 7.1上,当使用Web Audio API播放音频时,我不断发出嗡嗡声/嘈杂/失真的声音.这听起来是 distorted like this,而不是 normal like this. 使用HTML5音频时,相同的文件很好.这一切都适用于桌面(Firefox,Chrome,Safari). 编辑: > iOS模拟器版本iOS 7.1,8.1,8.2中的音频失真.在我播放任何东西之前,嗡嗡 在iOS 7.1上,当使用Web Audio API播放音频时,我不断发出嗡嗡声/嘈杂/失真的声音.这听起来是 distorted like this,而不是 normal like this.

使用HTML5音频时,相同的文件很好.这一切都适用于桌面(firefox,Chrome,Safari).

编辑:

> iOS模拟器版本iOS 7.1,8.1,8.2中的音频失真.在我播放任何东西之前,嗡嗡的声音经常开始.
>在Chrome和Safari中运行iOS 7.1的物理iPhone上的音频失真.
>在Chrome和Safari中运行iOS 8.1的物理iPhone上的音频都很好.

即:嗡嗡声的音频在iOS 7.1上.只要.

Howler.Js不是问题.问题仍然是使用纯Js这样:

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() */

此代码的实时版本可在此处获得:Web Audio API – Hello world

谷歌没有提出有关iOS 7.1上这种扭曲声音问题的任何结果.

还有其他人遇到过吗?我应该向Apple提交错误报告吗?

解决方法 我认为这个问题是由于重置audioContext.sampleRate prop引起的,这似乎是在浏览器/ OS播放以不同采样率记录的内容之后发生的.

我已经设计了以下解决方法,它基本上默默地​​播放以设备当前播放的采样率记录的短wav文件:

"use strict";var getData = function( context,filePath,callback ) {    var source = context.createBufferSource(),request = new XMLhttpRequest();    request.open( "GET",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 );        }    );};

显然,如果某些设备具有不同的采样率,则需要针对每个速率检测并使用特定文件.

总结

以上是内存溢出为你收集整理的带有WebAudio API的iOS 7.1中的音频失真全部内容,希望文章能够帮你解决带有WebAudio API的iOS 7.1中的音频失真所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1104929.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存