-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
101 lines (90 loc) · 2.7 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
declare interface AudioRecord {
new(samples: Float32Array, sampleRate: number): AudioRecordInstance;
}
declare interface AudioRecordInstance {
samples: Float32Array;
sampleRate: number;
setSampleRate(value: number): void;
getSampleRate(): number;
getLength(): number;
getDuration(): number;
getSamples(): Float32Array;
lTrim(duration?: number): void;
rTrim(duration?: number): void;
clear(): void;
play(): void;
getBlob(): Blob;
getWAVE(): Blob;
getObjectURL(): string;
download(fileName?: string): void;
getAudioElement(): HTMLAudioElement;
writeString(dataview: DataView, offset: number, str: string): void;
}
declare interface RecordProcessorConfig {
autoStart?: boolean;
autoStop?: boolean;
bufferSize?: 0 | 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384;
timeLimit?: number;
onSaturate?: "none" | "cancel" | "discard";
saturationThreshold?: number;
startThreshold?: number;
stopThreshold?: number;
stopDuration?: number;
marginBefore?: number;
marginAfter?: number;
minDuration?: number;
}
declare enum STATE {
"recording",
"listening",
"paused",
"stop",
}
declare enum EVENT {
"ready",
"readyFail",
"started",
"listening",
"recording",
"saturated",
"paused",
"stopped",
"canceled"
}
declare interface LinguaRecorder {
new(recordProcessorConfig?: RecordProcessorConfig): LinguaRecorderInstance;
}
declare interface LinguaRecorderInstance {
stream: MediaStream | null;
audioContext: AudioContext | null;
audioInput: MediaStreamAudioSourceNode | null;
processor: AudioWorkletNode | null;
recordProcessorConfig: RecordProcessorConfig;
_isConnected: boolean;
_extraAudioNodes: AudioNode[];
_eventHandlers: { [key in EVENT]?: ((value?: any) => void)[] };
_eventStorage: { [key in "ready" | "readyFail"]?: any };
_state: STATE;
_duration: number;
setConfig(config: object): LinguaRecorderInstance;
getRecordingTime(): number;
getState(): STATE;
getAudioContext(): AudioContext | null;
start(): LinguaRecorderInstance;
pause(): LinguaRecorderInstance;
stop(): LinguaRecorderInstance;
cancel(): LinguaRecorderInstance;
toggle(): LinguaRecorderInstance;
resume(): LinguaRecorderInstance;
on(event: string, handler: (value?: any) => void): LinguaRecorderInstance;
off(event: string, handler?: (value?: any) => void): LinguaRecorderInstance;
connectAudioNode(node: AudioNode): LinguaRecorderInstance;
disconnectAudioNode(node: AudioNode): LinguaRecorderInstance;
close(): LinguaRecorderInstance | undefined;
_sendCommandToProcessor(command: string, extra?: any): LinguaRecorderInstance;
_fire(event: string, value?: any): void;
_getAudioStream(): Promise<void>;
_initStream(): Promise<void>;
_connect(): void;
_disconnect(): void;
}