How to play wav audio byte array via javascript/html5?

前端 未结 3 601
小蘑菇
小蘑菇 2020-11-30 05:46

I\'m using the following method to play a byte array containing wav data. The function is being called from a GWT project.

This function plays back sound, but it so

3条回答
  •  旧时难觅i
    2020-11-30 06:51

    Clean up suggestion:

    function playByteArray( bytes ) {
        var buffer = new Uint8Array( bytes.length );
        buffer.set( new Uint8Array(bytes), 0 );
    
        context.decodeAudioData(buffer.buffer, play);
    }
    
    function play( audioBuffer ) {
        var source = context.createBufferSource();
        source.buffer = audioBuffer;
        source.connect( context.destination );
        source.start(0);
    }
    

提交回复
热议问题