0

如何在 JavaScript 中创建随机声音并将其保存到桌面?

4

1 回答 1

3

使用 Riffwave 之类的库:http: //codebase.es/riffwave/

“riffwave.js”是一个小型 javascript 库,可将音频数据编码为一种格式(RIFF 容器内的 PCM),该格式可用于播放带有 HTML5 音频元素的合成声音。

例如随机声音生成

var data = []; 

for (var i=0; i<1000; i++) {
    // fill data with random samples
    data[i] = Math.round(255 * Math.random()); 
}

var wave = new RIFFWAVE(data); // create the wave file

/*
     pass wave.dataURI property to a server page via POST and 
     then re-send the content along with the right headers 
     for a wav file so  to enforce download

     or just redirect your client using data:uri schema, like
     location.href =  wave.dataURI 
     (but this won't force the download in every browser)
*/
于 2012-04-23T10:20:30.080 回答