@easyv/biz-components 0.0.15 → 0.0.17
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/utils/xunFeiVoice/RecorderManager/RecorderManager.d.ts +0 -5
- package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager.es.js +25 -28
- package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager.es.js.map +1 -1
- package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worker.es.js +233 -0
- package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worker.es.js.map +1 -0
- package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worklet.d.ts +0 -0
- package/dist/utils/xunFeiVoice/RecorderManager/processorSource/processor.worklet.es.js.map +1 -0
- package/dist/utils/xunFeiVoice/XunFeiStreamVoiceManager.d.ts +2 -11
- package/dist/utils/xunFeiVoice/XunFeiStreamVoiceManager.es.js +11 -3
- package/dist/utils/xunFeiVoice/XunFeiStreamVoiceManager.es.js.map +1 -1
- package/dist/utils/xunFeiVoice/index.d.ts +1 -0
- package/dist/utils/xunFeiVoice/types.d.ts +9 -0
- package/package.json +1 -1
- package/dist/utils/xunFeiVoice/RecorderManager/processor.worklet.es.js.map +0 -1
- /package/dist/utils/xunFeiVoice/RecorderManager/{processor.worklet.d.ts → processorSource/processor.worker.d.ts} +0 -0
- /package/dist/utils/xunFeiVoice/RecorderManager/{processor.worklet.es.js → processorSource/processor.worklet.es.js} +0 -0
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
* 录音管理器
|
|
3
3
|
*/
|
|
4
4
|
export class RecorderManager {
|
|
5
|
-
/**
|
|
6
|
-
* @param {string} processorPath 音频处理器路径
|
|
7
|
-
*/
|
|
8
|
-
constructor(processorPath: string);
|
|
9
5
|
/** @type {Array<ArrayBuffer>} */
|
|
10
6
|
audioBuffers: Array<ArrayBuffer>;
|
|
11
7
|
/** @type {(params: RecordFrameInfo) => void} */
|
|
@@ -13,7 +9,6 @@ export class RecorderManager {
|
|
|
13
9
|
onStart: () => void;
|
|
14
10
|
/** @type {(data: Array<ArrayBuffer>) => void} */
|
|
15
11
|
onStop: (data: Array<ArrayBuffer>) => void;
|
|
16
|
-
processorPath: string;
|
|
17
12
|
/**
|
|
18
13
|
* 开始录音
|
|
19
14
|
* @param {{
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var c = (r, e, t) =>
|
|
4
|
-
import
|
|
5
|
-
import y from "./processor.
|
|
1
|
+
var S = Object.defineProperty;
|
|
2
|
+
var g = (r, e, t) => e in r ? S(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var c = (r, e, t) => g(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import k from "../../../node_modules/.pnpm/co-web-worker@1.0.1/node_modules/co-web-worker/index.es.js";
|
|
5
|
+
import y from "./processorSource/processor.worker.es.js";
|
|
6
|
+
import R from "./processorSource/processor.worklet.es.js";
|
|
6
7
|
const { AudioWorkletNode: h } = window, u = !!h;
|
|
7
|
-
async function
|
|
8
|
+
async function M() {
|
|
8
9
|
const r = navigator.mediaDevices ?? {};
|
|
9
10
|
if (typeof r.getUserMedia == "function")
|
|
10
11
|
return r.getUserMedia({ audio: !0, video: !1 });
|
|
@@ -14,20 +15,17 @@ async function R() {
|
|
|
14
15
|
});
|
|
15
16
|
throw new Error("浏览器不支持录音!");
|
|
16
17
|
}
|
|
17
|
-
const
|
|
18
|
-
const r = new Blob([
|
|
19
|
-
return URL.createObjectURL(
|
|
18
|
+
const w = (r) => {
|
|
19
|
+
const e = r === "worker" ? y : R, t = new Blob([e], { type: "application/javascript" });
|
|
20
|
+
return URL.createObjectURL(t);
|
|
20
21
|
};
|
|
21
|
-
async function
|
|
22
|
-
return u ? (await r.audioWorklet.addModule(
|
|
22
|
+
async function A(r) {
|
|
23
|
+
return u ? (await r.audioWorklet.addModule(w("worklet")), new h(r, "processor-worklet")) : { port: new k(w("worker")) };
|
|
23
24
|
}
|
|
24
25
|
const d = () => {
|
|
25
26
|
};
|
|
26
|
-
class
|
|
27
|
-
|
|
28
|
-
* @param {string} processorPath 音频处理器路径
|
|
29
|
-
*/
|
|
30
|
-
constructor(e) {
|
|
27
|
+
class v {
|
|
28
|
+
constructor() {
|
|
31
29
|
/** @type {Array<ArrayBuffer>} */
|
|
32
30
|
c(this, "audioBuffers", []);
|
|
33
31
|
/** @type {(params: RecordFrameInfo) => void} */
|
|
@@ -35,7 +33,6 @@ class C {
|
|
|
35
33
|
c(this, "onStart", d);
|
|
36
34
|
/** @type {(data: Array<ArrayBuffer>) => void} */
|
|
37
35
|
c(this, "onStop", d);
|
|
38
|
-
this.processorPath = e;
|
|
39
36
|
}
|
|
40
37
|
/**
|
|
41
38
|
* 开始录音
|
|
@@ -49,8 +46,8 @@ class C {
|
|
|
49
46
|
var t, s;
|
|
50
47
|
try {
|
|
51
48
|
this.audioBuffers = [];
|
|
52
|
-
const o = await
|
|
53
|
-
this.audioWorkletNode = await
|
|
49
|
+
const o = await M(), i = this.createAudioContext(o, e.sampleRate);
|
|
50
|
+
this.audioWorkletNode = await A(i), this.setupAudioProcessing(i, o, this.audioWorkletNode, e), (t = this.audioContext) == null || t.resume(), (s = this.onStart) == null || s.call(this);
|
|
54
51
|
} catch (o) {
|
|
55
52
|
throw console.error("Failed to start recording:", o), o;
|
|
56
53
|
}
|
|
@@ -75,8 +72,8 @@ class C {
|
|
|
75
72
|
* @private
|
|
76
73
|
*/
|
|
77
74
|
setupAudioProcessing(e, t, s, o) {
|
|
78
|
-
const
|
|
79
|
-
if (this.mediaSource =
|
|
75
|
+
const i = e.createMediaStreamSource(t);
|
|
76
|
+
if (this.mediaSource = i, s.port.postMessage({
|
|
80
77
|
type: "init",
|
|
81
78
|
data: {
|
|
82
79
|
frameSize: o.frameSize,
|
|
@@ -86,18 +83,18 @@ class C {
|
|
|
86
83
|
}
|
|
87
84
|
}), s.port.onmessage = (n) => {
|
|
88
85
|
var p, f, l, m;
|
|
89
|
-
const { data:
|
|
90
|
-
o.frameSize && this.onFrameRecorded && this.onFrameRecorded(
|
|
86
|
+
const { data: a } = n;
|
|
87
|
+
o.frameSize && this.onFrameRecorded && this.onFrameRecorded(a), a.frameBuffer && this.audioBuffers.push(a.frameBuffer), a.isLastFrame && (u || (p = s.port) == null || p.terminate(), (f = this.mediaSource) == null || f.disconnect(), (l = this.audioContext) == null || l.close(), (m = this.onStop) == null || m.call(this, this.audioBuffers));
|
|
91
88
|
}, u)
|
|
92
|
-
|
|
89
|
+
i.connect(s);
|
|
93
90
|
else {
|
|
94
91
|
const n = e.createScriptProcessor(0, 1, 1);
|
|
95
|
-
n.onaudioprocess = ({ inputBuffer:
|
|
92
|
+
n.onaudioprocess = ({ inputBuffer: a }) => {
|
|
96
93
|
s.port.postMessage({
|
|
97
94
|
type: "message",
|
|
98
|
-
data:
|
|
95
|
+
data: a.getChannelData(0)
|
|
99
96
|
});
|
|
100
|
-
},
|
|
97
|
+
}, i.connect(n), n.connect(e.destination);
|
|
101
98
|
}
|
|
102
99
|
}
|
|
103
100
|
/** 停止录音 */
|
|
@@ -116,6 +113,6 @@ class C {
|
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
115
|
export {
|
|
119
|
-
|
|
116
|
+
v as RecorderManager
|
|
120
117
|
};
|
|
121
118
|
//# sourceMappingURL=RecorderManager.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecorderManager.es.js","sources":["../../../../src/utils/xunFeiVoice/RecorderManager/RecorderManager.js"],"sourcesContent":["/**\n * 录音管理器 - 用于处理音频录制及处理\n */\nimport CrossOriginWorker from 'co-web-worker';\nimport workletJsString from './processor.worklet.js?raw';\n\n//------------------------------ 音频处理核心类 ------------------------------\nconst { AudioWorkletNode } = window;\nconst isAudioWorkletSupported = !!AudioWorkletNode;\n\n/**\n * 获取用户媒体设备权限\n * @returns {Promise<MediaStream>}\n */\nasync function requestMicrophonePermission() {\n const mediaDevices = navigator.mediaDevices ?? {};\n\n if (typeof mediaDevices.getUserMedia === 'function') {\n return mediaDevices.getUserMedia({ audio: true, video: false });\n }\n\n if (typeof navigator.getUserMedia === 'function') {\n return new Promise((resolve, reject) => {\n navigator.getUserMedia({ audio: true, video: false }, resolve, reject);\n });\n }\n\n throw new Error('浏览器不支持录音!');\n}\n\nconst generateWorkletUrl = () => {\n const blob = new Blob([
|
|
1
|
+
{"version":3,"file":"RecorderManager.es.js","sources":["../../../../src/utils/xunFeiVoice/RecorderManager/RecorderManager.js"],"sourcesContent":["/**\n * 录音管理器 - 用于处理音频录制及处理\n */\nimport CrossOriginWorker from 'co-web-worker';\nimport workerJsString from './processorSource/processor.worker.js?raw';\nimport workletJsString from './processorSource/processor.worklet.js?raw';\n\n//------------------------------ 音频处理核心类 ------------------------------\nconst { AudioWorkletNode } = window;\nconst isAudioWorkletSupported = !!AudioWorkletNode;\n\n/**\n * 获取用户媒体设备权限\n * @returns {Promise<MediaStream>}\n */\nasync function requestMicrophonePermission() {\n const mediaDevices = navigator.mediaDevices ?? {};\n\n if (typeof mediaDevices.getUserMedia === 'function') {\n return mediaDevices.getUserMedia({ audio: true, video: false });\n }\n\n if (typeof navigator.getUserMedia === 'function') {\n return new Promise((resolve, reject) => {\n navigator.getUserMedia({ audio: true, video: false }, resolve, reject);\n });\n }\n\n throw new Error('浏览器不支持录音!');\n}\n\n/** @type {(type: 'worker' | 'worklet') => string} */\nconst generateWorkletUrl = (type) => {\n const jsStr = type === 'worker' ? workerJsString : workletJsString;\n const blob = new Blob([jsStr], { type: 'application/javascript' });\n const scriptUrl = URL.createObjectURL(blob);\n return scriptUrl;\n};\n\n/**\n * 初始化音频处理器\n * @param {AudioContext} audioContext\n * @returns {Promise<AudioWorkletNode|{port: Worker}>}\n */\nasync function initializeAudioProcessor(audioContext) {\n if (isAudioWorkletSupported) {\n await audioContext.audioWorklet.addModule(generateWorkletUrl('worklet'));\n return new AudioWorkletNode(audioContext, 'processor-worklet');\n }\n\n const worker = new CrossOriginWorker(generateWorkletUrl('worker'));\n return { port: worker };\n}\n\nconst NOOP = () => {};\n/**\n * 录音管理器\n */\n//------------------------------ 录音管理器类 ------------------------------\nexport class RecorderManager {\n /** @type {Array<ArrayBuffer>} */\n audioBuffers = [];\n /** @type {(params: RecordFrameInfo) => void} */\n onFrameRecorded = NOOP;\n onStart = NOOP;\n /** @type {(data: Array<ArrayBuffer>) => void} */\n onStop = NOOP;\n\n constructor() {}\n\n /**\n * 开始录音\n * @param {{\n * sampleRate?: number,\n * frameSize?: number,\n * arrayBufferType?: string\n * }} config 录音配置\n */\n async start(config) {\n try {\n this.audioBuffers = [];\n\n // 获取音频流并创建处理节点\n const mediaStream = await requestMicrophonePermission();\n const audioContext = this.createAudioContext(mediaStream, config.sampleRate);\n this.audioWorkletNode = await initializeAudioProcessor(audioContext);\n\n // 初始化音频处理\n this.setupAudioProcessing(audioContext, mediaStream, this.audioWorkletNode, config);\n /** 恢复之前暂停播放的音频。 */\n this.audioContext?.resume();\n\n this.onStart?.();\n } catch (error) {\n console.error('Failed to start recording:', error);\n throw error;\n }\n }\n\n /**\n * 创建音频上下文\n * @private\n */\n createAudioContext(mediaStream, targetSampleRate) {\n try {\n const context = new (window.AudioContext || window.webkitAudioContext)({\n sampleRate: targetSampleRate,\n });\n context.createMediaStreamSource(mediaStream);\n return context;\n } catch (error) {\n // 回退处理:当目标采样率不支持时使用默认采样率\n const fallbackContext = new (window.AudioContext || window.webkitAudioContext)();\n console.warn(`Using default sample rate: ${fallbackContext.sampleRate}`);\n fallbackContext.createMediaStreamSource(mediaStream);\n return fallbackContext;\n }\n }\n\n /**\n * 配置音频处理管线\n * @private\n */\n setupAudioProcessing(audioContext, mediaStream, audioWorkletNode, config) {\n // 创建媒体流源节点\n const mediaSource = audioContext.createMediaStreamSource(mediaStream);\n this.mediaSource = mediaSource;\n\n // 配置处理器通信\n audioWorkletNode.port.postMessage({\n type: 'init',\n data: {\n frameSize: config.frameSize,\n toSampleRate: config.sampleRate || audioContext.sampleRate,\n fromSampleRate: audioContext.sampleRate,\n arrayBufferType: config.arrayBufferType || 'short16',\n },\n });\n\n // 处理音频数据回调\n audioWorkletNode.port.onmessage = (e) => {\n const { data } = e;\n if (config.frameSize && this.onFrameRecorded) {\n this.onFrameRecorded(data);\n }\n\n if (data.frameBuffer) {\n this.audioBuffers.push(data.frameBuffer);\n }\n\n if (data.isLastFrame) {\n if (!isAudioWorkletSupported) {\n audioWorkletNode.port?.terminate();\n }\n this.mediaSource?.disconnect();\n this.audioContext?.close();\n this.onStop?.(this.audioBuffers);\n }\n };\n\n // 连接音频节点\n if (isAudioWorkletSupported) {\n mediaSource.connect(audioWorkletNode);\n } else {\n const scriptProcessor = audioContext.createScriptProcessor(0, 1, 1);\n scriptProcessor.onaudioprocess = ({ inputBuffer }) => {\n audioWorkletNode.port.postMessage({\n type: 'message',\n data: inputBuffer.getChannelData(0),\n });\n };\n mediaSource.connect(scriptProcessor);\n scriptProcessor.connect(audioContext.destination);\n }\n }\n\n /** 停止录音 */\n stop() {\n /** 暂停音频上下文对象中的进度,并暂时剥离进程对音频设备硬件的访问权限,减少 CPU 和电池的使用 */\n this.audioContext?.suspend();\n if (!this.audioWorkletNode) {\n console.error('Recorder is not started.');\n return;\n }\n if (this.audioWorkletNode) {\n this.audioWorkletNode.port.postMessage({ type: 'stop' });\n }\n }\n\n close() {\n this.audioBuffers = [];\n if (this.audioContext?.state !== 'closed') {\n return this.audioContext?.close();\n }\n }\n}\n"],"names":["AudioWorkletNode","isAudioWorkletSupported","requestMicrophonePermission","mediaDevices","resolve","reject","generateWorkletUrl","type","jsStr","workerJsString","workletJsString","blob","initializeAudioProcessor","audioContext","CrossOriginWorker","NOOP","RecorderManager","__publicField","config","mediaStream","_a","_b","error","targetSampleRate","context","fallbackContext","audioWorkletNode","mediaSource","e","data","_c","_d","scriptProcessor","inputBuffer"],"mappings":";;;;;;AAQA,MAAM,EAAE,kBAAAA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AN,EAAuB,cAEzBC,IAAA,KAAK,gBAAL,QAAAA,EAAkB,eAClBS,IAAA,KAAK,iBAAL,QAAAA,EAAmB,UACnBC,IAAA,KAAK,WAAL,QAAAA,EAAA,WAAc,KAAK;AAAA,IAEtB,GAGG9B;AACF,MAAA0B,EAAY,QAAQD,CAAgB;AAAA,SAC/B;AACL,YAAMM,IAAkBnB,EAAa,sBAAsB,GAAG,GAAG,CAAC;AAClE,MAAAmB,EAAgB,iBAAiB,CAAC,EAAE,aAAAC,QAAkB;AACpD,QAAAP,EAAiB,KAAK,YAAY;AAAA,UAChC,MAAM;AAAA,UACN,MAAMO,EAAY,eAAe,CAAC;AAAA,QAC5C,CAAS;AAAA,MACF,GACDN,EAAY,QAAQK,CAAe,GACnCA,EAAgB,QAAQnB,EAAa,WAAW;AAAA,IACtD;AAAA,EACA;AAAA;AAAA,EAGE,OAAO;;AAGL,SADAO,IAAA,KAAK,iBAAL,QAAAA,EAAmB,WACf,CAAC,KAAK,kBAAkB;AAC1B,cAAQ,MAAM,0BAA0B;AACxC;AAAA,IACN;AACI,IAAI,KAAK,oBACP,KAAK,iBAAiB,KAAK,YAAY,EAAE,MAAM,QAAQ;AAAA,EAE7D;AAAA,EAEE,QAAQ;;AAEN,QADA,KAAK,eAAe,CAAE,KAClBA,IAAA,KAAK,iBAAL,gBAAAA,EAAmB,WAAU;AAC/B,cAAOC,IAAA,KAAK,iBAAL,gBAAAA,EAAmB;AAAA,EAEhC;AACA;"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
const n = `!(function () {
|
|
2
|
+
"use strict";
|
|
3
|
+
function t(t) {
|
|
4
|
+
return (
|
|
5
|
+
(function (t) {
|
|
6
|
+
if (Array.isArray(t)) return e(t);
|
|
7
|
+
})(t) ||
|
|
8
|
+
(function (t) {
|
|
9
|
+
if (
|
|
10
|
+
("undefined" != typeof Symbol && null != t[Symbol.iterator]) ||
|
|
11
|
+
null != t["@@iterator"]
|
|
12
|
+
)
|
|
13
|
+
return Array.from(t);
|
|
14
|
+
})(t) ||
|
|
15
|
+
(function (t, r) {
|
|
16
|
+
if (!t) return;
|
|
17
|
+
if ("string" == typeof t) return e(t, r);
|
|
18
|
+
var i = Object.prototype.toString.call(t).slice(8, -1);
|
|
19
|
+
"Object" === i && t.constructor && (i = t.constructor.name);
|
|
20
|
+
if ("Map" === i || "Set" === i) return Array.from(t);
|
|
21
|
+
if (
|
|
22
|
+
"Arguments" === i ||
|
|
23
|
+
/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)
|
|
24
|
+
)
|
|
25
|
+
return e(t, r);
|
|
26
|
+
})(t) ||
|
|
27
|
+
(function () {
|
|
28
|
+
throw new TypeError(
|
|
29
|
+
"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
|
|
30
|
+
);
|
|
31
|
+
})()
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
function e(t, e) {
|
|
35
|
+
(null == e || e > t.length) && (e = t.length);
|
|
36
|
+
for (var r = 0, i = new Array(e); r < e; r++) i[r] = t[r];
|
|
37
|
+
return i;
|
|
38
|
+
}
|
|
39
|
+
function r(t, e, r, i) {
|
|
40
|
+
(this.fromSampleRate = t),
|
|
41
|
+
(this.toSampleRate = e),
|
|
42
|
+
(this.channels = 0 | r),
|
|
43
|
+
(this.noReturn = !!i),
|
|
44
|
+
this.initialize();
|
|
45
|
+
}
|
|
46
|
+
(r.prototype.initialize = function () {
|
|
47
|
+
if (
|
|
48
|
+
!(this.fromSampleRate > 0 && this.toSampleRate > 0 && this.channels > 0)
|
|
49
|
+
)
|
|
50
|
+
throw new Error("Invalid settings specified for the resampler.");
|
|
51
|
+
this.fromSampleRate == this.toSampleRate
|
|
52
|
+
? ((this.resampler = this.bypassResampler), (this.ratioWeight = 1))
|
|
53
|
+
: (this.fromSampleRate < this.toSampleRate
|
|
54
|
+
? ((this.lastWeight = 1),
|
|
55
|
+
(this.resampler = this.compileLinearInterpolation))
|
|
56
|
+
: ((this.tailExists = !1),
|
|
57
|
+
(this.lastWeight = 0),
|
|
58
|
+
(this.resampler = this.compileMultiTap)),
|
|
59
|
+
(this.ratioWeight = this.fromSampleRate / this.toSampleRate));
|
|
60
|
+
}),
|
|
61
|
+
(r.prototype.compileLinearInterpolation = function (t) {
|
|
62
|
+
var e = t.length;
|
|
63
|
+
this.initializeBuffers(e);
|
|
64
|
+
var r,
|
|
65
|
+
i,
|
|
66
|
+
s = this.outputBufferSize,
|
|
67
|
+
a = this.ratioWeight,
|
|
68
|
+
f = this.lastWeight,
|
|
69
|
+
n = 0,
|
|
70
|
+
o = 0,
|
|
71
|
+
h = 0,
|
|
72
|
+
l = this.outputBuffer;
|
|
73
|
+
if (e % this.channels == 0) {
|
|
74
|
+
if (e > 0) {
|
|
75
|
+
for (; f < 1; f += a)
|
|
76
|
+
for (n = 1 - (o = f % 1), r = 0; r < this.channels; ++r)
|
|
77
|
+
l[h++] = this.lastOutput[r] * n + t[r] * o;
|
|
78
|
+
for (
|
|
79
|
+
f--, e -= this.channels, i = Math.floor(f) * this.channels;
|
|
80
|
+
h < s && i < e;
|
|
81
|
+
|
|
82
|
+
) {
|
|
83
|
+
for (n = 1 - (o = f % 1), r = 0; r < this.channels; ++r)
|
|
84
|
+
l[h++] = t[i + r] * n + t[i + this.channels + r] * o;
|
|
85
|
+
(f += a), (i = Math.floor(f) * this.channels);
|
|
86
|
+
}
|
|
87
|
+
for (r = 0; r < this.channels; ++r) this.lastOutput[r] = t[i++];
|
|
88
|
+
return (this.lastWeight = f % 1), this.bufferSlice(h);
|
|
89
|
+
}
|
|
90
|
+
return this.noReturn ? 0 : [];
|
|
91
|
+
}
|
|
92
|
+
throw new Error("Buffer was of incorrect sample length.");
|
|
93
|
+
}),
|
|
94
|
+
(r.prototype.compileMultiTap = function (t) {
|
|
95
|
+
var e = [],
|
|
96
|
+
r = t.length;
|
|
97
|
+
this.initializeBuffers(r);
|
|
98
|
+
var i = this.outputBufferSize;
|
|
99
|
+
if (r % this.channels == 0) {
|
|
100
|
+
if (r > 0) {
|
|
101
|
+
for (var s = this.ratioWeight, a = 0, f = 0; f < this.channels; ++f)
|
|
102
|
+
e[f] = 0;
|
|
103
|
+
var n = 0,
|
|
104
|
+
o = 0,
|
|
105
|
+
h = !this.tailExists;
|
|
106
|
+
this.tailExists = !1;
|
|
107
|
+
var l = this.outputBuffer,
|
|
108
|
+
u = 0,
|
|
109
|
+
p = 0;
|
|
110
|
+
do {
|
|
111
|
+
if (h) for (a = s, f = 0; f < this.channels; ++f) e[f] = 0;
|
|
112
|
+
else {
|
|
113
|
+
for (a = this.lastWeight, f = 0; f < this.channels; ++f)
|
|
114
|
+
e[f] += this.lastOutput[f];
|
|
115
|
+
h = !0;
|
|
116
|
+
}
|
|
117
|
+
for (; a > 0 && n < r; ) {
|
|
118
|
+
if (!(a >= (o = 1 + n - p))) {
|
|
119
|
+
for (f = 0; f < this.channels; ++f) e[f] += t[n + f] * a;
|
|
120
|
+
(p += a), (a = 0);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
for (f = 0; f < this.channels; ++f) e[f] += t[n++] * o;
|
|
124
|
+
(p = n), (a -= o);
|
|
125
|
+
}
|
|
126
|
+
if (0 != a) {
|
|
127
|
+
for (this.lastWeight = a, f = 0; f < this.channels; ++f)
|
|
128
|
+
this.lastOutput[f] = e[f];
|
|
129
|
+
this.tailExists = !0;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
for (f = 0; f < this.channels; ++f) l[u++] = e[f] / s;
|
|
133
|
+
} while (n < r && u < i);
|
|
134
|
+
return this.bufferSlice(u);
|
|
135
|
+
}
|
|
136
|
+
return this.noReturn ? 0 : [];
|
|
137
|
+
}
|
|
138
|
+
throw new Error("Buffer was of incorrect sample length.");
|
|
139
|
+
}),
|
|
140
|
+
(r.prototype.bypassResampler = function (t) {
|
|
141
|
+
return this.noReturn ? ((this.outputBuffer = t), t.length) : t;
|
|
142
|
+
}),
|
|
143
|
+
(r.prototype.bufferSlice = function (t) {
|
|
144
|
+
if (this.noReturn) return t;
|
|
145
|
+
try {
|
|
146
|
+
return this.outputBuffer.subarray(0, t);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
try {
|
|
149
|
+
return (this.outputBuffer.length = t), this.outputBuffer;
|
|
150
|
+
} catch (e) {
|
|
151
|
+
return this.outputBuffer.slice(0, t);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}),
|
|
155
|
+
(r.prototype.initializeBuffers = function (t) {
|
|
156
|
+
this.outputBufferSize = Math.ceil(
|
|
157
|
+
(t * this.toSampleRate) / this.fromSampleRate
|
|
158
|
+
);
|
|
159
|
+
try {
|
|
160
|
+
(this.outputBuffer = new Float32Array(this.outputBufferSize)),
|
|
161
|
+
(this.lastOutput = new Float32Array(this.channels));
|
|
162
|
+
} catch (t) {
|
|
163
|
+
(this.outputBuffer = []), (this.lastOutput = []);
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
(self.transData = function (t) {
|
|
167
|
+
return (
|
|
168
|
+
"short16" === self.arrayBufferType &&
|
|
169
|
+
(t = (function (t) {
|
|
170
|
+
for (
|
|
171
|
+
var e = new ArrayBuffer(2 * t.length),
|
|
172
|
+
r = new DataView(e),
|
|
173
|
+
i = 0,
|
|
174
|
+
s = 0;
|
|
175
|
+
s < t.length;
|
|
176
|
+
s += 1, i += 2
|
|
177
|
+
) {
|
|
178
|
+
var a = Math.max(-1, Math.min(1, t[s]));
|
|
179
|
+
r.setInt16(i, a < 0 ? 32768 * a : 32767 * a, !0);
|
|
180
|
+
}
|
|
181
|
+
return r.buffer;
|
|
182
|
+
})((t = self.resampler.resampler(t)))),
|
|
183
|
+
t
|
|
184
|
+
);
|
|
185
|
+
}),
|
|
186
|
+
(self.onmessage = function (e) {
|
|
187
|
+
var i = e.data,
|
|
188
|
+
s = i.type,
|
|
189
|
+
a = i.data;
|
|
190
|
+
if ("init" === s) {
|
|
191
|
+
var f = a.frameSize,
|
|
192
|
+
n = a.toSampleRate,
|
|
193
|
+
o = a.fromSampleRate,
|
|
194
|
+
h = a.arrayBufferType;
|
|
195
|
+
return (
|
|
196
|
+
(self.frameSize = f * Math.floor(o / n)),
|
|
197
|
+
(self.resampler = new r(o, n, 1)),
|
|
198
|
+
(self.frameBuffer = []),
|
|
199
|
+
void (self.arrayBufferType = h)
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
if (
|
|
203
|
+
("stop" === s &&
|
|
204
|
+
(self.postMessage({
|
|
205
|
+
frameBuffer: self.transData(self.frameBuffer),
|
|
206
|
+
isLastFrame: !0,
|
|
207
|
+
}),
|
|
208
|
+
(self.frameBuffer = [])),
|
|
209
|
+
"message" === s)
|
|
210
|
+
) {
|
|
211
|
+
var l,
|
|
212
|
+
u = a;
|
|
213
|
+
if (self.frameSize)
|
|
214
|
+
return (
|
|
215
|
+
(l = self.frameBuffer).push.apply(l, t(u)),
|
|
216
|
+
self.frameBuffer.length >= self.frameSize &&
|
|
217
|
+
(self.postMessage({
|
|
218
|
+
frameBuffer: self.transData(this.frameBuffer),
|
|
219
|
+
isLastFrame: !1,
|
|
220
|
+
}),
|
|
221
|
+
(self.frameBuffer = [])),
|
|
222
|
+
!0
|
|
223
|
+
);
|
|
224
|
+
u &&
|
|
225
|
+
self.postMessage({ frameBuffer: self.transData(u), isLastFrame: !1 });
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
})();
|
|
229
|
+
`;
|
|
230
|
+
export {
|
|
231
|
+
n as default
|
|
232
|
+
};
|
|
233
|
+
//# sourceMappingURL=processor.worker.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.worker.es.js","sources":["../../../../../src/utils/xunFeiVoice/RecorderManager/processorSource/processor.worker.js?raw"],"sourcesContent":["export default \"!(function () {\\n \\\"use strict\\\";\\n function t(t) {\\n return (\\n (function (t) {\\n if (Array.isArray(t)) return e(t);\\n })(t) ||\\n (function (t) {\\n if (\\n (\\\"undefined\\\" != typeof Symbol && null != t[Symbol.iterator]) ||\\n null != t[\\\"@@iterator\\\"]\\n )\\n return Array.from(t);\\n })(t) ||\\n (function (t, r) {\\n if (!t) return;\\n if (\\\"string\\\" == typeof t) return e(t, r);\\n var i = Object.prototype.toString.call(t).slice(8, -1);\\n \\\"Object\\\" === i && t.constructor && (i = t.constructor.name);\\n if (\\\"Map\\\" === i || \\\"Set\\\" === i) return Array.from(t);\\n if (\\n \\\"Arguments\\\" === i ||\\n /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)\\n )\\n return e(t, r);\\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 e(t, e) {\\n (null == e || e > t.length) && (e = t.length);\\n for (var r = 0, i = new Array(e); r < e; r++) i[r] = t[r];\\n return i;\\n }\\n function r(t, e, r, i) {\\n (this.fromSampleRate = t),\\n (this.toSampleRate = e),\\n (this.channels = 0 | r),\\n (this.noReturn = !!i),\\n this.initialize();\\n }\\n (r.prototype.initialize = function () {\\n if (\\n !(this.fromSampleRate > 0 && this.toSampleRate > 0 && this.channels > 0)\\n )\\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),\\n (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 (r.prototype.compileLinearInterpolation = function (t) {\\n var e = t.length;\\n this.initializeBuffers(e);\\n var r,\\n i,\\n s = this.outputBufferSize,\\n a = this.ratioWeight,\\n f = this.lastWeight,\\n n = 0,\\n o = 0,\\n h = 0,\\n l = this.outputBuffer;\\n if (e % this.channels == 0) {\\n if (e > 0) {\\n for (; f < 1; f += a)\\n for (n = 1 - (o = f % 1), r = 0; r < this.channels; ++r)\\n l[h++] = this.lastOutput[r] * n + t[r] * o;\\n for (\\n f--, e -= this.channels, i = Math.floor(f) * this.channels;\\n h < s && i < e;\\n\\n ) {\\n for (n = 1 - (o = f % 1), r = 0; r < this.channels; ++r)\\n l[h++] = t[i + r] * n + t[i + this.channels + r] * o;\\n (f += a), (i = Math.floor(f) * this.channels);\\n }\\n for (r = 0; r < this.channels; ++r) this.lastOutput[r] = t[i++];\\n return (this.lastWeight = f % 1), this.bufferSlice(h);\\n }\\n return this.noReturn ? 0 : [];\\n }\\n throw new Error(\\\"Buffer was of incorrect sample length.\\\");\\n }),\\n (r.prototype.compileMultiTap = function (t) {\\n var e = [],\\n r = t.length;\\n this.initializeBuffers(r);\\n var i = this.outputBufferSize;\\n if (r % this.channels == 0) {\\n if (r > 0) {\\n for (var s = this.ratioWeight, a = 0, f = 0; f < this.channels; ++f)\\n e[f] = 0;\\n var n = 0,\\n o = 0,\\n h = !this.tailExists;\\n this.tailExists = !1;\\n var l = this.outputBuffer,\\n u = 0,\\n p = 0;\\n do {\\n if (h) for (a = s, f = 0; f < this.channels; ++f) e[f] = 0;\\n else {\\n for (a = this.lastWeight, f = 0; f < this.channels; ++f)\\n e[f] += this.lastOutput[f];\\n h = !0;\\n }\\n for (; a > 0 && n < r; ) {\\n if (!(a >= (o = 1 + n - p))) {\\n for (f = 0; f < this.channels; ++f) e[f] += t[n + f] * a;\\n (p += a), (a = 0);\\n break;\\n }\\n for (f = 0; f < this.channels; ++f) e[f] += t[n++] * o;\\n (p = n), (a -= o);\\n }\\n if (0 != a) {\\n for (this.lastWeight = a, f = 0; f < this.channels; ++f)\\n this.lastOutput[f] = e[f];\\n this.tailExists = !0;\\n break;\\n }\\n for (f = 0; f < this.channels; ++f) l[u++] = e[f] / s;\\n } while (n < r && u < i);\\n return this.bufferSlice(u);\\n }\\n return this.noReturn ? 0 : [];\\n }\\n throw new Error(\\\"Buffer was of incorrect sample length.\\\");\\n }),\\n (r.prototype.bypassResampler = function (t) {\\n return this.noReturn ? ((this.outputBuffer = t), t.length) : t;\\n }),\\n (r.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 (r.prototype.initializeBuffers = function (t) {\\n this.outputBufferSize = Math.ceil(\\n (t * this.toSampleRate) / this.fromSampleRate\\n );\\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 (self.transData = function (t) {\\n return (\\n \\\"short16\\\" === self.arrayBufferType &&\\n (t = (function (t) {\\n for (\\n var e = new ArrayBuffer(2 * t.length),\\n r = new DataView(e),\\n i = 0,\\n s = 0;\\n s < t.length;\\n s += 1, i += 2\\n ) {\\n var a = Math.max(-1, Math.min(1, t[s]));\\n r.setInt16(i, a < 0 ? 32768 * a : 32767 * a, !0);\\n }\\n return r.buffer;\\n })((t = self.resampler.resampler(t)))),\\n t\\n );\\n }),\\n (self.onmessage = function (e) {\\n var i = e.data,\\n s = i.type,\\n a = i.data;\\n if (\\\"init\\\" === s) {\\n var f = a.frameSize,\\n n = a.toSampleRate,\\n o = a.fromSampleRate,\\n h = a.arrayBufferType;\\n return (\\n (self.frameSize = f * Math.floor(o / n)),\\n (self.resampler = new r(o, n, 1)),\\n (self.frameBuffer = []),\\n void (self.arrayBufferType = h)\\n );\\n }\\n if (\\n (\\\"stop\\\" === s &&\\n (self.postMessage({\\n frameBuffer: self.transData(self.frameBuffer),\\n isLastFrame: !0,\\n }),\\n (self.frameBuffer = [])),\\n \\\"message\\\" === s)\\n ) {\\n var l,\\n u = a;\\n if (self.frameSize)\\n return (\\n (l = self.frameBuffer).push.apply(l, t(u)),\\n self.frameBuffer.length >= self.frameSize &&\\n (self.postMessage({\\n frameBuffer: self.transData(this.frameBuffer),\\n isLastFrame: !1,\\n }),\\n (self.frameBuffer = [])),\\n !0\\n );\\n u &&\\n self.postMessage({ frameBuffer: self.transData(u), isLastFrame: !1 });\\n }\\n });\\n})();\\n\""],"names":["workerJsString"],"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;"}
|
|
File without changes
|
|
@@ -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;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,5 +1,5 @@
|
|
|
1
1
|
import { RecorderManager } from './RecorderManager';
|
|
2
|
-
import { RecordFrameInfo } from './types';
|
|
2
|
+
import { OnMessageInfo, RecordFrameInfo } from './types';
|
|
3
3
|
|
|
4
4
|
type errorType = 'socketConnect' | 'message' | 'record';
|
|
5
5
|
export interface XunFeiStreamVoiceManagerConfig {
|
|
@@ -11,20 +11,11 @@ export interface XunFeiStreamVoiceManagerConfig {
|
|
|
11
11
|
* @param info.message 消息内容
|
|
12
12
|
* @param info.isLatest 是否是最后一条消息。 isLatest 为 true 时, message 为完整的语音识别结果。
|
|
13
13
|
*/
|
|
14
|
-
onMessage: (info:
|
|
15
|
-
message: string;
|
|
16
|
-
isLatest?: boolean;
|
|
17
|
-
}) => void;
|
|
14
|
+
onMessage: (info: OnMessageInfo) => void;
|
|
18
15
|
/** webSocket 关闭的回调。
|
|
19
16
|
* 每次录音都会新建一个 webSocket 连接。录音结束后关闭 webSocket
|
|
20
17
|
*/
|
|
21
18
|
onWsClose: () => void;
|
|
22
|
-
/** 获取讯飞提供的 processor.worker.js 和 processor.worklet.js 的路径。
|
|
23
|
-
* 填写这两个文件的父路径就好。 如 a/b/processor.worker.js 则填写 a/b。
|
|
24
|
-
* 可以是oss地址,也可以是项目中的文件路径,智能通过url请求,能得到上面两个js文件即可。
|
|
25
|
-
* 目前已上传到 oss://{assetsBaseUrl}/announcement/easyvadmin/xun-fei-voice/ 目录下。
|
|
26
|
-
*/
|
|
27
|
-
processWorkJsPath: string;
|
|
28
19
|
/**
|
|
29
20
|
* 获取链接讯飞语音识别地址的 url
|
|
30
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
|
|
@@ -38,10 +38,18 @@ class C {
|
|
|
38
38
|
n.pgs ? (n.pgs === "apd" && (this.resultText = this.resultTextTemp), this.resultTextTemp = this.resultText + a) : this.resultText = this.resultText + a;
|
|
39
39
|
}
|
|
40
40
|
if (e.code === 0 && e.data.status === 2) {
|
|
41
|
-
this.config.onMessage({
|
|
41
|
+
this.config.onMessage({
|
|
42
|
+
message: this.resultText,
|
|
43
|
+
isLatest: !0,
|
|
44
|
+
tempMessage: this.resultTextTemp
|
|
45
|
+
}), (s = this.wsInstance) == null || s.close();
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
44
|
-
e.code === 0 && e.data.status === 1 && this.config.onMessage({
|
|
48
|
+
e.code === 0 && e.data.status === 1 && this.config.onMessage({
|
|
49
|
+
message: this.resultText,
|
|
50
|
+
isLatest: !1,
|
|
51
|
+
tempMessage: this.resultTextTemp
|
|
52
|
+
}), e.code !== 0 && ((r = this.wsInstance) == null || r.close(), this.config.onError({ type: "message", message: t }));
|
|
45
53
|
}
|
|
46
54
|
setConfig(t) {
|
|
47
55
|
this.config = {
|
|
@@ -122,7 +130,7 @@ class C {
|
|
|
122
130
|
), t && (this.readyToSend = !1, this.changeBtnStatus("CLOSING")));
|
|
123
131
|
}
|
|
124
132
|
initializeRecorder() {
|
|
125
|
-
this.recorder = new w(
|
|
133
|
+
this.recorder = new w(), this.recorder && (this.recorder.onFrameRecorded = (t) => {
|
|
126
134
|
this.recordProcess(t);
|
|
127
135
|
}, this.recorder.onStop = (t) => {
|
|
128
136
|
}, this.recorder.onStart = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"XunFeiStreamVoiceManager.es.js","sources":["../../../src/utils/xunFeiVoice/XunFeiStreamVoiceManager.ts"],"sourcesContent":["import CryptoJS from 'crypto-js';\nimport { RecorderManager } from './RecorderManager';\nimport type { RecordFrameInfo } from './types';\nimport { toBase64 } from './utils';\n\ntype errorType = 'socketConnect' | 'message' | 'record';\nlet startCount = 0;\n\nexport interface XunFeiStreamVoiceManagerConfig {\n onError: (errInfo: { type: errorType; message: string }) => void;\n /** ws 收到消息的回调\n * @param info.message 消息内容\n * @param info.isLatest 是否是最后一条消息。 isLatest 为 true 时, message 为完整的语音识别结果。\n */\n onMessage: (info: { message: string; isLatest?: boolean }) => void;\n /** webSocket 关闭的回调。\n * 每次录音都会新建一个 webSocket 连接。录音结束后关闭 webSocket\n */\n onWsClose: () => void;\n /** 获取讯飞提供的 processor.worker.js 和 processor.worklet.js 的路径。\n * 填写这两个文件的父路径就好。 如 a/b/processor.worker.js 则填写 a/b。\n * 可以是oss地址,也可以是项目中的文件路径,智能通过url请求,能得到上面两个js文件即可。\n * 目前已上传到 oss://{assetsBaseUrl}/announcement/easyvadmin/xun-fei-voice/ 目录下。\n */\n processWorkJsPath: string;\n // 获取 websocket url 的方法\n /**\n * 获取链接讯飞语音识别地址的 url\n * @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\n */\n getWebSocketUrl?: () => string;\n}\ntype SocketStatus = 'UNDEFINED' | 'CONNECTING' | 'OPEN' | 'CLOSING' | 'CLOSED';\n\n/** 现在前端mock,后续移到接口下发 */\nconst APPID = '93b73e33';\nconst API_SECRET = 'ZGJhMzQ5ZTJlMDgyYmE1ZTFlZDlmYjg0';\nconst API_KEY = 'fe43de7a071e3a32ec03c6f09fe7bedf';\n/**\n * 获取websocket url\n * 该接口需要后端提供,这里为了方便前端处理\n */\nfunction getWebSocketUrl() {\n // 请求地址根据语种不同变化\n const url = 'wss://iat-api.xfyun.cn/v2/iat';\n const host = 'iat-api.xfyun.cn';\n const apiKey = API_KEY;\n const apiSecret = API_SECRET;\n const date = new Date().toUTCString();\n const algorithm = 'hmac-sha256';\n const headers = 'host date request-line';\n const signatureOrigin = `host: ${host}\\ndate: ${date}\\nGET /v2/iat HTTP/1.1`;\n const signatureSha = CryptoJS.HmacSHA256(signatureOrigin, apiSecret);\n const signature = CryptoJS.enc.Base64.stringify(signatureSha);\n const authorizationOrigin = `api_key=\"${apiKey}\", algorithm=\"${algorithm}\", headers=\"${headers}\", signature=\"${signature}\"`;\n const authorization = window.btoa(authorizationOrigin);\n return `${url}?authorization=${authorization}&date=${date}&host=${host}`;\n}\n\n/**\n * 讯飞流式语音识别\n */\nexport class XunFeiStreamVoiceManager {\n wsInstance: WebSocket | null = null;\n status: SocketStatus = 'UNDEFINED';\n recorder: RecorderManager | null = null;\n isDestroy = false;\n resultText = '';\n resultTextTemp = '';\n continueRecord = false;\n startTimeStamp = 0;\n recordStatus: 'start' | 'stop' = 'stop';\n readyToSend = false;\n\n constructor(public config: XunFeiStreamVoiceManagerConfig) {\n this.initializeRecorder();\n }\n renderResult(resultData: string) {\n // 识别结束\n const jsonData = JSON.parse(resultData);\n if (jsonData.data && jsonData.data.result) {\n const data = jsonData.data.result;\n let str = '';\n const ws = data.ws;\n for (let i = 0; i < ws.length; i++) {\n str = str + ws[i].cw[0].w;\n }\n // 开启 wpgs 会有此字段(前提:在控制台开通动态修正功能)\n // 取值为 \"apd\"时表示该片结果是追加到前面的最终结果;取值为\"rpl\" 时表示替换前面的部分结果,替换范围为rg字段\n if (data.pgs) {\n if (data.pgs === 'apd') {\n // 将resultTextTemp同步给resultText\n this.resultText = this.resultTextTemp;\n }\n // 将结果存储在resultTextTemp中\n this.resultTextTemp = this.resultText + str;\n } else {\n this.resultText = this.resultText + str;\n }\n }\n /**\n * 识别结果是否结束标识:\n * 0:识别的第一块结果。\n * 1:识别中间结果。\n * 2:识别最后一块结果\n */\n if (jsonData.code === 0 && jsonData.data.status === 2) {\n this.config.onMessage({ message: this.resultText, isLatest: true });\n this.wsInstance?.close();\n return;\n }\n if (jsonData.code === 0 && jsonData.data.status === 1) {\n this.config.onMessage({ message: this.resultText, isLatest: false });\n }\n // code 不为0时表示出错\n if (jsonData.code !== 0) {\n this.wsInstance?.close();\n this.config.onError({ type: 'message', message: resultData });\n }\n }\n\n setConfig(newConfig: XunFeiStreamVoiceManagerConfig) {\n this.config = {\n ...this.config,\n ...newConfig,\n };\n this.initializeRecorder();\n }\n sendMessage(message: string) {\n if (this.wsInstance?.readyState === WebSocket.OPEN && this.readyToSend) {\n this.wsInstance.send(message);\n }\n }\n\n async recordConfigSend() {\n if (this.isDestroy) {\n return;\n }\n try {\n // 开始录音\n await this.recorder?.start({\n sampleRate: 16000,\n frameSize: 1280,\n });\n const params = {\n common: {\n app_id: APPID,\n },\n business: {\n language: 'zh_cn',\n domain: 'iat',\n accent: 'mandarin',\n vad_eos: 5000,\n dwa: 'wpgs',\n },\n data: {\n status: 0,\n format: 'audio/L16;rate=16000',\n encoding: 'raw',\n },\n };\n this.readyToSend = true;\n this.sendMessage(JSON.stringify(params));\n } catch (error) {\n console.error('record error:', error);\n this.config.onError({ type: 'record', message: '录音失败, 请检查权限!' });\n }\n }\n\n startNewSocket() {\n console.log(\n '%c ❤️ love ==== start new socket ',\n 'color: red; font-size: 16px;',\n startCount,\n new Date().toUTCString(),\n );\n startCount++;\n const websocketUrl = this.config.getWebSocketUrl?.() || getWebSocketUrl();\n if ('WebSocket' in window) {\n this.wsInstance = new WebSocket(websocketUrl);\n } else {\n this.config.onError({ type: 'socketConnect', message: '浏览器不支持 WebSocket' });\n return;\n }\n this.wsInstance.onmessage = (e) => {\n // 处理返回数据\n this.renderResult(e.data);\n };\n this.wsInstance.onerror = (e) => {\n console.error('socket error:', e);\n this.changeBtnStatus('CLOSED');\n };\n this.wsInstance.onclose = async () => {\n this.changeBtnStatus('CLOSED');\n this.config.onWsClose();\n this.recorder?.stop();\n if (this.continueRecord) {\n this.readyToSend = false;\n await this.recorder?.close();\n this.startRecord();\n }\n };\n this.wsInstance.onopen = () => {\n this.changeBtnStatus('OPEN');\n this.recordConfigSend();\n };\n }\n\n recordProcess({ isLastFrame, frameBuffer }: RecordFrameInfo) {\n if (this.isDestroy) {\n return;\n }\n if (!this.wsInstance) {\n return;\n }\n if (this.wsInstance.readyState === this.wsInstance.OPEN) {\n this.sendMessage(\n JSON.stringify({\n data: {\n status: isLastFrame ? 2 : 1,\n format: 'audio/L16;rate=16000',\n encoding: 'raw',\n audio: toBase64(frameBuffer),\n },\n }),\n );\n }\n if (isLastFrame) {\n this.readyToSend = false;\n this.changeBtnStatus('CLOSING');\n }\n }\n\n initializeRecorder() {\n this.recorder = new RecorderManager(this.config.processWorkJsPath);\n if (!this.recorder) {\n return;\n }\n this.recorder.onFrameRecorded = (data: RecordFrameInfo) => {\n this.recordProcess(data);\n };\n this.recorder.onStop = (_data: ArrayBuffer[]) => {\n // do nothing\n };\n this.recorder.onStart = () => {\n console.log('%c ❤️ love ==== recorder onStart:', 'color: red; font-size: 16px;');\n this.changeBtnStatus('OPEN');\n };\n }\n\n changeBtnStatus(status: SocketStatus) {\n this.status = status;\n }\n\n startRecord() {\n if (this.isDestroy) {\n return;\n }\n this.startTimeStamp = Date.now();\n this.resultText = '';\n this.resultTextTemp = '';\n this.startNewSocket();\n }\n\n async stopRecord() {\n console.log('stop record ====', Date.now() - this.startTimeStamp);\n // 结束录音,为了防止刚开始就关闭\n if (Date.now() - this.startTimeStamp < 500) {\n setTimeout(() => {\n this.recorder?.stop();\n }, 100);\n } else {\n this.recorder?.stop();\n }\n // 这里为了防止ws没有返回结束的数据,导致 ws 一直没关,所以加个定时器,5s 后手动关闭\n setTimeout(() => {\n if (this.wsInstance?.readyState === WebSocket.OPEN) {\n this.wsInstance?.close();\n }\n }, 5000);\n }\n\n /** 开启持续监听 */\n startContinueRecord() {\n this.continueRecord = true;\n this.startRecord();\n }\n\n stopContinueRecord() {\n this.continueRecord = false;\n this.stopRecord();\n }\n\n destroy() {\n this.isDestroy = true;\n setTimeout(() => {\n if (this.wsInstance?.readyState === WebSocket.OPEN) {\n this.wsInstance?.close();\n }\n this.recorder?.stop();\n }, 1000);\n }\n}\n"],"names":["startCount","APPID","API_SECRET","API_KEY","getWebSocketUrl","url","host","apiKey","apiSecret","date","algorithm","headers","signatureOrigin","signatureSha","CryptoJS","signature","authorizationOrigin","authorization","XunFeiStreamVoiceManager","config","__publicField","resultData","jsonData","data","str","ws","i","_a","_b","newConfig","message","params","error","websocketUrl","e","isLastFrame","frameBuffer","toBase64","RecorderManager","_data","status","_c"],"mappings":";;;;;;AAMA,IAAIA,IAAa;AA6BjB,MAAMC,IAAQ,YACRC,IAAa,oCACbC,IAAU;AAKhB,SAASC,IAAkB;AAEzB,QAAMC,IAAM,iCACNC,IAAO,oBACPC,IAASJ,GACTK,IAAYN,GACZO,KAAO,oBAAI,KAAK,GAAE,YAAY,GAC9BC,IAAY,eACZC,IAAU,0BACVC,IAAkB,SAASN,CAAI;AAAA,QAAWG,CAAI;AAAA,uBAC9CI,IAAeC,EAAS,WAAWF,GAAiBJ,CAAS,GAC7DO,IAAYD,EAAS,IAAI,OAAO,UAAUD,CAAY,GACtDG,IAAsB,YAAYT,CAAM,iBAAiBG,CAAS,eAAeC,CAAO,iBAAiBI,CAAS,KAClHE,IAAgB,OAAO,KAAKD,CAAmB;AACrD,SAAO,GAAGX,CAAG,kBAAkBY,CAAa,SAASR,CAAI,SAASH,CAAI;AACxE;AAKO,MAAMY,EAAyB;AAAA,EAYpC,YAAmBC,GAAwC;AAX3D,IAAAC,EAAA,oBAA+B;AAC/B,IAAAA,EAAA,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AA;AAAA,EAGhB,cAAc;AACZ,IAAI,KAAK,cAGJ,KAAA,iBAAiB,KAAK,IAAI,GAC/B,KAAK,aAAa,IAClB,KAAK,iBAAiB,IACtB,KAAK,eAAe;AAAA,EAAA;AAAA,EAGtB,MAAM,aAAa;;AACjB,YAAQ,IAAI,qBAAqB,KAAK,IAAI,IAAI,KAAK,cAAc,GAE7D,KAAK,IAAA,IAAQ,KAAK,iBAAiB,MACrC,WAAW,MAAM;;AACf,OAAAb,IAAA,KAAK,aAAL,QAAAA,EAAe;AAAA,OACd,GAAG,KAENA,IAAA,KAAK,aAAL,QAAAA,EAAe,QAGjB,WAAW,MAAM;;AACf,QAAIA,IAAA,KAAK,eAAL,gBAAAA,EAAiB,gBAAe,UAAU,UAC5CC,IAAA,KAAK,eAAL,QAAAA,EAAiB;AAAA,OAElB,GAAI;AAAA,EAAA;AAAA;AAAA,EAIT,sBAAsB;AACpB,SAAK,iBAAiB,IACtB,KAAK,YAAY;AAAA,EAAA;AAAA,EAGnB,qBAAqB;AACnB,SAAK,iBAAiB,IACtB,KAAK,WAAW;AAAA,EAAA;AAAA,EAGlB,UAAU;AACR,SAAK,YAAY,IACjB,WAAW,MAAM;;AACf,QAAID,IAAA,KAAK,eAAL,gBAAAA,EAAiB,gBAAe,UAAU,UAC5CC,IAAA,KAAK,eAAL,QAAAA,EAAiB,WAEnBa,IAAA,KAAK,aAAL,QAAAA,EAAe;AAAA,OACd,GAAI;AAAA,EAAA;AAEX;"}
|
|
1
|
+
{"version":3,"file":"XunFeiStreamVoiceManager.es.js","sources":["../../../src/utils/xunFeiVoice/XunFeiStreamVoiceManager.ts"],"sourcesContent":["import CryptoJS from 'crypto-js';\nimport { RecorderManager } from './RecorderManager';\nimport type { OnMessageInfo, RecordFrameInfo } from './types';\nimport { toBase64 } from './utils';\n\ntype errorType = 'socketConnect' | 'message' | 'record';\nlet startCount = 0;\n\nexport interface XunFeiStreamVoiceManagerConfig {\n onError: (errInfo: { type: errorType; message: string }) => void;\n /** ws 收到消息的回调\n * @param info.message 消息内容\n * @param info.isLatest 是否是最后一条消息。 isLatest 为 true 时, message 为完整的语音识别结果。\n */\n onMessage: (info: OnMessageInfo) => void;\n /** webSocket 关闭的回调。\n * 每次录音都会新建一个 webSocket 连接。录音结束后关闭 webSocket\n */\n onWsClose: () => void;\n /**\n * 获取链接讯飞语音识别地址的 url\n * @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\n */\n getWebSocketUrl?: () => string;\n}\ntype SocketStatus = 'UNDEFINED' | 'CONNECTING' | 'OPEN' | 'CLOSING' | 'CLOSED';\n\n/** 现在前端mock,后续移到接口下发 */\nconst APPID = '93b73e33';\nconst API_SECRET = 'ZGJhMzQ5ZTJlMDgyYmE1ZTFlZDlmYjg0';\nconst API_KEY = 'fe43de7a071e3a32ec03c6f09fe7bedf';\n/**\n * 获取websocket url\n * 该接口需要后端提供,这里为了方便前端处理\n */\nfunction getWebSocketUrl() {\n // 请求地址根据语种不同变化\n const url = 'wss://iat-api.xfyun.cn/v2/iat';\n const host = 'iat-api.xfyun.cn';\n const apiKey = API_KEY;\n const apiSecret = API_SECRET;\n const date = new Date().toUTCString();\n const algorithm = 'hmac-sha256';\n const headers = 'host date request-line';\n const signatureOrigin = `host: ${host}\\ndate: ${date}\\nGET /v2/iat HTTP/1.1`;\n const signatureSha = CryptoJS.HmacSHA256(signatureOrigin, apiSecret);\n const signature = CryptoJS.enc.Base64.stringify(signatureSha);\n const authorizationOrigin = `api_key=\"${apiKey}\", algorithm=\"${algorithm}\", headers=\"${headers}\", signature=\"${signature}\"`;\n const authorization = window.btoa(authorizationOrigin);\n return `${url}?authorization=${authorization}&date=${date}&host=${host}`;\n}\n\n/**\n * 讯飞流式语音识别\n */\nexport class XunFeiStreamVoiceManager {\n wsInstance: WebSocket | null = null;\n status: SocketStatus = 'UNDEFINED';\n recorder: RecorderManager | null = null;\n isDestroy = false;\n resultText = '';\n resultTextTemp = '';\n continueRecord = false;\n startTimeStamp = 0;\n recordStatus: 'start' | 'stop' = 'stop';\n readyToSend = false;\n\n constructor(public config: XunFeiStreamVoiceManagerConfig) {\n this.initializeRecorder();\n }\n renderResult(resultData: string) {\n // 识别结束\n const jsonData = JSON.parse(resultData);\n if (jsonData.data && jsonData.data.result) {\n const data = jsonData.data.result;\n let str = '';\n const ws = data.ws;\n for (let i = 0; i < ws.length; i++) {\n str = str + ws[i].cw[0].w;\n }\n // 开启 wpgs 会有此字段(前提:在控制台开通动态修正功能)\n // 取值为 \"apd\"时表示该片结果是追加到前面的最终结果;取值为\"rpl\" 时表示替换前面的部分结果,替换范围为rg字段\n if (data.pgs) {\n if (data.pgs === 'apd') {\n // 将resultTextTemp同步给resultText\n this.resultText = this.resultTextTemp;\n }\n // 将结果存储在resultTextTemp中\n this.resultTextTemp = this.resultText + str;\n } else {\n this.resultText = this.resultText + str;\n }\n }\n /**\n * 识别结果是否结束标识:\n * 0:识别的第一块结果。\n * 1:识别中间结果。\n * 2:识别最后一块结果\n */\n if (jsonData.code === 0 && jsonData.data.status === 2) {\n this.config.onMessage({\n message: this.resultText,\n isLatest: true,\n tempMessage: this.resultTextTemp,\n });\n this.wsInstance?.close();\n return;\n }\n if (jsonData.code === 0 && jsonData.data.status === 1) {\n this.config.onMessage({\n message: this.resultText,\n isLatest: false,\n tempMessage: this.resultTextTemp,\n });\n }\n // code 不为0时表示出错\n if (jsonData.code !== 0) {\n this.wsInstance?.close();\n this.config.onError({ type: 'message', message: resultData });\n }\n }\n\n setConfig(newConfig: XunFeiStreamVoiceManagerConfig) {\n this.config = {\n ...this.config,\n ...newConfig,\n };\n this.initializeRecorder();\n }\n sendMessage(message: string) {\n if (this.wsInstance?.readyState === WebSocket.OPEN && this.readyToSend) {\n this.wsInstance.send(message);\n }\n }\n\n async recordConfigSend() {\n if (this.isDestroy) {\n return;\n }\n try {\n // 开始录音\n await this.recorder?.start({\n sampleRate: 16000,\n frameSize: 1280,\n });\n const params = {\n common: {\n app_id: APPID,\n },\n business: {\n language: 'zh_cn',\n domain: 'iat',\n accent: 'mandarin',\n vad_eos: 5000,\n dwa: 'wpgs',\n },\n data: {\n status: 0,\n format: 'audio/L16;rate=16000',\n encoding: 'raw',\n },\n };\n this.readyToSend = true;\n this.sendMessage(JSON.stringify(params));\n } catch (error) {\n console.error('record error:', error);\n this.config.onError({ type: 'record', message: '录音失败, 请检查权限!' });\n }\n }\n\n startNewSocket() {\n console.log(\n '%c ❤️ love ==== start new socket ',\n 'color: red; font-size: 16px;',\n startCount,\n new Date().toUTCString(),\n );\n startCount++;\n const websocketUrl = this.config.getWebSocketUrl?.() || getWebSocketUrl();\n if ('WebSocket' in window) {\n this.wsInstance = new WebSocket(websocketUrl);\n } else {\n this.config.onError({ type: 'socketConnect', message: '浏览器不支持 WebSocket' });\n return;\n }\n this.wsInstance.onmessage = (e) => {\n // 处理返回数据\n this.renderResult(e.data);\n };\n this.wsInstance.onerror = (e) => {\n console.error('socket error:', e);\n this.changeBtnStatus('CLOSED');\n };\n this.wsInstance.onclose = async () => {\n this.changeBtnStatus('CLOSED');\n this.config.onWsClose();\n this.recorder?.stop();\n if (this.continueRecord) {\n this.readyToSend = false;\n await this.recorder?.close();\n this.startRecord();\n }\n };\n this.wsInstance.onopen = () => {\n this.changeBtnStatus('OPEN');\n this.recordConfigSend();\n };\n }\n\n recordProcess({ isLastFrame, frameBuffer }: RecordFrameInfo) {\n if (this.isDestroy) {\n return;\n }\n if (!this.wsInstance) {\n return;\n }\n if (this.wsInstance.readyState === this.wsInstance.OPEN) {\n this.sendMessage(\n JSON.stringify({\n data: {\n status: isLastFrame ? 2 : 1,\n format: 'audio/L16;rate=16000',\n encoding: 'raw',\n audio: toBase64(frameBuffer),\n },\n }),\n );\n }\n if (isLastFrame) {\n this.readyToSend = false;\n this.changeBtnStatus('CLOSING');\n }\n }\n\n initializeRecorder() {\n this.recorder = new RecorderManager();\n if (!this.recorder) {\n return;\n }\n this.recorder.onFrameRecorded = (data: RecordFrameInfo) => {\n this.recordProcess(data);\n };\n this.recorder.onStop = (_data: ArrayBuffer[]) => {\n // do nothing\n };\n this.recorder.onStart = () => {\n console.log('%c ❤️ love ==== recorder onStart:', 'color: red; font-size: 16px;');\n this.changeBtnStatus('OPEN');\n };\n }\n\n changeBtnStatus(status: SocketStatus) {\n this.status = status;\n }\n\n startRecord() {\n if (this.isDestroy) {\n return;\n }\n this.startTimeStamp = Date.now();\n this.resultText = '';\n this.resultTextTemp = '';\n this.startNewSocket();\n }\n\n async stopRecord() {\n console.log('stop record ====', Date.now() - this.startTimeStamp);\n // 结束录音,为了防止刚开始就关闭\n if (Date.now() - this.startTimeStamp < 500) {\n setTimeout(() => {\n this.recorder?.stop();\n }, 100);\n } else {\n this.recorder?.stop();\n }\n // 这里为了防止ws没有返回结束的数据,导致 ws 一直没关,所以加个定时器,5s 后手动关闭\n setTimeout(() => {\n if (this.wsInstance?.readyState === WebSocket.OPEN) {\n this.wsInstance?.close();\n }\n }, 5000);\n }\n\n /** 开启持续监听 */\n startContinueRecord() {\n this.continueRecord = true;\n this.startRecord();\n }\n\n stopContinueRecord() {\n this.continueRecord = false;\n this.stopRecord();\n }\n\n destroy() {\n this.isDestroy = true;\n setTimeout(() => {\n if (this.wsInstance?.readyState === WebSocket.OPEN) {\n this.wsInstance?.close();\n }\n this.recorder?.stop();\n }, 1000);\n }\n}\n"],"names":["startCount","APPID","API_SECRET","API_KEY","getWebSocketUrl","url","host","apiKey","apiSecret","date","algorithm","headers","signatureOrigin","signatureSha","CryptoJS","signature","authorizationOrigin","authorization","XunFeiStreamVoiceManager","config","__publicField","resultData","jsonData","data","str","ws","i","_a","_b","newConfig","message","params","error","websocketUrl","e","isLastFrame","frameBuffer","toBase64","RecorderManager","_data","status","_c"],"mappings":";;;;;;AAMA,IAAIA,IAAa;AAsBjB,MAAMC,IAAQ,YACRC,IAAa,oCACbC,I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,YAAY;AAAA,EAAA;AAAA,EAGnB,qBAAqB;AACnB,SAAK,iBAAiB,IACtB,KAAK,WAAW;AAAA,EAAA;AAAA,EAGlB,UAAU;AACR,SAAK,YAAY,IACjB,WAAW,MAAM;;AACf,QAAID,IAAA,KAAK,eAAL,gBAAAA,EAAiB,gBAAe,UAAU,UAC5CC,IAAA,KAAK,eAAL,QAAAA,EAAiB,WAEnBa,IAAA,KAAK,aAAL,QAAAA,EAAe;AAAA,OACd,GAAI;AAAA,EAAA;AAEX;"}
|
|
@@ -28,3 +28,12 @@ declare class RecorderManagerClass {
|
|
|
28
28
|
stop(): void;
|
|
29
29
|
}
|
|
30
30
|
export { RecorderManagerClass };
|
|
31
|
+
export interface OnMessageInfo {
|
|
32
|
+
/** 优化后的结果。最终结果 */
|
|
33
|
+
message: string;
|
|
34
|
+
isLatest?: boolean;
|
|
35
|
+
/** 临时结果
|
|
36
|
+
* 区别: 如用户再说 “一二三四五”, 临时结果为 “一、二、三、四、五”,最终结果会优化成阿拉伯数字 “12345
|
|
37
|
+
*/
|
|
38
|
+
tempMessage: string;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processor.worklet.es.js","sources":["../../../../src/utils/xunFeiVoice/RecorderManager/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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