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.
* @param {object} args Block arguments
* @param {object} util - utility object provided by the runtime.
* @return {Promise} A promise that resolves after playing the sound
*/
speakAndWait (args) {
speakAndWait (args, util) {
// Cast input to string
args.WORDS = Cast.toString(args.WORDS);
@ -154,8 +155,12 @@ class Scratch3SpeakBlocks {
}
};
this.runtime.audioEngine.decodeSoundPlayer(sound).then(soundPlayer => {
soundPlayer.connect(this.runtime.audioEngine);
soundPlayer.play();
// @todo this code should not go to production as is because it leaks
// 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);
});
});