@pompeii-labs/audio 0.1.3 → 0.1.5

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
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var alawmulaw = require('alawmulaw');
4
-
5
3
  // src/decoders/wav.ts
6
4
  function decodeWAV(bytes) {
7
5
  const view = new DataView(bytes.buffer);
@@ -76,11 +74,306 @@ function decodeWAV(bytes) {
76
74
  };
77
75
  return result;
78
76
  }
77
+
78
+ // src/decoders/mulaw.ts
79
79
  function mulawToPcm16(mulawData) {
80
- return alawmulaw.mulaw.decode(mulawData);
80
+ const pcmData = new Int16Array(mulawData.length);
81
+ for (let i = 0; i < mulawData.length; i++) {
82
+ pcmData[i] = mulawToLinear(mulawData[i]);
83
+ }
84
+ return pcmData;
85
+ }
86
+ function mulawToLinear(mulawByte) {
87
+ const inverted = mulawByte ^ 255;
88
+ const sign = inverted & 128;
89
+ const segment = (inverted & 112) >> 4;
90
+ const step = inverted & 15;
91
+ let linear;
92
+ if (segment === 0) {
93
+ linear = (step << 1) + 1;
94
+ } else {
95
+ linear = (step << 1) + 1 + 32 << segment + 2;
96
+ }
97
+ linear -= 33;
98
+ return sign ? -linear : linear;
99
+ }
100
+
101
+ // src/encoders/mulaw.ts
102
+ var BIAS = 132;
103
+ var CLIP = 32635;
104
+ var encodeTable = [
105
+ 0,
106
+ 0,
107
+ 1,
108
+ 1,
109
+ 2,
110
+ 2,
111
+ 2,
112
+ 2,
113
+ 3,
114
+ 3,
115
+ 3,
116
+ 3,
117
+ 3,
118
+ 3,
119
+ 3,
120
+ 3,
121
+ 4,
122
+ 4,
123
+ 4,
124
+ 4,
125
+ 4,
126
+ 4,
127
+ 4,
128
+ 4,
129
+ 4,
130
+ 4,
131
+ 4,
132
+ 4,
133
+ 4,
134
+ 4,
135
+ 4,
136
+ 4,
137
+ 5,
138
+ 5,
139
+ 5,
140
+ 5,
141
+ 5,
142
+ 5,
143
+ 5,
144
+ 5,
145
+ 5,
146
+ 5,
147
+ 5,
148
+ 5,
149
+ 5,
150
+ 5,
151
+ 5,
152
+ 5,
153
+ 5,
154
+ 5,
155
+ 5,
156
+ 5,
157
+ 5,
158
+ 5,
159
+ 5,
160
+ 5,
161
+ 5,
162
+ 5,
163
+ 5,
164
+ 5,
165
+ 5,
166
+ 5,
167
+ 5,
168
+ 5,
169
+ 6,
170
+ 6,
171
+ 6,
172
+ 6,
173
+ 6,
174
+ 6,
175
+ 6,
176
+ 6,
177
+ 6,
178
+ 6,
179
+ 6,
180
+ 6,
181
+ 6,
182
+ 6,
183
+ 6,
184
+ 6,
185
+ 6,
186
+ 6,
187
+ 6,
188
+ 6,
189
+ 6,
190
+ 6,
191
+ 6,
192
+ 6,
193
+ 6,
194
+ 6,
195
+ 6,
196
+ 6,
197
+ 6,
198
+ 6,
199
+ 6,
200
+ 6,
201
+ 6,
202
+ 6,
203
+ 6,
204
+ 6,
205
+ 6,
206
+ 6,
207
+ 6,
208
+ 6,
209
+ 6,
210
+ 6,
211
+ 6,
212
+ 6,
213
+ 6,
214
+ 6,
215
+ 6,
216
+ 6,
217
+ 6,
218
+ 6,
219
+ 6,
220
+ 6,
221
+ 6,
222
+ 6,
223
+ 6,
224
+ 6,
225
+ 6,
226
+ 6,
227
+ 6,
228
+ 6,
229
+ 6,
230
+ 6,
231
+ 6,
232
+ 6,
233
+ 7,
234
+ 7,
235
+ 7,
236
+ 7,
237
+ 7,
238
+ 7,
239
+ 7,
240
+ 7,
241
+ 7,
242
+ 7,
243
+ 7,
244
+ 7,
245
+ 7,
246
+ 7,
247
+ 7,
248
+ 7,
249
+ 7,
250
+ 7,
251
+ 7,
252
+ 7,
253
+ 7,
254
+ 7,
255
+ 7,
256
+ 7,
257
+ 7,
258
+ 7,
259
+ 7,
260
+ 7,
261
+ 7,
262
+ 7,
263
+ 7,
264
+ 7,
265
+ 7,
266
+ 7,
267
+ 7,
268
+ 7,
269
+ 7,
270
+ 7,
271
+ 7,
272
+ 7,
273
+ 7,
274
+ 7,
275
+ 7,
276
+ 7,
277
+ 7,
278
+ 7,
279
+ 7,
280
+ 7,
281
+ 7,
282
+ 7,
283
+ 7,
284
+ 7,
285
+ 7,
286
+ 7,
287
+ 7,
288
+ 7,
289
+ 7,
290
+ 7,
291
+ 7,
292
+ 7,
293
+ 7,
294
+ 7,
295
+ 7,
296
+ 7,
297
+ 7,
298
+ 7,
299
+ 7,
300
+ 7,
301
+ 7,
302
+ 7,
303
+ 7,
304
+ 7,
305
+ 7,
306
+ 7,
307
+ 7,
308
+ 7,
309
+ 7,
310
+ 7,
311
+ 7,
312
+ 7,
313
+ 7,
314
+ 7,
315
+ 7,
316
+ 7,
317
+ 7,
318
+ 7,
319
+ 7,
320
+ 7,
321
+ 7,
322
+ 7,
323
+ 7,
324
+ 7,
325
+ 7,
326
+ 7,
327
+ 7,
328
+ 7,
329
+ 7,
330
+ 7,
331
+ 7,
332
+ 7,
333
+ 7,
334
+ 7,
335
+ 7,
336
+ 7,
337
+ 7,
338
+ 7,
339
+ 7,
340
+ 7,
341
+ 7,
342
+ 7,
343
+ 7,
344
+ 7,
345
+ 7,
346
+ 7,
347
+ 7,
348
+ 7,
349
+ 7,
350
+ 7,
351
+ 7,
352
+ 7,
353
+ 7,
354
+ 7,
355
+ 7,
356
+ 7,
357
+ 7,
358
+ 7,
359
+ 7,
360
+ 7
361
+ ];
362
+ function encodeSample(sample) {
363
+ const sign = sample >> 8 & 128;
364
+ if (sign !== 0) sample = -sample;
365
+ sample = sample + BIAS;
366
+ if (sample > CLIP) sample = CLIP;
367
+ const exponent = encodeTable[sample >> 7 & 255];
368
+ const mantissa = sample >> exponent + 3 & 15;
369
+ return ~(sign | exponent << 4 | mantissa);
81
370
  }
82
371
  function pcm16ToMulaw(pcmData) {
83
- return alawmulaw.mulaw.encode(pcmData);
372
+ const mulawData = new Uint8Array(pcmData.length);
373
+ for (let i = 0; i < pcmData.length; i++) {
374
+ mulawData[i] = encodeSample(pcmData[i]);
375
+ }
376
+ return mulawData;
84
377
  }
85
378
 
86
379
  // src/helpers/bufferToInt16Array.ts
package/dist/index.mjs CHANGED
@@ -1,5 +1,3 @@
1
- import { mulaw } from 'alawmulaw';
2
-
3
1
  // src/decoders/wav.ts
4
2
  function decodeWAV(bytes) {
5
3
  const view = new DataView(bytes.buffer);
@@ -74,11 +72,306 @@ function decodeWAV(bytes) {
74
72
  };
75
73
  return result;
76
74
  }
75
+
76
+ // src/decoders/mulaw.ts
77
77
  function mulawToPcm16(mulawData) {
78
- return mulaw.decode(mulawData);
78
+ const pcmData = new Int16Array(mulawData.length);
79
+ for (let i = 0; i < mulawData.length; i++) {
80
+ pcmData[i] = mulawToLinear(mulawData[i]);
81
+ }
82
+ return pcmData;
83
+ }
84
+ function mulawToLinear(mulawByte) {
85
+ const inverted = mulawByte ^ 255;
86
+ const sign = inverted & 128;
87
+ const segment = (inverted & 112) >> 4;
88
+ const step = inverted & 15;
89
+ let linear;
90
+ if (segment === 0) {
91
+ linear = (step << 1) + 1;
92
+ } else {
93
+ linear = (step << 1) + 1 + 32 << segment + 2;
94
+ }
95
+ linear -= 33;
96
+ return sign ? -linear : linear;
97
+ }
98
+
99
+ // src/encoders/mulaw.ts
100
+ var BIAS = 132;
101
+ var CLIP = 32635;
102
+ var encodeTable = [
103
+ 0,
104
+ 0,
105
+ 1,
106
+ 1,
107
+ 2,
108
+ 2,
109
+ 2,
110
+ 2,
111
+ 3,
112
+ 3,
113
+ 3,
114
+ 3,
115
+ 3,
116
+ 3,
117
+ 3,
118
+ 3,
119
+ 4,
120
+ 4,
121
+ 4,
122
+ 4,
123
+ 4,
124
+ 4,
125
+ 4,
126
+ 4,
127
+ 4,
128
+ 4,
129
+ 4,
130
+ 4,
131
+ 4,
132
+ 4,
133
+ 4,
134
+ 4,
135
+ 5,
136
+ 5,
137
+ 5,
138
+ 5,
139
+ 5,
140
+ 5,
141
+ 5,
142
+ 5,
143
+ 5,
144
+ 5,
145
+ 5,
146
+ 5,
147
+ 5,
148
+ 5,
149
+ 5,
150
+ 5,
151
+ 5,
152
+ 5,
153
+ 5,
154
+ 5,
155
+ 5,
156
+ 5,
157
+ 5,
158
+ 5,
159
+ 5,
160
+ 5,
161
+ 5,
162
+ 5,
163
+ 5,
164
+ 5,
165
+ 5,
166
+ 5,
167
+ 6,
168
+ 6,
169
+ 6,
170
+ 6,
171
+ 6,
172
+ 6,
173
+ 6,
174
+ 6,
175
+ 6,
176
+ 6,
177
+ 6,
178
+ 6,
179
+ 6,
180
+ 6,
181
+ 6,
182
+ 6,
183
+ 6,
184
+ 6,
185
+ 6,
186
+ 6,
187
+ 6,
188
+ 6,
189
+ 6,
190
+ 6,
191
+ 6,
192
+ 6,
193
+ 6,
194
+ 6,
195
+ 6,
196
+ 6,
197
+ 6,
198
+ 6,
199
+ 6,
200
+ 6,
201
+ 6,
202
+ 6,
203
+ 6,
204
+ 6,
205
+ 6,
206
+ 6,
207
+ 6,
208
+ 6,
209
+ 6,
210
+ 6,
211
+ 6,
212
+ 6,
213
+ 6,
214
+ 6,
215
+ 6,
216
+ 6,
217
+ 6,
218
+ 6,
219
+ 6,
220
+ 6,
221
+ 6,
222
+ 6,
223
+ 6,
224
+ 6,
225
+ 6,
226
+ 6,
227
+ 6,
228
+ 6,
229
+ 6,
230
+ 6,
231
+ 7,
232
+ 7,
233
+ 7,
234
+ 7,
235
+ 7,
236
+ 7,
237
+ 7,
238
+ 7,
239
+ 7,
240
+ 7,
241
+ 7,
242
+ 7,
243
+ 7,
244
+ 7,
245
+ 7,
246
+ 7,
247
+ 7,
248
+ 7,
249
+ 7,
250
+ 7,
251
+ 7,
252
+ 7,
253
+ 7,
254
+ 7,
255
+ 7,
256
+ 7,
257
+ 7,
258
+ 7,
259
+ 7,
260
+ 7,
261
+ 7,
262
+ 7,
263
+ 7,
264
+ 7,
265
+ 7,
266
+ 7,
267
+ 7,
268
+ 7,
269
+ 7,
270
+ 7,
271
+ 7,
272
+ 7,
273
+ 7,
274
+ 7,
275
+ 7,
276
+ 7,
277
+ 7,
278
+ 7,
279
+ 7,
280
+ 7,
281
+ 7,
282
+ 7,
283
+ 7,
284
+ 7,
285
+ 7,
286
+ 7,
287
+ 7,
288
+ 7,
289
+ 7,
290
+ 7,
291
+ 7,
292
+ 7,
293
+ 7,
294
+ 7,
295
+ 7,
296
+ 7,
297
+ 7,
298
+ 7,
299
+ 7,
300
+ 7,
301
+ 7,
302
+ 7,
303
+ 7,
304
+ 7,
305
+ 7,
306
+ 7,
307
+ 7,
308
+ 7,
309
+ 7,
310
+ 7,
311
+ 7,
312
+ 7,
313
+ 7,
314
+ 7,
315
+ 7,
316
+ 7,
317
+ 7,
318
+ 7,
319
+ 7,
320
+ 7,
321
+ 7,
322
+ 7,
323
+ 7,
324
+ 7,
325
+ 7,
326
+ 7,
327
+ 7,
328
+ 7,
329
+ 7,
330
+ 7,
331
+ 7,
332
+ 7,
333
+ 7,
334
+ 7,
335
+ 7,
336
+ 7,
337
+ 7,
338
+ 7,
339
+ 7,
340
+ 7,
341
+ 7,
342
+ 7,
343
+ 7,
344
+ 7,
345
+ 7,
346
+ 7,
347
+ 7,
348
+ 7,
349
+ 7,
350
+ 7,
351
+ 7,
352
+ 7,
353
+ 7,
354
+ 7,
355
+ 7,
356
+ 7,
357
+ 7,
358
+ 7
359
+ ];
360
+ function encodeSample(sample) {
361
+ const sign = sample >> 8 & 128;
362
+ if (sign !== 0) sample = -sample;
363
+ sample = sample + BIAS;
364
+ if (sample > CLIP) sample = CLIP;
365
+ const exponent = encodeTable[sample >> 7 & 255];
366
+ const mantissa = sample >> exponent + 3 & 15;
367
+ return ~(sign | exponent << 4 | mantissa);
79
368
  }
80
369
  function pcm16ToMulaw(pcmData) {
81
- return mulaw.encode(pcmData);
370
+ const mulawData = new Uint8Array(pcmData.length);
371
+ for (let i = 0; i < pcmData.length; i++) {
372
+ mulawData[i] = encodeSample(pcmData[i]);
373
+ }
374
+ return mulawData;
82
375
  }
83
376
 
84
377
  // src/helpers/bufferToInt16Array.ts
package/dist/voice.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var alawmulaw = require('alawmulaw');
4
3
  var sdk = require('@deepgram/sdk');
5
4
  var elevenlabsJs = require('@elevenlabs/elevenlabs-js');
6
5
  var hume = require('hume');
@@ -14,11 +13,306 @@ var OpenAI__default = /*#__PURE__*/_interopDefault(OpenAI);
14
13
  function bufferToInt16Array(buffer) {
15
14
  return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2);
16
15
  }
16
+
17
+ // src/decoders/mulaw.ts
17
18
  function mulawToPcm16(mulawData) {
18
- return alawmulaw.mulaw.decode(mulawData);
19
+ const pcmData = new Int16Array(mulawData.length);
20
+ for (let i = 0; i < mulawData.length; i++) {
21
+ pcmData[i] = mulawToLinear(mulawData[i]);
22
+ }
23
+ return pcmData;
24
+ }
25
+ function mulawToLinear(mulawByte) {
26
+ const inverted = mulawByte ^ 255;
27
+ const sign = inverted & 128;
28
+ const segment = (inverted & 112) >> 4;
29
+ const step = inverted & 15;
30
+ let linear;
31
+ if (segment === 0) {
32
+ linear = (step << 1) + 1;
33
+ } else {
34
+ linear = (step << 1) + 1 + 32 << segment + 2;
35
+ }
36
+ linear -= 33;
37
+ return sign ? -linear : linear;
38
+ }
39
+
40
+ // src/encoders/mulaw.ts
41
+ var BIAS = 132;
42
+ var CLIP = 32635;
43
+ var encodeTable = [
44
+ 0,
45
+ 0,
46
+ 1,
47
+ 1,
48
+ 2,
49
+ 2,
50
+ 2,
51
+ 2,
52
+ 3,
53
+ 3,
54
+ 3,
55
+ 3,
56
+ 3,
57
+ 3,
58
+ 3,
59
+ 3,
60
+ 4,
61
+ 4,
62
+ 4,
63
+ 4,
64
+ 4,
65
+ 4,
66
+ 4,
67
+ 4,
68
+ 4,
69
+ 4,
70
+ 4,
71
+ 4,
72
+ 4,
73
+ 4,
74
+ 4,
75
+ 4,
76
+ 5,
77
+ 5,
78
+ 5,
79
+ 5,
80
+ 5,
81
+ 5,
82
+ 5,
83
+ 5,
84
+ 5,
85
+ 5,
86
+ 5,
87
+ 5,
88
+ 5,
89
+ 5,
90
+ 5,
91
+ 5,
92
+ 5,
93
+ 5,
94
+ 5,
95
+ 5,
96
+ 5,
97
+ 5,
98
+ 5,
99
+ 5,
100
+ 5,
101
+ 5,
102
+ 5,
103
+ 5,
104
+ 5,
105
+ 5,
106
+ 5,
107
+ 5,
108
+ 6,
109
+ 6,
110
+ 6,
111
+ 6,
112
+ 6,
113
+ 6,
114
+ 6,
115
+ 6,
116
+ 6,
117
+ 6,
118
+ 6,
119
+ 6,
120
+ 6,
121
+ 6,
122
+ 6,
123
+ 6,
124
+ 6,
125
+ 6,
126
+ 6,
127
+ 6,
128
+ 6,
129
+ 6,
130
+ 6,
131
+ 6,
132
+ 6,
133
+ 6,
134
+ 6,
135
+ 6,
136
+ 6,
137
+ 6,
138
+ 6,
139
+ 6,
140
+ 6,
141
+ 6,
142
+ 6,
143
+ 6,
144
+ 6,
145
+ 6,
146
+ 6,
147
+ 6,
148
+ 6,
149
+ 6,
150
+ 6,
151
+ 6,
152
+ 6,
153
+ 6,
154
+ 6,
155
+ 6,
156
+ 6,
157
+ 6,
158
+ 6,
159
+ 6,
160
+ 6,
161
+ 6,
162
+ 6,
163
+ 6,
164
+ 6,
165
+ 6,
166
+ 6,
167
+ 6,
168
+ 6,
169
+ 6,
170
+ 6,
171
+ 6,
172
+ 7,
173
+ 7,
174
+ 7,
175
+ 7,
176
+ 7,
177
+ 7,
178
+ 7,
179
+ 7,
180
+ 7,
181
+ 7,
182
+ 7,
183
+ 7,
184
+ 7,
185
+ 7,
186
+ 7,
187
+ 7,
188
+ 7,
189
+ 7,
190
+ 7,
191
+ 7,
192
+ 7,
193
+ 7,
194
+ 7,
195
+ 7,
196
+ 7,
197
+ 7,
198
+ 7,
199
+ 7,
200
+ 7,
201
+ 7,
202
+ 7,
203
+ 7,
204
+ 7,
205
+ 7,
206
+ 7,
207
+ 7,
208
+ 7,
209
+ 7,
210
+ 7,
211
+ 7,
212
+ 7,
213
+ 7,
214
+ 7,
215
+ 7,
216
+ 7,
217
+ 7,
218
+ 7,
219
+ 7,
220
+ 7,
221
+ 7,
222
+ 7,
223
+ 7,
224
+ 7,
225
+ 7,
226
+ 7,
227
+ 7,
228
+ 7,
229
+ 7,
230
+ 7,
231
+ 7,
232
+ 7,
233
+ 7,
234
+ 7,
235
+ 7,
236
+ 7,
237
+ 7,
238
+ 7,
239
+ 7,
240
+ 7,
241
+ 7,
242
+ 7,
243
+ 7,
244
+ 7,
245
+ 7,
246
+ 7,
247
+ 7,
248
+ 7,
249
+ 7,
250
+ 7,
251
+ 7,
252
+ 7,
253
+ 7,
254
+ 7,
255
+ 7,
256
+ 7,
257
+ 7,
258
+ 7,
259
+ 7,
260
+ 7,
261
+ 7,
262
+ 7,
263
+ 7,
264
+ 7,
265
+ 7,
266
+ 7,
267
+ 7,
268
+ 7,
269
+ 7,
270
+ 7,
271
+ 7,
272
+ 7,
273
+ 7,
274
+ 7,
275
+ 7,
276
+ 7,
277
+ 7,
278
+ 7,
279
+ 7,
280
+ 7,
281
+ 7,
282
+ 7,
283
+ 7,
284
+ 7,
285
+ 7,
286
+ 7,
287
+ 7,
288
+ 7,
289
+ 7,
290
+ 7,
291
+ 7,
292
+ 7,
293
+ 7,
294
+ 7,
295
+ 7,
296
+ 7,
297
+ 7,
298
+ 7,
299
+ 7
300
+ ];
301
+ function encodeSample(sample) {
302
+ const sign = sample >> 8 & 128;
303
+ if (sign !== 0) sample = -sample;
304
+ sample = sample + BIAS;
305
+ if (sample > CLIP) sample = CLIP;
306
+ const exponent = encodeTable[sample >> 7 & 255];
307
+ const mantissa = sample >> exponent + 3 & 15;
308
+ return ~(sign | exponent << 4 | mantissa);
19
309
  }
20
310
  function pcm16ToMulaw(pcmData) {
21
- return alawmulaw.mulaw.encode(pcmData);
311
+ const mulawData = new Uint8Array(pcmData.length);
312
+ for (let i = 0; i < pcmData.length; i++) {
313
+ mulawData[i] = encodeSample(pcmData[i]);
314
+ }
315
+ return mulawData;
22
316
  }
23
317
 
24
318
  // src/helpers/int16ArrayToBuffer.ts
@@ -182,7 +476,8 @@ var MagmaFlow = class {
182
476
  this.stt.input(int16ArrayToBuffer(resampledPCM));
183
477
  }
184
478
  inputText(text) {
185
- if (!text) {
479
+ if (text === void 0 || text === null) {
480
+ if (this.textBuffer.length === 0) return;
186
481
  this.textQueue.push(this.textBuffer);
187
482
  this.textBuffer = "";
188
483
  this.generateAudio();
@@ -191,6 +486,7 @@ var MagmaFlow = class {
191
486
  this.textBuffer += text;
192
487
  const chunks = splitTextIntoChunks(this.textBuffer, this.config.sentenceChunkLength ?? 50);
193
488
  for (const chunk of chunks) {
489
+ if (chunk.length === 0) continue;
194
490
  this.textQueue.push(chunk);
195
491
  this.textBuffer = this.textBuffer.slice(chunk.length);
196
492
  this.generateAudio();
package/dist/voice.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { mulaw } from 'alawmulaw';
2
1
  import { DeepgramClient, LiveTranscriptionEvents } from '@deepgram/sdk';
3
2
  import { ElevenLabsClient } from '@elevenlabs/elevenlabs-js';
4
3
  import { HumeClient } from 'hume';
@@ -8,11 +7,306 @@ import OpenAI from 'openai';
8
7
  function bufferToInt16Array(buffer) {
9
8
  return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2);
10
9
  }
10
+
11
+ // src/decoders/mulaw.ts
11
12
  function mulawToPcm16(mulawData) {
12
- return mulaw.decode(mulawData);
13
+ const pcmData = new Int16Array(mulawData.length);
14
+ for (let i = 0; i < mulawData.length; i++) {
15
+ pcmData[i] = mulawToLinear(mulawData[i]);
16
+ }
17
+ return pcmData;
18
+ }
19
+ function mulawToLinear(mulawByte) {
20
+ const inverted = mulawByte ^ 255;
21
+ const sign = inverted & 128;
22
+ const segment = (inverted & 112) >> 4;
23
+ const step = inverted & 15;
24
+ let linear;
25
+ if (segment === 0) {
26
+ linear = (step << 1) + 1;
27
+ } else {
28
+ linear = (step << 1) + 1 + 32 << segment + 2;
29
+ }
30
+ linear -= 33;
31
+ return sign ? -linear : linear;
32
+ }
33
+
34
+ // src/encoders/mulaw.ts
35
+ var BIAS = 132;
36
+ var CLIP = 32635;
37
+ var encodeTable = [
38
+ 0,
39
+ 0,
40
+ 1,
41
+ 1,
42
+ 2,
43
+ 2,
44
+ 2,
45
+ 2,
46
+ 3,
47
+ 3,
48
+ 3,
49
+ 3,
50
+ 3,
51
+ 3,
52
+ 3,
53
+ 3,
54
+ 4,
55
+ 4,
56
+ 4,
57
+ 4,
58
+ 4,
59
+ 4,
60
+ 4,
61
+ 4,
62
+ 4,
63
+ 4,
64
+ 4,
65
+ 4,
66
+ 4,
67
+ 4,
68
+ 4,
69
+ 4,
70
+ 5,
71
+ 5,
72
+ 5,
73
+ 5,
74
+ 5,
75
+ 5,
76
+ 5,
77
+ 5,
78
+ 5,
79
+ 5,
80
+ 5,
81
+ 5,
82
+ 5,
83
+ 5,
84
+ 5,
85
+ 5,
86
+ 5,
87
+ 5,
88
+ 5,
89
+ 5,
90
+ 5,
91
+ 5,
92
+ 5,
93
+ 5,
94
+ 5,
95
+ 5,
96
+ 5,
97
+ 5,
98
+ 5,
99
+ 5,
100
+ 5,
101
+ 5,
102
+ 6,
103
+ 6,
104
+ 6,
105
+ 6,
106
+ 6,
107
+ 6,
108
+ 6,
109
+ 6,
110
+ 6,
111
+ 6,
112
+ 6,
113
+ 6,
114
+ 6,
115
+ 6,
116
+ 6,
117
+ 6,
118
+ 6,
119
+ 6,
120
+ 6,
121
+ 6,
122
+ 6,
123
+ 6,
124
+ 6,
125
+ 6,
126
+ 6,
127
+ 6,
128
+ 6,
129
+ 6,
130
+ 6,
131
+ 6,
132
+ 6,
133
+ 6,
134
+ 6,
135
+ 6,
136
+ 6,
137
+ 6,
138
+ 6,
139
+ 6,
140
+ 6,
141
+ 6,
142
+ 6,
143
+ 6,
144
+ 6,
145
+ 6,
146
+ 6,
147
+ 6,
148
+ 6,
149
+ 6,
150
+ 6,
151
+ 6,
152
+ 6,
153
+ 6,
154
+ 6,
155
+ 6,
156
+ 6,
157
+ 6,
158
+ 6,
159
+ 6,
160
+ 6,
161
+ 6,
162
+ 6,
163
+ 6,
164
+ 6,
165
+ 6,
166
+ 7,
167
+ 7,
168
+ 7,
169
+ 7,
170
+ 7,
171
+ 7,
172
+ 7,
173
+ 7,
174
+ 7,
175
+ 7,
176
+ 7,
177
+ 7,
178
+ 7,
179
+ 7,
180
+ 7,
181
+ 7,
182
+ 7,
183
+ 7,
184
+ 7,
185
+ 7,
186
+ 7,
187
+ 7,
188
+ 7,
189
+ 7,
190
+ 7,
191
+ 7,
192
+ 7,
193
+ 7,
194
+ 7,
195
+ 7,
196
+ 7,
197
+ 7,
198
+ 7,
199
+ 7,
200
+ 7,
201
+ 7,
202
+ 7,
203
+ 7,
204
+ 7,
205
+ 7,
206
+ 7,
207
+ 7,
208
+ 7,
209
+ 7,
210
+ 7,
211
+ 7,
212
+ 7,
213
+ 7,
214
+ 7,
215
+ 7,
216
+ 7,
217
+ 7,
218
+ 7,
219
+ 7,
220
+ 7,
221
+ 7,
222
+ 7,
223
+ 7,
224
+ 7,
225
+ 7,
226
+ 7,
227
+ 7,
228
+ 7,
229
+ 7,
230
+ 7,
231
+ 7,
232
+ 7,
233
+ 7,
234
+ 7,
235
+ 7,
236
+ 7,
237
+ 7,
238
+ 7,
239
+ 7,
240
+ 7,
241
+ 7,
242
+ 7,
243
+ 7,
244
+ 7,
245
+ 7,
246
+ 7,
247
+ 7,
248
+ 7,
249
+ 7,
250
+ 7,
251
+ 7,
252
+ 7,
253
+ 7,
254
+ 7,
255
+ 7,
256
+ 7,
257
+ 7,
258
+ 7,
259
+ 7,
260
+ 7,
261
+ 7,
262
+ 7,
263
+ 7,
264
+ 7,
265
+ 7,
266
+ 7,
267
+ 7,
268
+ 7,
269
+ 7,
270
+ 7,
271
+ 7,
272
+ 7,
273
+ 7,
274
+ 7,
275
+ 7,
276
+ 7,
277
+ 7,
278
+ 7,
279
+ 7,
280
+ 7,
281
+ 7,
282
+ 7,
283
+ 7,
284
+ 7,
285
+ 7,
286
+ 7,
287
+ 7,
288
+ 7,
289
+ 7,
290
+ 7,
291
+ 7,
292
+ 7,
293
+ 7
294
+ ];
295
+ function encodeSample(sample) {
296
+ const sign = sample >> 8 & 128;
297
+ if (sign !== 0) sample = -sample;
298
+ sample = sample + BIAS;
299
+ if (sample > CLIP) sample = CLIP;
300
+ const exponent = encodeTable[sample >> 7 & 255];
301
+ const mantissa = sample >> exponent + 3 & 15;
302
+ return ~(sign | exponent << 4 | mantissa);
13
303
  }
14
304
  function pcm16ToMulaw(pcmData) {
15
- return mulaw.encode(pcmData);
305
+ const mulawData = new Uint8Array(pcmData.length);
306
+ for (let i = 0; i < pcmData.length; i++) {
307
+ mulawData[i] = encodeSample(pcmData[i]);
308
+ }
309
+ return mulawData;
16
310
  }
17
311
 
18
312
  // src/helpers/int16ArrayToBuffer.ts
@@ -176,7 +470,8 @@ var MagmaFlow = class {
176
470
  this.stt.input(int16ArrayToBuffer(resampledPCM));
177
471
  }
178
472
  inputText(text) {
179
- if (!text) {
473
+ if (text === void 0 || text === null) {
474
+ if (this.textBuffer.length === 0) return;
180
475
  this.textQueue.push(this.textBuffer);
181
476
  this.textBuffer = "";
182
477
  this.generateAudio();
@@ -185,6 +480,7 @@ var MagmaFlow = class {
185
480
  this.textBuffer += text;
186
481
  const chunks = splitTextIntoChunks(this.textBuffer, this.config.sentenceChunkLength ?? 50);
187
482
  for (const chunk of chunks) {
483
+ if (chunk.length === 0) continue;
188
484
  this.textQueue.push(chunk);
189
485
  this.textBuffer = this.textBuffer.slice(chunk.length);
190
486
  this.generateAudio();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pompeii-labs/audio",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "The Audio SDK from Pompeii Labs",
5
5
  "keywords": [
6
6
  "Pompeii",
@@ -44,8 +44,7 @@
44
44
  "@deepgram/sdk": "4.2.0",
45
45
  "@elevenlabs/elevenlabs-js": "2.2.0",
46
46
  "hume": "0.11.1",
47
- "openai": "4.86.2",
48
- "alawmulaw": "^6.0.0"
47
+ "openai": "4.86.2"
49
48
  },
50
49
  "devDependencies": {
51
50
  "@types/node": "^22.16.0",