使用Javascript Code:
<script>
function play(music,time){
//參考http://www.csie.ntnu.edu.tw/~u91029/Audio.html
var sampleRate = 10000;
var sampleNumber = music[0].length*10000*time;
var ctx = new AudioContext();
var buffer = ctx.createBuffer(2, sampleNumber, sampleRate);
//製作聲音資料
var data0 = buffer.getChannelData(0); //第1聲道
var data1 = buffer.getChannelData(1); //第2聲道
for (var i = 0; i < sampleNumber; ++i){
var index=Math.floor(i/(sampleRate*time));
data0[i] = Math.sin((Math.PI * 2) * i * music[0][index] / sampleRate);
data1[i] = Math.sin((Math.PI * 2) * i * music[1][index] / sampleRate);
}
// 製作節點、串連節點、播放聲音
var node = ctx.createBufferSource();
node.buffer = buffer;
node.connect(ctx.destination);
node.start(0);
}
var __=0;
var S960=960;
var S853=853;
var music=[[
S960,S960,S960,S960, //2秒
__, //停頓0.5sec
S960,S960, //1秒
__, //停頓0.5秒
S960,S960, //1秒
__, //停頓0.5秒
S960,S960,S960,S960, //2秒
__, //停頓0.5sec
S960,S960, //1秒
__, //停頓0.5秒
S960,S960 //1秒
],[
S853,S853,S853,S853,
__,
S853,S853,
__,
S853,S853,
__,
S853,S853,S853,S853,
__,
S853,S853,
__,
S853,S853
]];
play(music,0.5);/**/
</script>
文章短網址: https://slanla.com/__cihuvb