如何在JavaScript中创建随机声音并将其保存到桌面?
答案 0 :(得分:3)
使用像Riffwave这样的库:http://codebase.es/riffwave/
“riffwave.js”是一个小型的JavaScript库,它将音频数据编码为格式(RIFF容器内的PCM),可用于播放HTML5音频元素的合成声音。
e.g。随机声音生成
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)
*/