0

次のwavファイルがあります:ffmpeg -i my.wav

次の出力が得られます。

output:   Duration: 00:00:12.63, bitrate: 352 kb/s
    Stream #0.0: Audio: pcm_s16le, 22050 Hz, 1 channels, s16, 352 kb/s

これは、以下に示す base64 変数としてメモリにロードされた JavaScript に base64 文字列として格納されます。

コードは次のとおりです。

byte_str = Base64.decode(base64)
buffer = new ArrayBuffer(byte_str.length*2)
buffer_view = new Uint16Array(buffer)
/* this is coffeescript */
for i in [0..byte_str.length]
   buffer_view[i] = byte_str.charCodeAt(i)
console.log(byte_str.length)
console.log(buffer_view)
console.log(buffer_view.buffer)
context = new webkitAudioContext()
context.decodeAudioData(buffer,function (buffer) {
    /* never gets hit */
    source = @context.createBufferSource()
    source.buffer = buffer
    source.connect(@context.destination)
    source.noteOn(0)
});

出力:

108185
[82, 73, 70, 70, 36, 128, 87, 65, 86, 69, 102, 109, 116, 32, 16, 0, 0, 0, 1, 0, 1, 0, 34, 86, 0, 0, 68, 49152, 2, 0, 16, 0, 100, 97, 116, 97, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,....]
ArrayBuffer {byteLength: 216370} 

このプレゼンテーションを見ると、WAV ヘッダーがあります: http://html5-demos.appspot.com/static/html5-whats-new/template/index.html#29

var header = new Uint8Array([
    0x52,0x49,0x46,0x46, // "RIFF"
    0, 0, 0, 0,          // put total size here
    0x57,0x41,0x56,0x45,
    ...
]);

最初の値を 16 進数に変換すると、これは私の場合と同じですが、私の場合、decodeAudioData に対してコールバックが起動することはありません。何か案は?

4

1 に答える 1

0

このライブラリを使用した場合のエンコーディングの問題であることが判明しました 。http : //www.webtoolkit.info/javascript-base64.html _utf8_decodeステップを削除しましたが、うまく機能しました。

于 2013-01-18T00:38:28.080 に答える