@easyv/biz-components 0.0.13 → 0.0.15
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/hooks/index.d.ts +1 -0
- package/dist/hooks/useXunFeiSteamVoiceManager.d.ts +8 -0
- package/dist/hooks/useXunFeiSteamVoiceManager.es.js +15 -0
- package/dist/hooks/useXunFeiSteamVoiceManager.es.js.map +1 -0
- package/dist/index.es.js +10 -6
- package/dist/index.es.js.map +1 -1
- package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager-draft.d.ts +38 -0
- package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager.d.ts +47 -0
- package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager.es.js +121 -0
- package/dist/utils/xunFeiVoice/RecorderManager/RecorderManager.es.js.map +1 -0
- package/dist/utils/xunFeiVoice/RecorderManager/index.d.ts +1 -0
- package/dist/utils/xunFeiVoice/RecorderManager/processor.worklet.d.ts +0 -0
- package/dist/utils/xunFeiVoice/RecorderManager/processor.worklet.es.js +379 -0
- package/dist/utils/xunFeiVoice/RecorderManager/processor.worklet.es.js.map +1 -0
- package/dist/utils/xunFeiVoice/{xunFeiStreamVoiceManager.d.ts → XunFeiStreamVoiceManager.d.ts} +15 -5
- package/dist/utils/xunFeiVoice/XunFeiStreamVoiceManager.es.js +165 -0
- package/dist/utils/xunFeiVoice/XunFeiStreamVoiceManager.es.js.map +1 -0
- package/dist/utils/xunFeiVoice/index.d.ts +2 -1
- package/dist/utils/xunFeiVoice/test/RecorderManager.cy.d.ts +1 -0
- package/dist/utils/xunFeiVoice/test/XunFeiVoiceManager.cy.d.ts +1 -0
- package/dist/utils/xunFeiVoice/types.d.ts +2 -2
- package/dist/utils/xunFeiVoice/utils.d.ts +0 -1
- package/dist/utils/xunFeiVoice/utils.es.js.map +1 -1
- package/package.json +4 -2
- package/dist/utils/xunFeiVoice/recordManager.es.js +0 -175
- package/dist/utils/xunFeiVoice/recordManager.es.js.map +0 -1
- package/dist/utils/xunFeiVoice/xunFeiStreamVoiceManager.es.js +0 -140
- package/dist/utils/xunFeiVoice/xunFeiStreamVoiceManager.es.js.map +0 -1
- /package/dist/utils/xunFeiVoice/{recordManager.d.ts → RecorderManager/RecordManager-origin.d.ts} +0 -0
package/dist/hooks/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { XunFeiStreamVoiceManager, XunFeiStreamVoiceManagerConfig } from '../utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 讯飞流式语音识别的 hook,注意 config 只在初识化时注册一次,后续更改,请使用 manager.setConfig 方法更新
|
|
5
|
+
* @param config XunFeiStreamVoiceManagerConfig
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const useXunFeiSteamVoiceManager: (config: XunFeiStreamVoiceManagerConfig) => XunFeiStreamVoiceManager | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useState as o, useEffect as a } from "react";
|
|
2
|
+
import { XunFeiStreamVoiceManager as s } from "../utils/xunFeiVoice/XunFeiStreamVoiceManager.es.js";
|
|
3
|
+
const c = (t) => {
|
|
4
|
+
const [r, n] = o(null);
|
|
5
|
+
return a(() => {
|
|
6
|
+
const e = new s(t);
|
|
7
|
+
return n(e), () => {
|
|
8
|
+
e == null || e.destroy();
|
|
9
|
+
};
|
|
10
|
+
}, []), r;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
c as useXunFeiSteamVoiceManager
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=useXunFeiSteamVoiceManager.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useXunFeiSteamVoiceManager.es.js","sources":["../../src/hooks/useXunFeiSteamVoiceManager.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { XunFeiStreamVoiceManager, XunFeiStreamVoiceManagerConfig } from '@/utils';\n\n/**\n * 讯飞流式语音识别的 hook,注意 config 只在初识化时注册一次,后续更改,请使用 manager.setConfig 方法更新\n * @param config XunFeiStreamVoiceManagerConfig\n * @returns\n */\nexport const useXunFeiSteamVoiceManager = (config: XunFeiStreamVoiceManagerConfig) => {\n const [manager, setManager] = useState<XunFeiStreamVoiceManager | null>(null);\n\n useEffect(() => {\n const newManager = new XunFeiStreamVoiceManager(config);\n setManager(newManager);\n return () => {\n newManager?.destroy();\n };\n }, []);\n return manager;\n};\n"],"names":["useXunFeiSteamVoiceManager","config","manager","setManager","useState","useEffect","newManager","XunFeiStreamVoiceManager"],"mappings":";;AAQa,MAAAA,IAA6B,CAACC,MAA2C;AACpF,QAAM,CAACC,GAASC,CAAU,IAAIC,EAA0C,IAAI;AAE5E,SAAAC,EAAU,MAAM;AACR,UAAAC,IAAa,IAAIC,EAAyBN,CAAM;AACtD,WAAAE,EAAWG,CAAU,GACd,MAAM;AACX,MAAAA,KAAA,QAAAA,EAAY;AAAA,IACd;AAAA,EACF,GAAG,EAAE,GACEJ;AACT;"}
|
package/dist/index.es.js
CHANGED
|
@@ -3,17 +3,21 @@ import { AiMessageRender as t } from "./components/AiMessageRender/AiMessageRend
|
|
|
3
3
|
import { ShadowDom as n } from "./components/ShadowDom/ShadowDom.es.js";
|
|
4
4
|
import { ScrollController as i } from "./components/ScrollController/ScrollController.es.js";
|
|
5
5
|
import { VoiceAnimation as f } from "./components/VoiceAnimation/VoiceAnimation.es.js";
|
|
6
|
-
import { useDivAutoScroll as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { useDivAutoScroll as c } from "./hooks/useDivAutoScroll.es.js";
|
|
7
|
+
import { useXunFeiSteamVoiceManager as u } from "./hooks/useXunFeiSteamVoiceManager.es.js";
|
|
8
|
+
import { FunASRManager as l, getWebSocketConnectForFunASR as A } from "./utils/funASR/funASRManager.es.js";
|
|
9
|
+
import { XunFeiStreamVoiceManager as M } from "./utils/xunFeiVoice/XunFeiStreamVoiceManager.es.js";
|
|
10
|
+
import { RecorderManager as R } from "./utils/xunFeiVoice/RecorderManager/RecorderManager.es.js";
|
|
9
11
|
export {
|
|
10
12
|
t as AiMessageRender,
|
|
11
13
|
l as FunASRManager,
|
|
14
|
+
R as RecorderManager,
|
|
12
15
|
i as ScrollController,
|
|
13
16
|
n as ShadowDom,
|
|
14
17
|
f as VoiceAnimation,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
M as XunFeiStreamVoiceManager,
|
|
19
|
+
A as getWebSocketConnectForFunASR,
|
|
20
|
+
c as useDivAutoScroll,
|
|
21
|
+
u as useXunFeiSteamVoiceManager
|
|
18
22
|
};
|
|
19
23
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RecordFrameInfo } from '../types';
|
|
2
|
+
|
|
3
|
+
export interface RecorderManagerConfig {
|
|
4
|
+
/** 需要传入 一个 AudioWorklet 脚本,应用到 audioContext.audioWorklet.addModule(workletJsPath).
|
|
5
|
+
* AudioWorklet 运行在 Web Audio API 的 AudioWorklet 环境中,延迟更低,更适合实时音频处理。 */
|
|
6
|
+
workletJsPath: string;
|
|
7
|
+
/** 传入一个 一个 Web Worker 脚本。
|
|
8
|
+
* 用于后台对音频数据的处理。
|
|
9
|
+
*/
|
|
10
|
+
workerJsPath?: string;
|
|
11
|
+
onStop?: (audioBuffers: ArrayBuffer[]) => void;
|
|
12
|
+
onFrameRecorded?: (params: RecordFrameInfo) => void;
|
|
13
|
+
/**
|
|
14
|
+
* 监听录音开始事件
|
|
15
|
+
*/
|
|
16
|
+
onStart?: () => void;
|
|
17
|
+
onError?: (error: string) => void;
|
|
18
|
+
}
|
|
19
|
+
export interface startConfig {
|
|
20
|
+
toSampleRate?: number;
|
|
21
|
+
fromSampleRate?: number;
|
|
22
|
+
frameSize?: number;
|
|
23
|
+
arrayBufferType?: 'short16' | 'float32';
|
|
24
|
+
}
|
|
25
|
+
export declare class RecorderManager {
|
|
26
|
+
config: RecorderManagerConfig;
|
|
27
|
+
audioContext: AudioContext | null;
|
|
28
|
+
audioSource: MediaStreamAudioSourceNode | undefined;
|
|
29
|
+
workletNode: AudioWorkletNode | undefined;
|
|
30
|
+
status: 'beforeInit' | 'initialized' | 'start' | 'stop';
|
|
31
|
+
audioChunks: any[];
|
|
32
|
+
constructor(config: RecorderManagerConfig);
|
|
33
|
+
setConfig: (newConfig: Partial<RecorderManagerConfig>) => void;
|
|
34
|
+
resetAudioContext: () => Promise<void>;
|
|
35
|
+
start: (config: startConfig) => Promise<void>;
|
|
36
|
+
stop: () => void;
|
|
37
|
+
getAudioUrl: () => string;
|
|
38
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 录音管理器
|
|
3
|
+
*/
|
|
4
|
+
export class RecorderManager {
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} processorPath 音频处理器路径
|
|
7
|
+
*/
|
|
8
|
+
constructor(processorPath: string);
|
|
9
|
+
/** @type {Array<ArrayBuffer>} */
|
|
10
|
+
audioBuffers: Array<ArrayBuffer>;
|
|
11
|
+
/** @type {(params: RecordFrameInfo) => void} */
|
|
12
|
+
onFrameRecorded: (params: RecordFrameInfo) => void;
|
|
13
|
+
onStart: () => void;
|
|
14
|
+
/** @type {(data: Array<ArrayBuffer>) => void} */
|
|
15
|
+
onStop: (data: Array<ArrayBuffer>) => void;
|
|
16
|
+
processorPath: string;
|
|
17
|
+
/**
|
|
18
|
+
* 开始录音
|
|
19
|
+
* @param {{
|
|
20
|
+
* sampleRate?: number,
|
|
21
|
+
* frameSize?: number,
|
|
22
|
+
* arrayBufferType?: string
|
|
23
|
+
* }} config 录音配置
|
|
24
|
+
*/
|
|
25
|
+
start(config: {
|
|
26
|
+
sampleRate?: number;
|
|
27
|
+
frameSize?: number;
|
|
28
|
+
arrayBufferType?: string;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
audioWorkletNode: AudioWorkletNode | {
|
|
31
|
+
port: Worker;
|
|
32
|
+
} | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* 创建音频上下文
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
private createAudioContext;
|
|
38
|
+
/**
|
|
39
|
+
* 配置音频处理管线
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private setupAudioProcessing;
|
|
43
|
+
mediaSource: any;
|
|
44
|
+
/** 停止录音 */
|
|
45
|
+
stop(): void;
|
|
46
|
+
close(): any;
|
|
47
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var w = Object.defineProperty;
|
|
2
|
+
var S = (r, e, t) => e in r ? w(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var c = (r, e, t) => S(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import g from "../../../node_modules/.pnpm/co-web-worker@1.0.1/node_modules/co-web-worker/index.es.js";
|
|
5
|
+
import y from "./processor.worklet.es.js";
|
|
6
|
+
const { AudioWorkletNode: h } = window, u = !!h;
|
|
7
|
+
async function R() {
|
|
8
|
+
const r = navigator.mediaDevices ?? {};
|
|
9
|
+
if (typeof r.getUserMedia == "function")
|
|
10
|
+
return r.getUserMedia({ audio: !0, video: !1 });
|
|
11
|
+
if (typeof navigator.getUserMedia == "function")
|
|
12
|
+
return new Promise((e, t) => {
|
|
13
|
+
navigator.getUserMedia({ audio: !0, video: !1 }, e, t);
|
|
14
|
+
});
|
|
15
|
+
throw new Error("浏览器不支持录音!");
|
|
16
|
+
}
|
|
17
|
+
const k = () => {
|
|
18
|
+
const r = new Blob([y], { type: "application/javascript" });
|
|
19
|
+
return URL.createObjectURL(r);
|
|
20
|
+
};
|
|
21
|
+
async function M(r, e) {
|
|
22
|
+
return u ? (await r.audioWorklet.addModule(k()), new h(r, "processor-worklet")) : { port: new g(`${e}/processor.worker.js`) };
|
|
23
|
+
}
|
|
24
|
+
const d = () => {
|
|
25
|
+
};
|
|
26
|
+
class C {
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} processorPath 音频处理器路径
|
|
29
|
+
*/
|
|
30
|
+
constructor(e) {
|
|
31
|
+
/** @type {Array<ArrayBuffer>} */
|
|
32
|
+
c(this, "audioBuffers", []);
|
|
33
|
+
/** @type {(params: RecordFrameInfo) => void} */
|
|
34
|
+
c(this, "onFrameRecorded", d);
|
|
35
|
+
c(this, "onStart", d);
|
|
36
|
+
/** @type {(data: Array<ArrayBuffer>) => void} */
|
|
37
|
+
c(this, "onStop", d);
|
|
38
|
+
this.processorPath = e;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 开始录音
|
|
42
|
+
* @param {{
|
|
43
|
+
* sampleRate?: number,
|
|
44
|
+
* frameSize?: number,
|
|
45
|
+
* arrayBufferType?: string
|
|
46
|
+
* }} config 录音配置
|
|
47
|
+
*/
|
|
48
|
+
async start(e) {
|
|
49
|
+
var t, s;
|
|
50
|
+
try {
|
|
51
|
+
this.audioBuffers = [];
|
|
52
|
+
const o = await R(), a = this.createAudioContext(o, e.sampleRate);
|
|
53
|
+
this.audioWorkletNode = await M(a, this.processorPath), this.setupAudioProcessing(a, o, this.audioWorkletNode, e), (t = this.audioContext) == null || t.resume(), (s = this.onStart) == null || s.call(this);
|
|
54
|
+
} catch (o) {
|
|
55
|
+
throw console.error("Failed to start recording:", o), o;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 创建音频上下文
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
createAudioContext(e, t) {
|
|
63
|
+
try {
|
|
64
|
+
const s = new (window.AudioContext || window.webkitAudioContext)({
|
|
65
|
+
sampleRate: t
|
|
66
|
+
});
|
|
67
|
+
return s.createMediaStreamSource(e), s;
|
|
68
|
+
} catch {
|
|
69
|
+
const o = new (window.AudioContext || window.webkitAudioContext)();
|
|
70
|
+
return console.warn(`Using default sample rate: ${o.sampleRate}`), o.createMediaStreamSource(e), o;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 配置音频处理管线
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
setupAudioProcessing(e, t, s, o) {
|
|
78
|
+
const a = e.createMediaStreamSource(t);
|
|
79
|
+
if (this.mediaSource = a, s.port.postMessage({
|
|
80
|
+
type: "init",
|
|
81
|
+
data: {
|
|
82
|
+
frameSize: o.frameSize,
|
|
83
|
+
toSampleRate: o.sampleRate || e.sampleRate,
|
|
84
|
+
fromSampleRate: e.sampleRate,
|
|
85
|
+
arrayBufferType: o.arrayBufferType || "short16"
|
|
86
|
+
}
|
|
87
|
+
}), s.port.onmessage = (n) => {
|
|
88
|
+
var p, f, l, m;
|
|
89
|
+
const { data: i } = n;
|
|
90
|
+
o.frameSize && this.onFrameRecorded && this.onFrameRecorded(i), i.frameBuffer && this.audioBuffers.push(i.frameBuffer), i.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
|
+
}, u)
|
|
92
|
+
a.connect(s);
|
|
93
|
+
else {
|
|
94
|
+
const n = e.createScriptProcessor(0, 1, 1);
|
|
95
|
+
n.onaudioprocess = ({ inputBuffer: i }) => {
|
|
96
|
+
s.port.postMessage({
|
|
97
|
+
type: "message",
|
|
98
|
+
data: i.getChannelData(0)
|
|
99
|
+
});
|
|
100
|
+
}, a.connect(n), n.connect(e.destination);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** 停止录音 */
|
|
104
|
+
stop() {
|
|
105
|
+
var e;
|
|
106
|
+
if ((e = this.audioContext) == null || e.suspend(), !this.audioWorkletNode) {
|
|
107
|
+
console.error("Recorder is not started.");
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.audioWorkletNode && this.audioWorkletNode.port.postMessage({ type: "stop" });
|
|
111
|
+
}
|
|
112
|
+
close() {
|
|
113
|
+
var e, t;
|
|
114
|
+
if (this.audioBuffers = [], ((e = this.audioContext) == null ? void 0 : e.state) !== "closed")
|
|
115
|
+
return (t = this.audioContext) == null ? void 0 : t.close();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
C as RecorderManager
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=RecorderManager.es.js.map
|
|
@@ -0,0 +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([workletJsString], { type: 'application/javascript' });\n const scriptUrl = URL.createObjectURL(blob);\n return scriptUrl;\n};\n\n/**\n * 初始化音频处理器\n * @param {AudioContext} audioContext\n * @param {string} processorPath\n * @returns {Promise<AudioWorkletNode|{port: Worker}>}\n */\nasync function initializeAudioProcessor(audioContext, processorPath) {\n if (isAudioWorkletSupported) {\n await audioContext.audioWorklet.addModule(generateWorkletUrl());\n return new AudioWorkletNode(audioContext, 'processor-worklet');\n }\n\n const worker = new CrossOriginWorker(`${processorPath}/processor.worker.js`);\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 /**\n * @param {string} processorPath 音频处理器路径\n */\n constructor(processorPath) {\n this.processorPath = processorPath;\n }\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, this.processorPath);\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","blob","workletJsString","initializeAudioProcessor","audioContext","processorPath","CrossOriginWorker","NOOP","RecorderManager","__publicField","config","mediaStream","_a","_b","error","targetSampleRate","context","fallbackContext","audioWorkletNode","mediaSource","e","data","_c","_d","scriptProcessor","inputBuffer"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './RecorderManager';
|
|
File without changes
|
|
@@ -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
|