mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-28 22:30:40 -04:00
Set volume of speech using effect chain
This commit is contained in:
parent
5dfa4cc691
commit
fb7c293e71
1 changed files with 5 additions and 9 deletions
|
@ -337,17 +337,13 @@ class Scratch3SpeakBlocks {
|
|||
}
|
||||
};
|
||||
this.runtime.audioEngine.decodeSoundPlayer(sound).then(soundPlayer => {
|
||||
const context = this.runtime.audioEngine.audioContext;
|
||||
soundPlayer.setPlaybackRate(playbackRate);
|
||||
soundPlayer.play();
|
||||
|
||||
// Increase the loudness of the speech sound
|
||||
const gainNode = context.createGain();
|
||||
gainNode.gain.setValueAtTime(2, context.currentTime);
|
||||
// Note that this connect must be done after play is called,
|
||||
// which initializes the soundPlayer's output node.
|
||||
soundPlayer.outputNode.connect(gainNode);
|
||||
gainNode.connect(this.runtime.audioEngine.inputNode);
|
||||
// Increase the volume
|
||||
const engine = this.runtime.audioEngine;
|
||||
const chain = engine.createEffectChain();
|
||||
chain.set('volume', 250);
|
||||
soundPlayer.connect(chain);
|
||||
|
||||
soundPlayer.on('stop', resolve);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue