-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
30 lines (26 loc) · 910 Bytes
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>createplay</title>
</head>
<body>
<button id="start">播放</button>
</body>
<script>
// chrome 73 需要用户点击才可播放
document.getElementById('start').addEventListener('click', function() {
var context = new (window.AudioContext || window.webkitAudioContext)();
var oscillator = context.createOscillator();
// oscillator.type = 'sine';
// oscillator.frequency.value = 800; // 频率800Hz,默认440
var gainNode = context.createGain();
gainNode.gain.value = 0.8; // 音量 0 ~ 1
oscillator.connect(gainNode); // 关联到音量
gainNode.connect(context.destination); // 音量关联到扬声器
oscillator.start();
});
</script>
</html>