@micdrop/client 3.3.1 → 3.4.0
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/README.md +1 -1
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1221,6 +1221,8 @@ var Pcm16AudioStream = class extends EventEmitter5 {
|
|
|
1221
1221
|
this.prebufferDuration = 0;
|
|
1222
1222
|
this.volumeTimers = [];
|
|
1223
1223
|
this.meter = new VolumeMeter();
|
|
1224
|
+
// Wall time before which no utterance starts, see warmUp()
|
|
1225
|
+
this.holdUntil = 0;
|
|
1224
1226
|
}
|
|
1225
1227
|
/**
|
|
1226
1228
|
* Queues samples for playback
|
|
@@ -1236,6 +1238,34 @@ var Pcm16AudioStream = class extends EventEmitter5 {
|
|
|
1236
1238
|
);
|
|
1237
1239
|
this.handleSamples(samples);
|
|
1238
1240
|
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Plays silence for a while, and holds the next utterance until it is over.
|
|
1243
|
+
*
|
|
1244
|
+
* Firefox mangles what it plays while a Bluetooth headset switches to its
|
|
1245
|
+
* call profile, which the headset does as soon as its microphone opens. The
|
|
1246
|
+
* first answer then comes out all at once. Silence played through that switch
|
|
1247
|
+
* goes unheard.
|
|
1248
|
+
* @param duration - How long to play silence, in milliseconds
|
|
1249
|
+
*/
|
|
1250
|
+
warmUp(duration) {
|
|
1251
|
+
this.holdUntil = Date.now() + duration;
|
|
1252
|
+
const samples = new Float32Array(
|
|
1253
|
+
Math.round(duration / 1e3 * this.sink.sampleRate)
|
|
1254
|
+
);
|
|
1255
|
+
this.warmUpAudio?.stop();
|
|
1256
|
+
this.warmUpAudio = this.sink.schedule(
|
|
1257
|
+
samples,
|
|
1258
|
+
this.sink.currentTime,
|
|
1259
|
+
() => this.warmUpAudio = void 0
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
/** Stops playing, for a stream no longer used */
|
|
1263
|
+
destroy() {
|
|
1264
|
+
this.stopAudio();
|
|
1265
|
+
this.warmUpAudio?.stop();
|
|
1266
|
+
this.warmUpAudio = void 0;
|
|
1267
|
+
this.removeAllListeners();
|
|
1268
|
+
}
|
|
1239
1269
|
/** Drops everything queued and stops playing immediately */
|
|
1240
1270
|
stopAudio() {
|
|
1241
1271
|
for (const source of this.sources) {
|
|
@@ -1275,6 +1305,14 @@ var Pcm16AudioStream = class extends EventEmitter5 {
|
|
|
1275
1305
|
clearTimeout(this.quietTimer);
|
|
1276
1306
|
this.quietTimer = void 0;
|
|
1277
1307
|
}
|
|
1308
|
+
const hold = this.holdUntil - Date.now();
|
|
1309
|
+
if (hold > 0) {
|
|
1310
|
+
this.holdTimer ?? (this.holdTimer = setTimeout(() => {
|
|
1311
|
+
this.holdTimer = void 0;
|
|
1312
|
+
this.flushPrebuffer();
|
|
1313
|
+
}, hold));
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1278
1316
|
this.prebuffering = false;
|
|
1279
1317
|
const buffers = this.prebuffer;
|
|
1280
1318
|
this.prebuffer = [];
|
|
@@ -1290,6 +1328,10 @@ var Pcm16AudioStream = class extends EventEmitter5 {
|
|
|
1290
1328
|
clearTimeout(this.endTimer);
|
|
1291
1329
|
this.endTimer = void 0;
|
|
1292
1330
|
}
|
|
1331
|
+
if (this.holdTimer !== void 0) {
|
|
1332
|
+
clearTimeout(this.holdTimer);
|
|
1333
|
+
this.holdTimer = void 0;
|
|
1334
|
+
}
|
|
1293
1335
|
this.prebuffering = true;
|
|
1294
1336
|
this.prebuffer = [];
|
|
1295
1337
|
this.prebufferDuration = 0;
|