I have created a oscillator (as shown below), like MDN said:
// from : https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var oscillator = audioCtx.createOscillator();
var gainNode = audioCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioCtx.destination);
oscillator.type = 'sine'; // sine wave — other values are 'square', 'sawtooth', 'triangle' and 'custom'
oscillator.frequency.value = 2500; // value in hertz
oscillator.start();
Is there a method to change the volume, like I changed the frequency value?
You need to look at modifying the audioContext and gainNode for volume changes. Following link might help:
https://github.com/mdn/voice-change-o-matic/blob/gh-pages/scripts/app.js