Use sprite’s soundbank to play text2speech sound (#1388)

* Use sprite’s soundbank to play sound

* Add todo comment
This commit is contained in:
Eric Rosenbaum 2018-07-23 11:16:00 -04:00 committed by GitHub
parent db0597ada5
commit f5066626e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -116,9 +116,10 @@ class Scratch3SpeakBlocks {
/** /**
* Convert the provided text into a sound file and then play the file. * Convert the provided text into a sound file and then play the file.
* @param {object} args Block arguments * @param {object} args Block arguments
* @param {object} util - utility object provided by the runtime.
* @return {Promise} A promise that resolves after playing the sound * @return {Promise} A promise that resolves after playing the sound
*/ */
speakAndWait (args) { speakAndWait (args, util) {
// Cast input to string // Cast input to string
args.WORDS = Cast.toString(args.WORDS); args.WORDS = Cast.toString(args.WORDS);
@ -154,8 +155,12 @@ class Scratch3SpeakBlocks {
} }
}; };
this.runtime.audioEngine.decodeSoundPlayer(sound).then(soundPlayer => { this.runtime.audioEngine.decodeSoundPlayer(sound).then(soundPlayer => {
soundPlayer.connect(this.runtime.audioEngine); // @todo this code should not go to production as is because it leaks
soundPlayer.play(); // soundplayers. We may not want to use the soundbank for this purpose
// at all.
const soundBank = util.target.sprite.soundBank;
soundBank.addSoundPlayer(soundPlayer);
soundBank.playSound(util.target, soundPlayer.id);
soundPlayer.on('stop', resolve); soundPlayer.on('stop', resolve);
}); });
}); });