pixi-live2d-display-advanced 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,7 @@ var __async = (__this, __arguments, generator) => {
23
23
  });
24
24
  };
25
25
  import { utils as utils$1, Matrix, Texture, Transform, Point, ObservablePoint } from "@pixi/core";
26
- import { Sound, webaudio } from "@pixi/sound";
26
+ import { sound, Sound, webaudio } from "@pixi/sound";
27
27
  import { Container } from "@pixi/display";
28
28
  const LOGICAL_WIDTH = 2;
29
29
  const LOGICAL_HEIGHT = 2;
@@ -78,7 +78,7 @@ const config = {
78
78
  preserveExpressionOnMotion: true,
79
79
  cubism4: CubismConfig
80
80
  };
81
- const VERSION = "v0.5.2";
81
+ const VERSION = "v0.5.4";
82
82
  const logger = {
83
83
  log(tag, ...messages) {
84
84
  if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
@@ -3695,6 +3695,7 @@ class MotionState {
3695
3695
  }
3696
3696
  const TAG$2 = "SoundManager";
3697
3697
  const VOLUME = 0.5;
3698
+ sound.disableAutoPause = true;
3698
3699
  class SoundManager {
3699
3700
  /**
3700
3701
  * Global volume that applies to all the sounds.
@@ -3710,11 +3711,10 @@ class SoundManager {
3710
3711
  /**
3711
3712
  * Creates an audio element and adds it to the {@link audios}.
3712
3713
  * @param file - URL of the sound file.
3713
- * @param onFinish - Callback invoked when the playback has finished.
3714
3714
  * @param onError - Callback invoked when error occurs.
3715
3715
  * @return Created audio element.
3716
3716
  */
3717
- static add(file, onFinish, onError) {
3717
+ static add(file, onError) {
3718
3718
  return __async(this, null, function* () {
3719
3719
  try {
3720
3720
  const task = new Promise((resolve, reject) => {
@@ -3722,10 +3722,6 @@ class SoundManager {
3722
3722
  url: file,
3723
3723
  volume: this._volume,
3724
3724
  preload: true,
3725
- complete: () => {
3726
- this.dispose(audio);
3727
- onFinish == null ? void 0 : onFinish();
3728
- },
3729
3725
  loaded: () => {
3730
3726
  if (!(audio.media instanceof webaudio.WebAudioMedia)) {
3731
3727
  reject(new Error(`Error: ${file} is not WebAudioMedia`));
@@ -3745,9 +3741,16 @@ class SoundManager {
3745
3741
  /**
3746
3742
  * Plays the sound.
3747
3743
  * @param audio - An audio element.
3744
+ * @param onFinish - Callback invoked when the playback has finished.
3748
3745
  */
3749
- static play(audio) {
3750
- audio.play();
3746
+ static play(audio, onFinish) {
3747
+ audio.play({
3748
+ singleInstance: true,
3749
+ complete: () => {
3750
+ onFinish == null ? void 0 : onFinish();
3751
+ audio.destroy();
3752
+ }
3753
+ });
3751
3754
  }
3752
3755
  static addAnalyzer(audio, context) {
3753
3756
  const media = audio.media;
@@ -3760,7 +3763,6 @@ class SoundManager {
3760
3763
  analyser.smoothingTimeConstant = 0.85;
3761
3764
  source.connect(analyser);
3762
3765
  source.start(0);
3763
- analyser.connect(context.destination);
3764
3766
  this.analysers.push(analyser);
3765
3767
  return analyser;
3766
3768
  }
@@ -3987,7 +3989,7 @@ class MotionManager extends utils$1.EventEmitter {
3987
3989
  * @returns Promise that resolves with true if the sound is playing, false otherwise.
3988
3990
  */
3989
3991
  speak(_0) {
3990
- return __async(this, arguments, function* (sound, {
3992
+ return __async(this, arguments, function* (sound2, {
3991
3993
  volume = VOLUME,
3992
3994
  expression,
3993
3995
  resetExpression = true,
@@ -4004,37 +4006,26 @@ class MotionManager extends utils$1.EventEmitter {
4004
4006
  }
4005
4007
  }
4006
4008
  let soundURL;
4007
- const isBase64Content = sound && sound.startsWith("data:");
4008
- if (sound && !isBase64Content) {
4009
+ const isBase64Content = sound2 && sound2.startsWith("data:");
4010
+ if (sound2 && !isBase64Content) {
4009
4011
  const A = document.createElement("a");
4010
- A.href = sound;
4011
- sound = A.href;
4012
- soundURL = sound;
4012
+ A.href = sound2;
4013
+ sound2 = A.href;
4014
+ soundURL = sound2;
4013
4015
  } else {
4014
4016
  soundURL = "data:audio/";
4015
4017
  }
4016
- const file = sound;
4018
+ const file = sound2;
4017
4019
  if (file) {
4018
4020
  try {
4019
- audio = yield SoundManager.add(
4020
- file,
4021
- (that = this) => {
4022
- logger.warn(this.tag, "Audio finished playing");
4023
- onFinish == null ? void 0 : onFinish();
4024
- if (resetExpression && expression && that.expressionManager) {
4025
- that.expressionManager.resetExpression();
4026
- }
4027
- that.currentAudio = void 0;
4028
- },
4029
- (e, that = this) => {
4030
- logger.error(this.tag, "Error during audio playback:", e);
4031
- onError == null ? void 0 : onError(e);
4032
- if (resetExpression && expression && that.expressionManager) {
4033
- that.expressionManager.resetExpression();
4034
- }
4035
- that.currentAudio = void 0;
4021
+ audio = yield SoundManager.add(file, (e, that = this) => {
4022
+ logger.error(this.tag, "Error during audio playback:", e);
4023
+ onError == null ? void 0 : onError(e);
4024
+ if (resetExpression && expression && that.expressionManager) {
4025
+ that.expressionManager.resetExpression();
4036
4026
  }
4037
- );
4027
+ that.currentAudio = void 0;
4028
+ });
4038
4029
  this.initializeAudio(audio, volume);
4039
4030
  } catch (e) {
4040
4031
  logger.warn(this.tag, "Failed to create audio", soundURL, e);
@@ -4045,7 +4036,13 @@ class MotionManager extends utils$1.EventEmitter {
4045
4036
  let playSuccess = true;
4046
4037
  try {
4047
4038
  if (config.motionSync) {
4048
- SoundManager.play(audio);
4039
+ SoundManager.play(audio, () => {
4040
+ onFinish == null ? void 0 : onFinish();
4041
+ if (resetExpression && expression && this.expressionManager) {
4042
+ this.expressionManager.resetExpression();
4043
+ }
4044
+ this.currentAudio = void 0;
4045
+ });
4049
4046
  }
4050
4047
  } catch (e) {
4051
4048
  logger.warn(this.tag, "Failed to play audio", audio.url, e);
@@ -4082,7 +4079,7 @@ class MotionManager extends utils$1.EventEmitter {
4082
4079
  */
4083
4080
  startMotion(_0, _1) {
4084
4081
  return __async(this, arguments, function* (group, index, priority = MotionPriority.NORMAL, {
4085
- sound = void 0,
4082
+ sound: sound2 = void 0,
4086
4083
  volume = VOLUME,
4087
4084
  expression = void 0,
4088
4085
  resetExpression = true,
@@ -4108,12 +4105,12 @@ class MotionManager extends utils$1.EventEmitter {
4108
4105
  }
4109
4106
  let audio;
4110
4107
  let soundURL;
4111
- const isBase64Content = sound && sound.startsWith("data:");
4112
- if (sound && !isBase64Content) {
4108
+ const isBase64Content = sound2 && sound2.startsWith("data:");
4109
+ if (sound2 && !isBase64Content) {
4113
4110
  const A = document.createElement("a");
4114
- A.href = sound;
4115
- sound = A.href;
4116
- soundURL = sound;
4111
+ A.href = sound2;
4112
+ sound2 = A.href;
4113
+ soundURL = sound2;
4117
4114
  } else {
4118
4115
  soundURL = this.getSoundFile(definition);
4119
4116
  if (soundURL) {
@@ -4123,24 +4120,14 @@ class MotionManager extends utils$1.EventEmitter {
4123
4120
  const file = soundURL;
4124
4121
  if (file) {
4125
4122
  try {
4126
- audio = yield SoundManager.add(
4127
- file,
4128
- (that = this) => {
4129
- onFinish == null ? void 0 : onFinish();
4130
- if (resetExpression && expression && that.expressionManager) {
4131
- that.expressionManager.resetExpression();
4132
- }
4133
- that.currentAudio = void 0;
4134
- },
4135
- (e, that = this) => {
4136
- logger.error(this.tag, "Error during audio playback:", e);
4137
- onError == null ? void 0 : onError(e);
4138
- if (resetExpression && expression && that.expressionManager) {
4139
- that.expressionManager.resetExpression();
4140
- }
4141
- that.currentAudio = void 0;
4123
+ audio = yield SoundManager.add(file, (e, that = this) => {
4124
+ logger.error(this.tag, "Error during audio playback:", e);
4125
+ onError == null ? void 0 : onError(e);
4126
+ if (resetExpression && expression && that.expressionManager) {
4127
+ that.expressionManager.resetExpression();
4142
4128
  }
4143
- );
4129
+ that.currentAudio = void 0;
4130
+ });
4144
4131
  this.initializeAudio(audio, volume);
4145
4132
  } catch (e) {
4146
4133
  logger.warn(this.tag, "Failed to create audio", soundURL, e);
@@ -4150,7 +4137,13 @@ class MotionManager extends utils$1.EventEmitter {
4150
4137
  if (audio) {
4151
4138
  if (config.motionSync) {
4152
4139
  try {
4153
- SoundManager.play(audio);
4140
+ SoundManager.play(audio, (that = this) => {
4141
+ onFinish == null ? void 0 : onFinish();
4142
+ if (resetExpression && expression && that.expressionManager) {
4143
+ that.expressionManager.resetExpression();
4144
+ }
4145
+ that.currentAudio = void 0;
4146
+ });
4154
4147
  } catch (e) {
4155
4148
  logger.warn(this.tag, "Failed to play audio", audio.url, e);
4156
4149
  }
@@ -4191,7 +4184,7 @@ class MotionManager extends utils$1.EventEmitter {
4191
4184
  */
4192
4185
  startRandomMotion(_0, _1) {
4193
4186
  return __async(this, arguments, function* (group, priority, {
4194
- sound,
4187
+ sound: sound2,
4195
4188
  volume = VOLUME,
4196
4189
  expression,
4197
4190
  resetExpression = true,
@@ -4209,7 +4202,7 @@ class MotionManager extends utils$1.EventEmitter {
4209
4202
  if (availableIndices.length) {
4210
4203
  const index = availableIndices[Math.floor(Math.random() * availableIndices.length)];
4211
4204
  return this.startMotion(group, index, priority, {
4212
- sound,
4205
+ sound: sound2,
4213
4206
  volume,
4214
4207
  expression,
4215
4208
  resetExpression,
@@ -5530,7 +5523,7 @@ class Live2DModel extends Container {
5530
5523
  */
5531
5524
  motion(_0, _1, _2) {
5532
5525
  return __async(this, arguments, function* (group, index, priority, {
5533
- sound = void 0,
5526
+ sound: sound2 = void 0,
5534
5527
  volume = VOLUME,
5535
5528
  expression = void 0,
5536
5529
  resetExpression = true,
@@ -5539,7 +5532,7 @@ class Live2DModel extends Container {
5539
5532
  } = {}) {
5540
5533
  if (index === void 0) {
5541
5534
  return this.internalModel.motionManager.startRandomMotion(group, priority, {
5542
- sound,
5535
+ sound: sound2,
5543
5536
  volume,
5544
5537
  expression,
5545
5538
  resetExpression,
@@ -5548,7 +5541,7 @@ class Live2DModel extends Container {
5548
5541
  });
5549
5542
  } else {
5550
5543
  return this.internalModel.motionManager.startMotion(group, index, priority, {
5551
- sound,
5544
+ sound: sound2,
5552
5545
  volume,
5553
5546
  expression,
5554
5547
  resetExpression,
@@ -5631,14 +5624,14 @@ class Live2DModel extends Container {
5631
5624
  * @param [options.onError] - Callback function when an error occurs.
5632
5625
  * @returns Promise that resolves with true if the sound is playing, false if it's not.
5633
5626
  */
5634
- speak(sound, {
5627
+ speak(sound2, {
5635
5628
  volume = VOLUME,
5636
5629
  expression,
5637
5630
  resetExpression = true,
5638
5631
  onFinish,
5639
5632
  onError
5640
5633
  } = {}) {
5641
- return this.internalModel.motionManager.speak(sound, {
5634
+ return this.internalModel.motionManager.speak(sound2, {
5642
5635
  volume,
5643
5636
  expression,
5644
5637
  resetExpression,
package/dist/cubism2.js CHANGED
@@ -79,7 +79,7 @@ var __async = (__this, __arguments, generator) => {
79
79
  preserveExpressionOnMotion: true,
80
80
  cubism4: CubismConfig
81
81
  };
82
- const VERSION = "v0.5.2";
82
+ const VERSION = "v0.5.4";
83
83
  const logger = {
84
84
  log(tag, ...messages) {
85
85
  if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
@@ -3696,6 +3696,7 @@ var __async = (__this, __arguments, generator) => {
3696
3696
  }
3697
3697
  const TAG$2 = "SoundManager";
3698
3698
  const VOLUME = 0.5;
3699
+ sound.sound.disableAutoPause = true;
3699
3700
  class SoundManager {
3700
3701
  /**
3701
3702
  * Global volume that applies to all the sounds.
@@ -3711,11 +3712,10 @@ var __async = (__this, __arguments, generator) => {
3711
3712
  /**
3712
3713
  * Creates an audio element and adds it to the {@link audios}.
3713
3714
  * @param file - URL of the sound file.
3714
- * @param onFinish - Callback invoked when the playback has finished.
3715
3715
  * @param onError - Callback invoked when error occurs.
3716
3716
  * @return Created audio element.
3717
3717
  */
3718
- static add(file, onFinish, onError) {
3718
+ static add(file, onError) {
3719
3719
  return __async(this, null, function* () {
3720
3720
  try {
3721
3721
  const task = new Promise((resolve, reject) => {
@@ -3723,10 +3723,6 @@ var __async = (__this, __arguments, generator) => {
3723
3723
  url: file,
3724
3724
  volume: this._volume,
3725
3725
  preload: true,
3726
- complete: () => {
3727
- this.dispose(audio);
3728
- onFinish == null ? void 0 : onFinish();
3729
- },
3730
3726
  loaded: () => {
3731
3727
  if (!(audio.media instanceof sound.webaudio.WebAudioMedia)) {
3732
3728
  reject(new Error(`Error: ${file} is not WebAudioMedia`));
@@ -3746,9 +3742,16 @@ var __async = (__this, __arguments, generator) => {
3746
3742
  /**
3747
3743
  * Plays the sound.
3748
3744
  * @param audio - An audio element.
3745
+ * @param onFinish - Callback invoked when the playback has finished.
3749
3746
  */
3750
- static play(audio) {
3751
- audio.play();
3747
+ static play(audio, onFinish) {
3748
+ audio.play({
3749
+ singleInstance: true,
3750
+ complete: () => {
3751
+ onFinish == null ? void 0 : onFinish();
3752
+ audio.destroy();
3753
+ }
3754
+ });
3752
3755
  }
3753
3756
  static addAnalyzer(audio, context) {
3754
3757
  const media = audio.media;
@@ -3761,7 +3764,6 @@ var __async = (__this, __arguments, generator) => {
3761
3764
  analyser.smoothingTimeConstant = 0.85;
3762
3765
  source.connect(analyser);
3763
3766
  source.start(0);
3764
- analyser.connect(context.destination);
3765
3767
  this.analysers.push(analyser);
3766
3768
  return analyser;
3767
3769
  }
@@ -4017,25 +4019,14 @@ var __async = (__this, __arguments, generator) => {
4017
4019
  const file = sound2;
4018
4020
  if (file) {
4019
4021
  try {
4020
- audio = yield SoundManager.add(
4021
- file,
4022
- (that = this) => {
4023
- logger.warn(this.tag, "Audio finished playing");
4024
- onFinish == null ? void 0 : onFinish();
4025
- if (resetExpression && expression && that.expressionManager) {
4026
- that.expressionManager.resetExpression();
4027
- }
4028
- that.currentAudio = void 0;
4029
- },
4030
- (e, that = this) => {
4031
- logger.error(this.tag, "Error during audio playback:", e);
4032
- onError == null ? void 0 : onError(e);
4033
- if (resetExpression && expression && that.expressionManager) {
4034
- that.expressionManager.resetExpression();
4035
- }
4036
- that.currentAudio = void 0;
4022
+ audio = yield SoundManager.add(file, (e, that = this) => {
4023
+ logger.error(this.tag, "Error during audio playback:", e);
4024
+ onError == null ? void 0 : onError(e);
4025
+ if (resetExpression && expression && that.expressionManager) {
4026
+ that.expressionManager.resetExpression();
4037
4027
  }
4038
- );
4028
+ that.currentAudio = void 0;
4029
+ });
4039
4030
  this.initializeAudio(audio, volume);
4040
4031
  } catch (e) {
4041
4032
  logger.warn(this.tag, "Failed to create audio", soundURL, e);
@@ -4046,7 +4037,13 @@ var __async = (__this, __arguments, generator) => {
4046
4037
  let playSuccess = true;
4047
4038
  try {
4048
4039
  if (config.motionSync) {
4049
- SoundManager.play(audio);
4040
+ SoundManager.play(audio, () => {
4041
+ onFinish == null ? void 0 : onFinish();
4042
+ if (resetExpression && expression && this.expressionManager) {
4043
+ this.expressionManager.resetExpression();
4044
+ }
4045
+ this.currentAudio = void 0;
4046
+ });
4050
4047
  }
4051
4048
  } catch (e) {
4052
4049
  logger.warn(this.tag, "Failed to play audio", audio.url, e);
@@ -4124,24 +4121,14 @@ var __async = (__this, __arguments, generator) => {
4124
4121
  const file = soundURL;
4125
4122
  if (file) {
4126
4123
  try {
4127
- audio = yield SoundManager.add(
4128
- file,
4129
- (that = this) => {
4130
- onFinish == null ? void 0 : onFinish();
4131
- if (resetExpression && expression && that.expressionManager) {
4132
- that.expressionManager.resetExpression();
4133
- }
4134
- that.currentAudio = void 0;
4135
- },
4136
- (e, that = this) => {
4137
- logger.error(this.tag, "Error during audio playback:", e);
4138
- onError == null ? void 0 : onError(e);
4139
- if (resetExpression && expression && that.expressionManager) {
4140
- that.expressionManager.resetExpression();
4141
- }
4142
- that.currentAudio = void 0;
4124
+ audio = yield SoundManager.add(file, (e, that = this) => {
4125
+ logger.error(this.tag, "Error during audio playback:", e);
4126
+ onError == null ? void 0 : onError(e);
4127
+ if (resetExpression && expression && that.expressionManager) {
4128
+ that.expressionManager.resetExpression();
4143
4129
  }
4144
- );
4130
+ that.currentAudio = void 0;
4131
+ });
4145
4132
  this.initializeAudio(audio, volume);
4146
4133
  } catch (e) {
4147
4134
  logger.warn(this.tag, "Failed to create audio", soundURL, e);
@@ -4151,7 +4138,13 @@ var __async = (__this, __arguments, generator) => {
4151
4138
  if (audio) {
4152
4139
  if (config.motionSync) {
4153
4140
  try {
4154
- SoundManager.play(audio);
4141
+ SoundManager.play(audio, (that = this) => {
4142
+ onFinish == null ? void 0 : onFinish();
4143
+ if (resetExpression && expression && that.expressionManager) {
4144
+ that.expressionManager.resetExpression();
4145
+ }
4146
+ that.currentAudio = void 0;
4147
+ });
4155
4148
  } catch (e) {
4156
4149
  logger.warn(this.tag, "Failed to play audio", audio.url, e);
4157
4150
  }