@easyv/biz-components 0.0.13 → 0.0.16

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.
Files changed (32) hide show
  1. package/dist/hooks/index.d.ts +1 -0
  2. package/dist/hooks/useXunFeiSteamVoiceManager.d.ts +8 -0
  3. package/dist/hooks/useXunFeiSteamVoiceManager.es.js +15 -0
  4. package/dist/hooks/useXunFeiSteamVoiceManager.es.js.map +1 -0
  5. package/dist/index.es.js +10 -6
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager-draft.d.ts +38 -0
  8. package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager.d.ts +42 -0
  9. package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager.es.js +118 -0
  10. package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager.es.js.map +1 -0
  11. package/dist/utils/xunFeiVoice/RecorderManager/index.d.ts +1 -0
  12. package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worker.d.ts +0 -0
  13. package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worker.es.js +233 -0
  14. package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worker.es.js.map +1 -0
  15. package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worklet.d.ts +0 -0
  16. package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worklet.es.js +379 -0
  17. package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worklet.es.js.map +1 -0
  18. package/dist/utils/xunFeiVoice/{xunFeiStreamVoiceManager.d.ts → XunFeiStreamVoiceManager.d.ts} +16 -15
  19. package/dist/utils/xunFeiVoice/XunFeiStreamVoiceManager.es.js +177 -0
  20. package/dist/utils/xunFeiVoice/XunFeiStreamVoiceManager.es.js.map +1 -0
  21. package/dist/utils/xunFeiVoice/index.d.ts +3 -1
  22. package/dist/utils/xunFeiVoice/test/RecorderManager.cy.d.ts +1 -0
  23. package/dist/utils/xunFeiVoice/test/XunFeiVoiceManager.cy.d.ts +1 -0
  24. package/dist/utils/xunFeiVoice/types.d.ts +11 -2
  25. package/dist/utils/xunFeiVoice/utils.d.ts +0 -1
  26. package/dist/utils/xunFeiVoice/utils.es.js.map +1 -1
  27. package/package.json +4 -2
  28. package/dist/utils/xunFeiVoice/recordManager.es.js +0 -175
  29. package/dist/utils/xunFeiVoice/recordManager.es.js.map +0 -1
  30. package/dist/utils/xunFeiVoice/xunFeiStreamVoiceManager.es.js +0 -140
  31. package/dist/utils/xunFeiVoice/xunFeiStreamVoiceManager.es.js.map +0 -1
  32. /package/dist/utils/xunFeiVoice/{recordManager.d.ts → RecorderManager/RecordManager-origin.d.ts} +0 -0
@@ -0,0 +1,379 @@
1
+ const n = `!(function () {
2
+ 'use strict';
3
+ function t(t, e) {
4
+ for (var r = 0; r < e.length; r++) {
5
+ var n = e[r];
6
+ (n.enumerable = n.enumerable || !1),
7
+ (n.configurable = !0),
8
+ 'value' in n && (n.writable = !0),
9
+ Object.defineProperty(
10
+ t,
11
+ ((i = n.key),
12
+ (o = void 0),
13
+ 'symbol' ==
14
+ typeof (o = (function (t, e) {
15
+ if ('object' != typeof t || null === t) return t;
16
+ var r = t[Symbol.toPrimitive];
17
+ if (void 0 !== r) {
18
+ var n = r.call(t, e || 'default');
19
+ if ('object' != typeof n) return n;
20
+ throw new TypeError('@@toPrimitive must return a primitive value.');
21
+ }
22
+ return ('string' === e ? String : Number)(t);
23
+ })(i, 'string'))
24
+ ? o
25
+ : String(o)),
26
+ n,
27
+ );
28
+ }
29
+ var i, o;
30
+ }
31
+ function e(t) {
32
+ return (
33
+ (e = Object.setPrototypeOf
34
+ ? Object.getPrototypeOf.bind()
35
+ : function (t) {
36
+ return t.__proto__ || Object.getPrototypeOf(t);
37
+ }),
38
+ e(t)
39
+ );
40
+ }
41
+ function r(t, e) {
42
+ return (
43
+ (r = Object.setPrototypeOf
44
+ ? Object.setPrototypeOf.bind()
45
+ : function (t, e) {
46
+ return (t.__proto__ = e), t;
47
+ }),
48
+ r(t, e)
49
+ );
50
+ }
51
+ function n() {
52
+ if ('undefined' == typeof Reflect || !Reflect.construct) return !1;
53
+ if (Reflect.construct.sham) return !1;
54
+ if ('function' == typeof Proxy) return !0;
55
+ try {
56
+ return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})), !0;
57
+ } catch (t) {
58
+ return !1;
59
+ }
60
+ }
61
+ function i(t, e, o) {
62
+ return (
63
+ (i = n()
64
+ ? Reflect.construct.bind()
65
+ : function (t, e, n) {
66
+ var i = [null];
67
+ i.push.apply(i, e);
68
+ var o = new (Function.bind.apply(t, i))();
69
+ return n && r(o, n.prototype), o;
70
+ }),
71
+ i.apply(null, arguments)
72
+ );
73
+ }
74
+ function o(t) {
75
+ var n = 'function' == typeof Map ? new Map() : void 0;
76
+ return (
77
+ (o = function (t) {
78
+ if (null === t || ((o = t), -1 === Function.toString.call(o).indexOf('[native code]')))
79
+ return t;
80
+ var o;
81
+ if ('function' != typeof t)
82
+ throw new TypeError('Super expression must either be null or a function');
83
+ if (void 0 !== n) {
84
+ if (n.has(t)) return n.get(t);
85
+ n.set(t, a);
86
+ }
87
+ function a() {
88
+ return i(t, arguments, e(this).constructor);
89
+ }
90
+ return (
91
+ (a.prototype = Object.create(t.prototype, {
92
+ constructor: {
93
+ value: a,
94
+ enumerable: !1,
95
+ writable: !0,
96
+ configurable: !0,
97
+ },
98
+ })),
99
+ r(a, t)
100
+ );
101
+ }),
102
+ o(t)
103
+ );
104
+ }
105
+ function a(t) {
106
+ if (void 0 === t)
107
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
108
+ return t;
109
+ }
110
+ function s(t) {
111
+ var r = n();
112
+ return function () {
113
+ var n,
114
+ i = e(t);
115
+ if (r) {
116
+ var o = e(this).constructor;
117
+ n = Reflect.construct(i, arguments, o);
118
+ } else n = i.apply(this, arguments);
119
+ return (function (t, e) {
120
+ if (e && ('object' == typeof e || 'function' == typeof e)) return e;
121
+ if (void 0 !== e)
122
+ throw new TypeError('Derived constructors may only return object or undefined');
123
+ return a(t);
124
+ })(this, n);
125
+ };
126
+ }
127
+ function fn(t) {
128
+ return (
129
+ (function (t) {
130
+ if (Array.isArray(t)) return u(t);
131
+ })(t) ||
132
+ (function (t) {
133
+ if (
134
+ t !== undefined &&
135
+ (('undefined' != typeof Symbol && null != t[Symbol.iterator]) || null != t['@@iterator'])
136
+ )
137
+ return Array.from(t);
138
+ })(t) ||
139
+ (function (t, e) {
140
+ if (!t) return;
141
+ if ('string' == typeof t) return u(t, e);
142
+ var r = Object.prototype.toString.call(t).slice(8, -1);
143
+ 'Object' === r && t.constructor && (r = t.constructor.name);
144
+ if ('Map' === r || 'Set' === r) return Array.from(t);
145
+ if ('Arguments' === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)) return u(t, e);
146
+ })(t) ||
147
+ (function () {
148
+ throw new TypeError(
149
+ 'Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
150
+ );
151
+ })()
152
+ );
153
+ }
154
+ function u(t, e) {
155
+ (null == e || e > t.length) && (e = t.length);
156
+ for (var r = 0, n = new Array(e); r < e; r++) n[r] = t[r];
157
+ return n;
158
+ }
159
+ function l(t, e, r, n) {
160
+ (this.fromSampleRate = t),
161
+ (this.toSampleRate = e),
162
+ (this.channels = 0 | r),
163
+ (this.noReturn = !!n),
164
+ this.initialize();
165
+ }
166
+ (l.prototype.initialize = function () {
167
+ if (!(this.fromSampleRate > 0 && this.toSampleRate > 0 && this.channels > 0))
168
+ throw new Error('Invalid settings specified for the resampler.');
169
+ this.fromSampleRate == this.toSampleRate
170
+ ? ((this.resampler = this.bypassResampler), (this.ratioWeight = 1))
171
+ : (this.fromSampleRate < this.toSampleRate
172
+ ? ((this.lastWeight = 1), (this.resampler = this.compileLinearInterpolation))
173
+ : ((this.tailExists = !1),
174
+ (this.lastWeight = 0),
175
+ (this.resampler = this.compileMultiTap)),
176
+ (this.ratioWeight = this.fromSampleRate / this.toSampleRate));
177
+ }),
178
+ (l.prototype.compileLinearInterpolation = function (t) {
179
+ var e = t.length;
180
+ this.initializeBuffers(e);
181
+ var r,
182
+ n,
183
+ i = this.outputBufferSize,
184
+ o = this.ratioWeight,
185
+ a = this.lastWeight,
186
+ s = 0,
187
+ f = 0,
188
+ u = 0,
189
+ l = this.outputBuffer;
190
+ if (e % this.channels == 0) {
191
+ if (e > 0) {
192
+ for (; a < 1; a += o)
193
+ for (s = 1 - (f = a % 1), r = 0; r < this.channels; ++r)
194
+ l[u++] = this.lastOutput[r] * s + t[r] * f;
195
+ for (a--, e -= this.channels, n = Math.floor(a) * this.channels; u < i && n < e; ) {
196
+ for (s = 1 - (f = a % 1), r = 0; r < this.channels; ++r)
197
+ l[u++] = t[n + r] * s + t[n + this.channels + r] * f;
198
+ (a += o), (n = Math.floor(a) * this.channels);
199
+ }
200
+ for (r = 0; r < this.channels; ++r) this.lastOutput[r] = t[n++];
201
+ return (this.lastWeight = a % 1), this.bufferSlice(u);
202
+ }
203
+ return this.noReturn ? 0 : [];
204
+ }
205
+ throw new Error('Buffer was of incorrect sample length.');
206
+ }),
207
+ (l.prototype.compileMultiTap = function (t) {
208
+ var e = [],
209
+ r = t.length;
210
+ this.initializeBuffers(r);
211
+ var n = this.outputBufferSize;
212
+ if (r % this.channels == 0) {
213
+ if (r > 0) {
214
+ for (var i = this.ratioWeight, o = 0, a = 0; a < this.channels; ++a) e[a] = 0;
215
+ var s = 0,
216
+ f = 0,
217
+ u = !this.tailExists;
218
+ this.tailExists = !1;
219
+ var l = this.outputBuffer,
220
+ h = 0,
221
+ c = 0;
222
+ do {
223
+ if (u) for (o = i, a = 0; a < this.channels; ++a) e[a] = 0;
224
+ else {
225
+ for (o = this.lastWeight, a = 0; a < this.channels; ++a) e[a] += this.lastOutput[a];
226
+ u = !0;
227
+ }
228
+ for (; o > 0 && s < r; ) {
229
+ if (!(o >= (f = 1 + s - c))) {
230
+ for (a = 0; a < this.channels; ++a) e[a] += t[s + a] * o;
231
+ (c += o), (o = 0);
232
+ break;
233
+ }
234
+ for (a = 0; a < this.channels; ++a) e[a] += t[s++] * f;
235
+ (c = s), (o -= f);
236
+ }
237
+ if (0 != o) {
238
+ for (this.lastWeight = o, a = 0; a < this.channels; ++a) this.lastOutput[a] = e[a];
239
+ this.tailExists = !0;
240
+ break;
241
+ }
242
+ for (a = 0; a < this.channels; ++a) l[h++] = e[a] / i;
243
+ } while (s < r && h < n);
244
+ return this.bufferSlice(h);
245
+ }
246
+ return this.noReturn ? 0 : [];
247
+ }
248
+ throw new Error('Buffer was of incorrect sample length.');
249
+ }),
250
+ (l.prototype.bypassResampler = function (t) {
251
+ return this.noReturn ? ((this.outputBuffer = t), t.length) : t;
252
+ }),
253
+ (l.prototype.bufferSlice = function (t) {
254
+ if (this.noReturn) return t;
255
+ try {
256
+ return this.outputBuffer.subarray(0, t);
257
+ } catch (e) {
258
+ try {
259
+ return (this.outputBuffer.length = t), this.outputBuffer;
260
+ } catch (e) {
261
+ return this.outputBuffer.slice(0, t);
262
+ }
263
+ }
264
+ }),
265
+ (l.prototype.initializeBuffers = function (t) {
266
+ this.outputBufferSize = Math.ceil((t * this.toSampleRate) / this.fromSampleRate);
267
+ try {
268
+ (this.outputBuffer = new Float32Array(this.outputBufferSize)),
269
+ (this.lastOutput = new Float32Array(this.channels));
270
+ } catch (t) {
271
+ (this.outputBuffer = []), (this.lastOutput = []);
272
+ }
273
+ });
274
+ var h = (function (e) {
275
+ !(function (t, e) {
276
+ if ('function' != typeof e && null !== e)
277
+ throw new TypeError('Super expression must either be null or a function');
278
+ (t.prototype = Object.create(e && e.prototype, {
279
+ constructor: { value: t, writable: !0, configurable: !0 },
280
+ })),
281
+ Object.defineProperty(t, 'prototype', { writable: !1 }),
282
+ e && r(t, e);
283
+ })(h, e);
284
+ var n,
285
+ i,
286
+ o,
287
+ u = s(h);
288
+ function h() {
289
+ var t;
290
+ !(function (t, e) {
291
+ if (!(t instanceof e)) throw new TypeError('Cannot call a class as a function');
292
+ })(this, h);
293
+ var e = a((t = u.call(this)));
294
+ return (
295
+ (t.port.onmessage = function (t) {
296
+ var r = t.data,
297
+ n = r.type,
298
+ i = r.data;
299
+ if ((console.log('type', n), 'init' === n)) {
300
+ var o = i.frameSize,
301
+ a = i.toSampleRate,
302
+ s = i.arrayBufferType,
303
+ f = i.fromSampleRate;
304
+ return (
305
+ (e.frameSize = o * Math.floor(f / a)),
306
+ (e.resampler = new l(f, a, 1)),
307
+ (e.frameBuffer = []),
308
+ void (e.arrayBufferType = s)
309
+ );
310
+ }
311
+ 'stop' === n &&
312
+ (e.port.postMessage({
313
+ frameBuffer: e.transData(e.frameBuffer),
314
+ isLastFrame: !0,
315
+ }),
316
+ (e.frameBuffer = []));
317
+ }),
318
+ t
319
+ );
320
+ }
321
+ return (
322
+ (n = h),
323
+ (i = [
324
+ {
325
+ key: 'process',
326
+ value: function (t) {
327
+ var e,
328
+ r = t[0][0];
329
+ if (!r) return true;
330
+ return this.frameSize
331
+ ? ((e = this.frameBuffer).push.apply(e, fn(r)),
332
+ this.frameBuffer.length >= this.frameSize &&
333
+ (this.port.postMessage({
334
+ frameBuffer: this.transData(this.frameBuffer),
335
+ isLastFrame: !1,
336
+ }),
337
+ (this.frameBuffer = [])),
338
+ !0)
339
+ : (r &&
340
+ this.port.postMessage({
341
+ frameBuffer: this.transData(r),
342
+ isLastFrame: !1,
343
+ }),
344
+ !0);
345
+ },
346
+ },
347
+ {
348
+ key: 'transData',
349
+ value: function (t) {
350
+ return (
351
+ 'short16' === this.arrayBufferType &&
352
+ (t = (function (t) {
353
+ for (
354
+ var e = new ArrayBuffer(2 * t.length), r = new DataView(e), n = 0, i = 0;
355
+ i < t.length;
356
+ i += 1, n += 2
357
+ ) {
358
+ var o = Math.max(-1, Math.min(1, t[i]));
359
+ r.setInt16(n, o < 0 ? 32768 * o : 32767 * o, !0);
360
+ }
361
+ return r.buffer;
362
+ })((t = this.resampler.resampler(t)))),
363
+ t
364
+ );
365
+ },
366
+ },
367
+ ]) && t(n.prototype, i),
368
+ o && t(n, o),
369
+ Object.defineProperty(n, 'prototype', { writable: !1 }),
370
+ h
371
+ );
372
+ })(o(AudioWorkletProcessor));
373
+ registerProcessor('processor-worklet', h);
374
+ })();
375
+ `;
376
+ export {
377
+ n as default
378
+ };
379
+ //# sourceMappingURL=processor.worklet.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processor.worklet.es.js","sources":["../../../../../src/utils/xunFeiVoice/RecorderManager/processorSource/processor.worklet.js?raw"],"sourcesContent":["export default \"!(function () {\\n 'use strict';\\n function t(t, e) {\\n for (var r = 0; r < e.length; r++) {\\n var n = e[r];\\n (n.enumerable = n.enumerable || !1),\\n (n.configurable = !0),\\n 'value' in n && (n.writable = !0),\\n Object.defineProperty(\\n t,\\n ((i = n.key),\\n (o = void 0),\\n 'symbol' ==\\n typeof (o = (function (t, e) {\\n if ('object' != typeof t || null === t) return t;\\n var r = t[Symbol.toPrimitive];\\n if (void 0 !== r) {\\n var n = r.call(t, e || 'default');\\n if ('object' != typeof n) return n;\\n throw new TypeError('@@toPrimitive must return a primitive value.');\\n }\\n return ('string' === e ? String : Number)(t);\\n })(i, 'string'))\\n ? o\\n : String(o)),\\n n,\\n );\\n }\\n var i, o;\\n }\\n function e(t) {\\n return (\\n (e = Object.setPrototypeOf\\n ? Object.getPrototypeOf.bind()\\n : function (t) {\\n return t.__proto__ || Object.getPrototypeOf(t);\\n }),\\n e(t)\\n );\\n }\\n function r(t, e) {\\n return (\\n (r = Object.setPrototypeOf\\n ? Object.setPrototypeOf.bind()\\n : function (t, e) {\\n return (t.__proto__ = e), t;\\n }),\\n r(t, e)\\n );\\n }\\n function n() {\\n if ('undefined' == typeof Reflect || !Reflect.construct) return !1;\\n if (Reflect.construct.sham) return !1;\\n if ('function' == typeof Proxy) return !0;\\n try {\\n return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})), !0;\\n } catch (t) {\\n return !1;\\n }\\n }\\n function i(t, e, o) {\\n return (\\n (i = n()\\n ? Reflect.construct.bind()\\n : function (t, e, n) {\\n var i = [null];\\n i.push.apply(i, e);\\n var o = new (Function.bind.apply(t, i))();\\n return n && r(o, n.prototype), o;\\n }),\\n i.apply(null, arguments)\\n );\\n }\\n function o(t) {\\n var n = 'function' == typeof Map ? new Map() : void 0;\\n return (\\n (o = function (t) {\\n if (null === t || ((o = t), -1 === Function.toString.call(o).indexOf('[native code]')))\\n return t;\\n var o;\\n if ('function' != typeof t)\\n throw new TypeError('Super expression must either be null or a function');\\n if (void 0 !== n) {\\n if (n.has(t)) return n.get(t);\\n n.set(t, a);\\n }\\n function a() {\\n return i(t, arguments, e(this).constructor);\\n }\\n return (\\n (a.prototype = Object.create(t.prototype, {\\n constructor: {\\n value: a,\\n enumerable: !1,\\n writable: !0,\\n configurable: !0,\\n },\\n })),\\n r(a, t)\\n );\\n }),\\n o(t)\\n );\\n }\\n function a(t) {\\n if (void 0 === t)\\n throw new ReferenceError(\\\"this hasn't been initialised - super() hasn't been called\\\");\\n return t;\\n }\\n function s(t) {\\n var r = n();\\n return function () {\\n var n,\\n i = e(t);\\n if (r) {\\n var o = e(this).constructor;\\n n = Reflect.construct(i, arguments, o);\\n } else n = i.apply(this, arguments);\\n return (function (t, e) {\\n if (e && ('object' == typeof e || 'function' == typeof e)) return e;\\n if (void 0 !== e)\\n throw new TypeError('Derived constructors may only return object or undefined');\\n return a(t);\\n })(this, n);\\n };\\n }\\n function fn(t) {\\n return (\\n (function (t) {\\n if (Array.isArray(t)) return u(t);\\n })(t) ||\\n (function (t) {\\n if (\\n t !== undefined &&\\n (('undefined' != typeof Symbol && null != t[Symbol.iterator]) || null != t['@@iterator'])\\n )\\n return Array.from(t);\\n })(t) ||\\n (function (t, e) {\\n if (!t) return;\\n if ('string' == typeof t) return u(t, e);\\n var r = Object.prototype.toString.call(t).slice(8, -1);\\n 'Object' === r && t.constructor && (r = t.constructor.name);\\n if ('Map' === r || 'Set' === r) return Array.from(t);\\n if ('Arguments' === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)) return u(t, e);\\n })(t) ||\\n (function () {\\n throw new TypeError(\\n 'Invalid attempt to spread non-iterable instance.\\\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',\\n );\\n })()\\n );\\n }\\n function u(t, e) {\\n (null == e || e > t.length) && (e = t.length);\\n for (var r = 0, n = new Array(e); r < e; r++) n[r] = t[r];\\n return n;\\n }\\n function l(t, e, r, n) {\\n (this.fromSampleRate = t),\\n (this.toSampleRate = e),\\n (this.channels = 0 | r),\\n (this.noReturn = !!n),\\n this.initialize();\\n }\\n (l.prototype.initialize = function () {\\n if (!(this.fromSampleRate > 0 && this.toSampleRate > 0 && this.channels > 0))\\n throw new Error('Invalid settings specified for the resampler.');\\n this.fromSampleRate == this.toSampleRate\\n ? ((this.resampler = this.bypassResampler), (this.ratioWeight = 1))\\n : (this.fromSampleRate < this.toSampleRate\\n ? ((this.lastWeight = 1), (this.resampler = this.compileLinearInterpolation))\\n : ((this.tailExists = !1),\\n (this.lastWeight = 0),\\n (this.resampler = this.compileMultiTap)),\\n (this.ratioWeight = this.fromSampleRate / this.toSampleRate));\\n }),\\n (l.prototype.compileLinearInterpolation = function (t) {\\n var e = t.length;\\n this.initializeBuffers(e);\\n var r,\\n n,\\n i = this.outputBufferSize,\\n o = this.ratioWeight,\\n a = this.lastWeight,\\n s = 0,\\n f = 0,\\n u = 0,\\n l = this.outputBuffer;\\n if (e % this.channels == 0) {\\n if (e > 0) {\\n for (; a < 1; a += o)\\n for (s = 1 - (f = a % 1), r = 0; r < this.channels; ++r)\\n l[u++] = this.lastOutput[r] * s + t[r] * f;\\n for (a--, e -= this.channels, n = Math.floor(a) * this.channels; u < i && n < e; ) {\\n for (s = 1 - (f = a % 1), r = 0; r < this.channels; ++r)\\n l[u++] = t[n + r] * s + t[n + this.channels + r] * f;\\n (a += o), (n = Math.floor(a) * this.channels);\\n }\\n for (r = 0; r < this.channels; ++r) this.lastOutput[r] = t[n++];\\n return (this.lastWeight = a % 1), this.bufferSlice(u);\\n }\\n return this.noReturn ? 0 : [];\\n }\\n throw new Error('Buffer was of incorrect sample length.');\\n }),\\n (l.prototype.compileMultiTap = function (t) {\\n var e = [],\\n r = t.length;\\n this.initializeBuffers(r);\\n var n = this.outputBufferSize;\\n if (r % this.channels == 0) {\\n if (r > 0) {\\n for (var i = this.ratioWeight, o = 0, a = 0; a < this.channels; ++a) e[a] = 0;\\n var s = 0,\\n f = 0,\\n u = !this.tailExists;\\n this.tailExists = !1;\\n var l = this.outputBuffer,\\n h = 0,\\n c = 0;\\n do {\\n if (u) for (o = i, a = 0; a < this.channels; ++a) e[a] = 0;\\n else {\\n for (o = this.lastWeight, a = 0; a < this.channels; ++a) e[a] += this.lastOutput[a];\\n u = !0;\\n }\\n for (; o > 0 && s < r; ) {\\n if (!(o >= (f = 1 + s - c))) {\\n for (a = 0; a < this.channels; ++a) e[a] += t[s + a] * o;\\n (c += o), (o = 0);\\n break;\\n }\\n for (a = 0; a < this.channels; ++a) e[a] += t[s++] * f;\\n (c = s), (o -= f);\\n }\\n if (0 != o) {\\n for (this.lastWeight = o, a = 0; a < this.channels; ++a) this.lastOutput[a] = e[a];\\n this.tailExists = !0;\\n break;\\n }\\n for (a = 0; a < this.channels; ++a) l[h++] = e[a] / i;\\n } while (s < r && h < n);\\n return this.bufferSlice(h);\\n }\\n return this.noReturn ? 0 : [];\\n }\\n throw new Error('Buffer was of incorrect sample length.');\\n }),\\n (l.prototype.bypassResampler = function (t) {\\n return this.noReturn ? ((this.outputBuffer = t), t.length) : t;\\n }),\\n (l.prototype.bufferSlice = function (t) {\\n if (this.noReturn) return t;\\n try {\\n return this.outputBuffer.subarray(0, t);\\n } catch (e) {\\n try {\\n return (this.outputBuffer.length = t), this.outputBuffer;\\n } catch (e) {\\n return this.outputBuffer.slice(0, t);\\n }\\n }\\n }),\\n (l.prototype.initializeBuffers = function (t) {\\n this.outputBufferSize = Math.ceil((t * this.toSampleRate) / this.fromSampleRate);\\n try {\\n (this.outputBuffer = new Float32Array(this.outputBufferSize)),\\n (this.lastOutput = new Float32Array(this.channels));\\n } catch (t) {\\n (this.outputBuffer = []), (this.lastOutput = []);\\n }\\n });\\n var h = (function (e) {\\n !(function (t, e) {\\n if ('function' != typeof e && null !== e)\\n throw new TypeError('Super expression must either be null or a function');\\n (t.prototype = Object.create(e && e.prototype, {\\n constructor: { value: t, writable: !0, configurable: !0 },\\n })),\\n Object.defineProperty(t, 'prototype', { writable: !1 }),\\n e && r(t, e);\\n })(h, e);\\n var n,\\n i,\\n o,\\n u = s(h);\\n function h() {\\n var t;\\n !(function (t, e) {\\n if (!(t instanceof e)) throw new TypeError('Cannot call a class as a function');\\n })(this, h);\\n var e = a((t = u.call(this)));\\n return (\\n (t.port.onmessage = function (t) {\\n var r = t.data,\\n n = r.type,\\n i = r.data;\\n if ((console.log('type', n), 'init' === n)) {\\n var o = i.frameSize,\\n a = i.toSampleRate,\\n s = i.arrayBufferType,\\n f = i.fromSampleRate;\\n return (\\n (e.frameSize = o * Math.floor(f / a)),\\n (e.resampler = new l(f, a, 1)),\\n (e.frameBuffer = []),\\n void (e.arrayBufferType = s)\\n );\\n }\\n 'stop' === n &&\\n (e.port.postMessage({\\n frameBuffer: e.transData(e.frameBuffer),\\n isLastFrame: !0,\\n }),\\n (e.frameBuffer = []));\\n }),\\n t\\n );\\n }\\n return (\\n (n = h),\\n (i = [\\n {\\n key: 'process',\\n value: function (t) {\\n var e,\\n r = t[0][0];\\n if (!r) return true;\\n return this.frameSize\\n ? ((e = this.frameBuffer).push.apply(e, fn(r)),\\n this.frameBuffer.length >= this.frameSize &&\\n (this.port.postMessage({\\n frameBuffer: this.transData(this.frameBuffer),\\n isLastFrame: !1,\\n }),\\n (this.frameBuffer = [])),\\n !0)\\n : (r &&\\n this.port.postMessage({\\n frameBuffer: this.transData(r),\\n isLastFrame: !1,\\n }),\\n !0);\\n },\\n },\\n {\\n key: 'transData',\\n value: function (t) {\\n return (\\n 'short16' === this.arrayBufferType &&\\n (t = (function (t) {\\n for (\\n var e = new ArrayBuffer(2 * t.length), r = new DataView(e), n = 0, i = 0;\\n i < t.length;\\n i += 1, n += 2\\n ) {\\n var o = Math.max(-1, Math.min(1, t[i]));\\n r.setInt16(n, o < 0 ? 32768 * o : 32767 * o, !0);\\n }\\n return r.buffer;\\n })((t = this.resampler.resampler(t)))),\\n t\\n );\\n },\\n },\\n ]) && t(n.prototype, i),\\n o && t(n, o),\\n Object.defineProperty(n, 'prototype', { writable: !1 }),\\n h\\n );\\n })(o(AudioWorkletProcessor));\\n registerProcessor('processor-worklet', h);\\n})();\\n\""],"names":["workletJsString"],"mappings":"AAAA,MAAeA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;"}
@@ -1,28 +1,21 @@
1
- import { OnRecordProcessParams, RecorderManagerClass } from './types';
1
+ import { RecorderManager } from './RecorderManager';
2
+ import { OnMessageInfo, RecordFrameInfo } from './types';
2
3
 
4
+ type errorType = 'socketConnect' | 'message' | 'record';
3
5
  export interface XunFeiStreamVoiceManagerConfig {
4
6
  onError: (errInfo: {
5
- type: 'socketConnect' | 'message';
7
+ type: errorType;
6
8
  message: string;
7
9
  }) => void;
8
10
  /** ws 收到消息的回调
9
11
  * @param info.message 消息内容
10
12
  * @param info.isLatest 是否是最后一条消息。 isLatest 为 true 时, message 为完整的语音识别结果。
11
13
  */
12
- onMessage: (info: {
13
- message: string;
14
- isLatest?: boolean;
15
- }) => void;
14
+ onMessage: (info: OnMessageInfo) => void;
16
15
  /** webSocket 关闭的回调。
17
16
  * 每次录音都会新建一个 webSocket 连接。录音结束后关闭 webSocket
18
17
  */
19
18
  onWsClose: () => void;
20
- /** 获取讯飞提供的 processor.worker.js 和 processor.worklet.js 的路径。
21
- * 填写这两个文件的父路径就好。 如 a/b/processor.worker.js 则填写 a/b。
22
- * 可以是oss地址,也可以是项目中的文件路径,智能通过url请求,能得到上面两个js文件即可。
23
- * 目前已上传到 oss://{assetsBaseUrl}/announcement/easyvadmin/xun-fei-voice/ 目录下。
24
- */
25
- processWorkJsPath: string;
26
19
  /**
27
20
  * 获取链接讯飞语音识别地址的 url
28
21
  * @returns websocket url。详情查看讯飞文档里的鉴权方法:https://www.xfyun.cn/doc/asr/voicedictation/API.html#%E6%8E%A5%E5%8F%A3%E8%B0%83%E7%94%A8%E6%B5%81%E7%A8%8B
@@ -37,20 +30,28 @@ export declare class XunFeiStreamVoiceManager {
37
30
  config: XunFeiStreamVoiceManagerConfig;
38
31
  wsInstance: WebSocket | null;
39
32
  status: SocketStatus;
40
- recorder: RecorderManagerClass | null;
33
+ recorder: RecorderManager | null;
41
34
  isDestroy: boolean;
42
35
  resultText: string;
43
36
  resultTextTemp: string;
37
+ continueRecord: boolean;
38
+ startTimeStamp: number;
39
+ recordStatus: 'start' | 'stop';
40
+ readyToSend: boolean;
44
41
  constructor(config: XunFeiStreamVoiceManagerConfig);
45
42
  renderResult(resultData: string): void;
46
43
  setConfig(newConfig: XunFeiStreamVoiceManagerConfig): void;
47
- recordConfigSend(): void;
44
+ sendMessage(message: string): void;
45
+ recordConfigSend(): Promise<void>;
48
46
  startNewSocket(): void;
49
- recordProcess({ isLastFrame, frameBuffer }: OnRecordProcessParams): void;
47
+ recordProcess({ isLastFrame, frameBuffer }: RecordFrameInfo): void;
50
48
  initializeRecorder(): void;
51
49
  changeBtnStatus(status: SocketStatus): void;
52
50
  startRecord(): void;
53
51
  stopRecord(): Promise<void>;
52
+ /** 开启持续监听 */
53
+ startContinueRecord(): void;
54
+ stopContinueRecord(): void;
54
55
  destroy(): void;
55
56
  }
56
57
  export {};
@@ -0,0 +1,177 @@
1
+ var m = Object.defineProperty;
2
+ var p = (i, t, e) => t in i ? m(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
+ var o = (i, t, e) => p(i, typeof t != "symbol" ? t + "" : t, e);
4
+ import d from "../../node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.es.js";
5
+ import { toBase64 as S } from "./utils.es.js";
6
+ import { RecorderManager as T } from "./RecorderManager/RecorderManager.es.js";
7
+ let l = 0;
8
+ const w = "93b73e33", y = "ZGJhMzQ5ZTJlMDgyYmE1ZTFlZDlmYjg0", x = "fe43de7a071e3a32ec03c6f09fe7bedf";
9
+ function I() {
10
+ const i = "wss://iat-api.xfyun.cn/v2/iat", t = "iat-api.xfyun.cn", e = x, s = y, r = (/* @__PURE__ */ new Date()).toUTCString(), n = "hmac-sha256", a = "host date request-line", h = `host: ${t}
11
+ date: ${r}
12
+ GET /v2/iat HTTP/1.1`, c = d.HmacSHA256(h, s), u = d.enc.Base64.stringify(c), g = `api_key="${e}", algorithm="${n}", headers="${a}", signature="${u}"`, f = window.btoa(g);
13
+ return `${i}?authorization=${f}&date=${r}&host=${t}`;
14
+ }
15
+ class C {
16
+ constructor(t) {
17
+ o(this, "wsInstance", null);
18
+ o(this, "status", "UNDEFINED");
19
+ o(this, "recorder", null);
20
+ o(this, "isDestroy", !1);
21
+ o(this, "resultText", "");
22
+ o(this, "resultTextTemp", "");
23
+ o(this, "continueRecord", !1);
24
+ o(this, "startTimeStamp", 0);
25
+ o(this, "recordStatus", "stop");
26
+ o(this, "readyToSend", !1);
27
+ this.config = t, this.initializeRecorder();
28
+ }
29
+ renderResult(t) {
30
+ var s, r;
31
+ const e = JSON.parse(t);
32
+ if (e.data && e.data.result) {
33
+ const n = e.data.result;
34
+ let a = "";
35
+ const h = n.ws;
36
+ for (let c = 0; c < h.length; c++)
37
+ a = a + h[c].cw[0].w;
38
+ n.pgs ? (n.pgs === "apd" && (this.resultText = this.resultTextTemp), this.resultTextTemp = this.resultText + a) : this.resultText = this.resultText + a, console.log("%c 🐶 dog ==== renderResult:", "color: green; font-size: 16px;", {
39
+ str: a,
40
+ resultTextTemp: this.resultTextTemp,
41
+ resultText: this.resultText
42
+ });
43
+ }
44
+ if (e.code === 0 && e.data.status === 2) {
45
+ this.config.onMessage({
46
+ message: this.resultText,
47
+ isLatest: !0,
48
+ tempMessage: this.resultTextTemp
49
+ }), (s = this.wsInstance) == null || s.close();
50
+ return;
51
+ }
52
+ e.code === 0 && e.data.status === 1 && this.config.onMessage({
53
+ message: this.resultText,
54
+ isLatest: !1,
55
+ tempMessage: this.resultTextTemp
56
+ }), e.code !== 0 && ((r = this.wsInstance) == null || r.close(), this.config.onError({ type: "message", message: t }));
57
+ }
58
+ setConfig(t) {
59
+ this.config = {
60
+ ...this.config,
61
+ ...t
62
+ }, this.initializeRecorder();
63
+ }
64
+ sendMessage(t) {
65
+ var e;
66
+ ((e = this.wsInstance) == null ? void 0 : e.readyState) === WebSocket.OPEN && this.readyToSend && this.wsInstance.send(t);
67
+ }
68
+ async recordConfigSend() {
69
+ var t;
70
+ if (!this.isDestroy)
71
+ try {
72
+ await ((t = this.recorder) == null ? void 0 : t.start({
73
+ sampleRate: 16e3,
74
+ frameSize: 1280
75
+ }));
76
+ const e = {
77
+ common: {
78
+ app_id: w
79
+ },
80
+ business: {
81
+ language: "zh_cn",
82
+ domain: "iat",
83
+ accent: "mandarin",
84
+ vad_eos: 5e3,
85
+ dwa: "wpgs"
86
+ },
87
+ data: {
88
+ status: 0,
89
+ format: "audio/L16;rate=16000",
90
+ encoding: "raw"
91
+ }
92
+ };
93
+ this.readyToSend = !0, this.sendMessage(JSON.stringify(e));
94
+ } catch (e) {
95
+ console.error("record error:", e), this.config.onError({ type: "record", message: "录音失败, 请检查权限!" });
96
+ }
97
+ }
98
+ startNewSocket() {
99
+ var e, s;
100
+ console.log(
101
+ "%c ❤️ love ==== start new socket ",
102
+ "color: red; font-size: 16px;",
103
+ l,
104
+ (/* @__PURE__ */ new Date()).toUTCString()
105
+ ), l++;
106
+ const t = ((s = (e = this.config).getWebSocketUrl) == null ? void 0 : s.call(e)) || I();
107
+ if ("WebSocket" in window)
108
+ this.wsInstance = new WebSocket(t);
109
+ else {
110
+ this.config.onError({ type: "socketConnect", message: "浏览器不支持 WebSocket" });
111
+ return;
112
+ }
113
+ this.wsInstance.onmessage = (r) => {
114
+ this.renderResult(r.data);
115
+ }, this.wsInstance.onerror = (r) => {
116
+ console.error("socket error:", r), this.changeBtnStatus("CLOSED");
117
+ }, this.wsInstance.onclose = async () => {
118
+ var r, n;
119
+ this.changeBtnStatus("CLOSED"), this.config.onWsClose(), (r = this.recorder) == null || r.stop(), this.continueRecord && (this.readyToSend = !1, await ((n = this.recorder) == null ? void 0 : n.close()), this.startRecord());
120
+ }, this.wsInstance.onopen = () => {
121
+ this.changeBtnStatus("OPEN"), this.recordConfigSend();
122
+ };
123
+ }
124
+ recordProcess({ isLastFrame: t, frameBuffer: e }) {
125
+ this.isDestroy || this.wsInstance && (this.wsInstance.readyState === this.wsInstance.OPEN && this.sendMessage(
126
+ JSON.stringify({
127
+ data: {
128
+ status: t ? 2 : 1,
129
+ format: "audio/L16;rate=16000",
130
+ encoding: "raw",
131
+ audio: S(e)
132
+ }
133
+ })
134
+ ), t && (this.readyToSend = !1, this.changeBtnStatus("CLOSING")));
135
+ }
136
+ initializeRecorder() {
137
+ this.recorder = new T(), this.recorder && (this.recorder.onFrameRecorded = (t) => {
138
+ this.recordProcess(t);
139
+ }, this.recorder.onStop = (t) => {
140
+ }, this.recorder.onStart = () => {
141
+ console.log("%c ❤️ love ==== recorder onStart:", "color: red; font-size: 16px;"), this.changeBtnStatus("OPEN");
142
+ });
143
+ }
144
+ changeBtnStatus(t) {
145
+ this.status = t;
146
+ }
147
+ startRecord() {
148
+ this.isDestroy || (this.startTimeStamp = Date.now(), this.resultText = "", this.resultTextTemp = "", this.startNewSocket());
149
+ }
150
+ async stopRecord() {
151
+ var t;
152
+ console.log("stop record ====", Date.now() - this.startTimeStamp), Date.now() - this.startTimeStamp < 500 ? setTimeout(() => {
153
+ var e;
154
+ (e = this.recorder) == null || e.stop();
155
+ }, 100) : (t = this.recorder) == null || t.stop(), setTimeout(() => {
156
+ var e, s;
157
+ ((e = this.wsInstance) == null ? void 0 : e.readyState) === WebSocket.OPEN && ((s = this.wsInstance) == null || s.close());
158
+ }, 5e3);
159
+ }
160
+ /** 开启持续监听 */
161
+ startContinueRecord() {
162
+ this.continueRecord = !0, this.startRecord();
163
+ }
164
+ stopContinueRecord() {
165
+ this.continueRecord = !1, this.stopRecord();
166
+ }
167
+ destroy() {
168
+ this.isDestroy = !0, setTimeout(() => {
169
+ var t, e, s;
170
+ ((t = this.wsInstance) == null ? void 0 : t.readyState) === WebSocket.OPEN && ((e = this.wsInstance) == null || e.close()), (s = this.recorder) == null || s.stop();
171
+ }, 1e3);
172
+ }
173
+ }
174
+ export {
175
+ C as XunFeiStreamVoiceManager
176
+ };
177
+ //# sourceMappingURL=XunFeiStreamVoiceManager.es.js.map