Building a Musical Instrument with the Web Audio API
https://www.taniarascia.com/musical-instrument-web-audio-api
键盘乐器简化成按一个键发出一个对应音高的音。
参考文中给出的示例代码
const audio = new (window.AudioContext || window.webkitAudioContext)()
const gainNode = audio.createGain()
gainNode.gain.value = 0.1
gainNode.connect(audio.destination)
const oscillator = audio.createOscillator()
oscillator.type = 'sawtooth'
oscillator.connect(gainNode)
oscillator.frequency.value = 440
oscillator.start()
使用 OscillatorNode 发出一个指定频率的音。 是个挺有趣的尝试。