@charivo/tts 0.3.2 → 0.3.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.
package/dist/index.js CHANGED
@@ -160,18 +160,19 @@ var TTSManagerImpl = class {
160
160
  } catch (error) {
161
161
  console.warn("\u26A0\uFE0F TTS Manager: Failed to stop player cleanly", error);
162
162
  throw (0, import_core.toCharivoError)("provider", error, "Failed to stop TTS");
163
+ } finally {
164
+ if (this.currentAudio) {
165
+ this.currentAudio.onended = null;
166
+ this.currentAudio.onerror = null;
167
+ this.currentAudio.pause();
168
+ this.currentAudio = null;
169
+ }
170
+ if (this.currentAudioUrl) {
171
+ URL.revokeObjectURL(this.currentAudioUrl);
172
+ this.currentAudioUrl = null;
173
+ }
174
+ this.endAudioSession();
163
175
  }
164
- if (this.currentAudio) {
165
- this.currentAudio.onended = null;
166
- this.currentAudio.onerror = null;
167
- this.currentAudio.pause();
168
- this.currentAudio = null;
169
- }
170
- if (this.currentAudioUrl) {
171
- URL.revokeObjectURL(this.currentAudioUrl);
172
- this.currentAudioUrl = null;
173
- }
174
- this.endAudioSession();
175
176
  }
176
177
  /**
177
178
  * 음성 설정
@@ -192,7 +193,8 @@ var TTSManagerImpl = class {
192
193
  const dummyAudio = document.createElement("audio");
193
194
  dummyAudio.preload = "none";
194
195
  this.startAudioSession(dummyAudio);
195
- this.webSimulator.startSimulation(text, options?.rate || 1);
196
+ const effectiveRate = options?.rate !== void 0 ? Math.max(0.1, Math.min(10, options.rate)) : 1;
197
+ this.webSimulator.startSimulation(text, effectiveRate);
196
198
  try {
197
199
  await this.ttsPlayer.speak(text, options);
198
200
  } finally {
@@ -230,7 +232,7 @@ var TTSManagerImpl = class {
230
232
  const audio = new Audio(audioUrl);
231
233
  this.currentAudio = audio;
232
234
  this.currentAudioUrl = audioUrl;
233
- if (options?.volume) {
235
+ if (options?.volume !== void 0) {
234
236
  audio.volume = Math.max(0, Math.min(1, options.volume));
235
237
  }
236
238
  this.startAudioSession(audio);
package/dist/index.mjs CHANGED
@@ -132,18 +132,19 @@ var TTSManagerImpl = class {
132
132
  } catch (error) {
133
133
  console.warn("\u26A0\uFE0F TTS Manager: Failed to stop player cleanly", error);
134
134
  throw toCharivoError("provider", error, "Failed to stop TTS");
135
+ } finally {
136
+ if (this.currentAudio) {
137
+ this.currentAudio.onended = null;
138
+ this.currentAudio.onerror = null;
139
+ this.currentAudio.pause();
140
+ this.currentAudio = null;
141
+ }
142
+ if (this.currentAudioUrl) {
143
+ URL.revokeObjectURL(this.currentAudioUrl);
144
+ this.currentAudioUrl = null;
145
+ }
146
+ this.endAudioSession();
135
147
  }
136
- if (this.currentAudio) {
137
- this.currentAudio.onended = null;
138
- this.currentAudio.onerror = null;
139
- this.currentAudio.pause();
140
- this.currentAudio = null;
141
- }
142
- if (this.currentAudioUrl) {
143
- URL.revokeObjectURL(this.currentAudioUrl);
144
- this.currentAudioUrl = null;
145
- }
146
- this.endAudioSession();
147
148
  }
148
149
  /**
149
150
  * 음성 설정
@@ -164,7 +165,8 @@ var TTSManagerImpl = class {
164
165
  const dummyAudio = document.createElement("audio");
165
166
  dummyAudio.preload = "none";
166
167
  this.startAudioSession(dummyAudio);
167
- this.webSimulator.startSimulation(text, options?.rate || 1);
168
+ const effectiveRate = options?.rate !== void 0 ? Math.max(0.1, Math.min(10, options.rate)) : 1;
169
+ this.webSimulator.startSimulation(text, effectiveRate);
168
170
  try {
169
171
  await this.ttsPlayer.speak(text, options);
170
172
  } finally {
@@ -202,7 +204,7 @@ var TTSManagerImpl = class {
202
204
  const audio = new Audio(audioUrl);
203
205
  this.currentAudio = audio;
204
206
  this.currentAudioUrl = audioUrl;
205
- if (options?.volume) {
207
+ if (options?.volume !== void 0) {
206
208
  audio.volume = Math.max(0, Math.min(1, options.volume));
207
209
  }
208
210
  this.startAudioSession(audio);
@@ -128,7 +128,7 @@ var OpenAITTSPlayer = class {
128
128
  const audioUrl = URL.createObjectURL(blob);
129
129
  return new Promise((resolve, reject) => {
130
130
  const audio = new Audio(audioUrl);
131
- if (options?.volume) {
131
+ if (options?.volume !== void 0) {
132
132
  audio.volume = Math.max(0, Math.min(1, options.volume));
133
133
  }
134
134
  audio.onended = () => {
@@ -95,7 +95,7 @@ var OpenAITTSPlayer = class {
95
95
  const audioUrl = URL.createObjectURL(blob);
96
96
  return new Promise((resolve, reject) => {
97
97
  const audio = new Audio(audioUrl);
98
- if (options?.volume) {
98
+ if (options?.volume !== void 0) {
99
99
  audio.volume = Math.max(0, Math.min(1, options.volume));
100
100
  }
101
101
  audio.onended = () => {
@@ -67,7 +67,7 @@ var RemoteTTSPlayer = class {
67
67
  const audioUrl = URL.createObjectURL(blob);
68
68
  return new Promise((resolve, reject) => {
69
69
  const audio = new Audio(audioUrl);
70
- if (options?.volume) {
70
+ if (options?.volume !== void 0) {
71
71
  audio.volume = Math.max(0, Math.min(1, options.volume));
72
72
  }
73
73
  audio.onended = () => {
@@ -46,7 +46,7 @@ var RemoteTTSPlayer = class {
46
46
  const audioUrl = URL.createObjectURL(blob);
47
47
  return new Promise((resolve, reject) => {
48
48
  const audio = new Audio(audioUrl);
49
- if (options?.volume) {
49
+ if (options?.volume !== void 0) {
50
50
  audio.volume = Math.max(0, Math.min(1, options.volume));
51
51
  }
52
52
  audio.onended = () => {
package/dist/web/index.js CHANGED
@@ -61,11 +61,11 @@ var WebTTSPlayer = class {
61
61
  }
62
62
  const utterance = new SpeechSynthesisUtterance(text);
63
63
  if (options) {
64
- if (options.rate)
64
+ if (options.rate !== void 0)
65
65
  utterance.rate = Math.max(0.1, Math.min(10, options.rate));
66
- if (options.pitch)
66
+ if (options.pitch !== void 0)
67
67
  utterance.pitch = Math.max(0, Math.min(2, options.pitch));
68
- if (options.volume)
68
+ if (options.volume !== void 0)
69
69
  utterance.volume = Math.max(0, Math.min(1, options.volume));
70
70
  if (options.voice) {
71
71
  const selectedVoice = this.findVoice(options.voice);
@@ -36,11 +36,11 @@ var WebTTSPlayer = class {
36
36
  }
37
37
  const utterance = new SpeechSynthesisUtterance(text);
38
38
  if (options) {
39
- if (options.rate)
39
+ if (options.rate !== void 0)
40
40
  utterance.rate = Math.max(0.1, Math.min(10, options.rate));
41
- if (options.pitch)
41
+ if (options.pitch !== void 0)
42
42
  utterance.pitch = Math.max(0, Math.min(2, options.pitch));
43
- if (options.volume)
43
+ if (options.volume !== void 0)
44
44
  utterance.volume = Math.max(0, Math.min(1, options.volume));
45
45
  if (options.voice) {
46
46
  const selectedVoice = this.findVoice(options.voice);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charivo/tts",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "TTS manager and browser adapters for Charivo",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "openai": "^4.47.1",
39
- "@charivo/core": "0.11.0"
39
+ "@charivo/core": "0.13.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "tsup": "^8.5.0",