2012-04-23 70 views
0

如何在JavaScript中創建隨機聲音並將其保存到桌面?js中的隨機聲音

+1

取決於你的意思是「隨機聲音」。 – JJJ 2012-04-23 10:07:21

+0

你爲什麼要標記jQuery? – 2012-04-23 10:08:20

+0

這意味着每秒有不同的音符。 – user1 2012-04-23 10:08:32

回答

3

使用像Riffwave庫:http://codebase.es/riffwave/

「riffwave.js」是音頻數據編碼到可以用來播放合成聲音與格式(PCM一個RIFF容器內)一個微小的JavaScript庫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) 
*/