g711-web-stream-player 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +273 -0
- package/dist/index.cjs +492 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +170 -0
- package/dist/index.d.ts +170 -0
- package/dist/index.js +482 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +518 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +16 -0
- package/dist/react.d.ts +16 -0
- package/dist/react.js +516 -0
- package/dist/react.js.map +1 -0
- package/dist/vue.cjs +517 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +17 -0
- package/dist/vue.d.ts +17 -0
- package/dist/vue.js +515 -0
- package/dist/vue.js.map +1 -0
- package/package.json +92 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/** Supported ITU-T G.711 companding variants. */
|
|
2
|
+
type G711CodecType = 'pcma' | 'pcmu';
|
|
3
|
+
/** Decode one G.711 A-law byte to a signed 16-bit PCM sample. */
|
|
4
|
+
declare function decodeALaw(encoded: number): number;
|
|
5
|
+
/** Decode one G.711 μ-law byte to a signed 16-bit PCM sample. */
|
|
6
|
+
declare function decodeMuLaw(encoded: number): number;
|
|
7
|
+
/** Decode a complete G.711 packet into signed 16-bit PCM samples. */
|
|
8
|
+
declare function decodeG711Chunk(data: Uint8Array, codec: G711CodecType): Int16Array;
|
|
9
|
+
/** Convert signed 16-bit PCM into Web Audio's normalized Float32 format. */
|
|
10
|
+
declare function pcm16ToFloat32(pcm: Int16Array): Float32Array;
|
|
11
|
+
/** Decode a G.711 packet directly into samples accepted by the Web Audio API. */
|
|
12
|
+
declare function decodeG711ToFloat32(data: Uint8Array, codec: G711CodecType): Float32Array;
|
|
13
|
+
|
|
14
|
+
interface G711AudioPlayerOptions {
|
|
15
|
+
/** G.711 input rate. Telephony streams normally use 8000 Hz. */
|
|
16
|
+
inputSampleRate?: number;
|
|
17
|
+
/** Maximum queued audio, in milliseconds. */
|
|
18
|
+
bufferDurationMs?: number;
|
|
19
|
+
/** Audio collected before playback starts or resumes after an underflow. */
|
|
20
|
+
prebufferMs?: number;
|
|
21
|
+
/** Old audio discarded when the ring buffer overflows. */
|
|
22
|
+
overflowDropMs?: number;
|
|
23
|
+
/** ScriptProcessor buffer size; must be one of the Web Audio supported sizes. */
|
|
24
|
+
processorBufferSize?: 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384;
|
|
25
|
+
/** Enable Catmull-Rom interpolation instead of linear interpolation. */
|
|
26
|
+
cubicInterpolation?: boolean;
|
|
27
|
+
/** RMS value below which the noise gate closes. Set to 0 to disable it. */
|
|
28
|
+
noiseGateThreshold?: number;
|
|
29
|
+
/** Gain used while the gate is closed, from 0 to 1. */
|
|
30
|
+
noiseGateFloor?: number;
|
|
31
|
+
/** Gate closing speed, from 0 (slow) to 1 (immediate). */
|
|
32
|
+
noiseGateRelease?: number;
|
|
33
|
+
/** High-pass cutoff in hertz. Set to 0 to disable the filter. */
|
|
34
|
+
highpassHz?: number;
|
|
35
|
+
/** High-shelf start frequency. Set to 0 to disable the filter. */
|
|
36
|
+
highshelfHz?: number;
|
|
37
|
+
/** High-shelf gain in dB. */
|
|
38
|
+
highshelfGainDb?: number;
|
|
39
|
+
/** Initial output volume. */
|
|
40
|
+
volume?: number;
|
|
41
|
+
/** Start muted. */
|
|
42
|
+
muted?: boolean;
|
|
43
|
+
/** Emit diagnostic events without logging stream URLs or packet contents. */
|
|
44
|
+
onDiagnostic?: (event: G711DiagnosticEvent) => void;
|
|
45
|
+
}
|
|
46
|
+
interface G711DiagnosticState {
|
|
47
|
+
contextState: AudioContextState | 'not-created';
|
|
48
|
+
muted: boolean;
|
|
49
|
+
volume: number;
|
|
50
|
+
outputSampleRate: number;
|
|
51
|
+
queuedSamples: number;
|
|
52
|
+
queuedMilliseconds: number;
|
|
53
|
+
inputChunkCount: number;
|
|
54
|
+
inputBytes: number;
|
|
55
|
+
processCallbackCount: number;
|
|
56
|
+
underflowCount: number;
|
|
57
|
+
overflowCount: number;
|
|
58
|
+
waitingForBuffer: boolean;
|
|
59
|
+
destroyed: boolean;
|
|
60
|
+
}
|
|
61
|
+
interface G711DiagnosticEvent {
|
|
62
|
+
type: 'initialized' | 'context-state' | 'underflow' | 'overflow' | 'destroyed';
|
|
63
|
+
state: G711DiagnosticState;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Browser G.711 player with jitter buffering, resampling and speech-oriented
|
|
67
|
+
* noise filtering. Create one instance per independently controlled stream.
|
|
68
|
+
*/
|
|
69
|
+
declare class G711AudioPlayer {
|
|
70
|
+
private readonly options;
|
|
71
|
+
private context;
|
|
72
|
+
private gainNode;
|
|
73
|
+
private scriptNode;
|
|
74
|
+
private nodes;
|
|
75
|
+
private outputSampleRate;
|
|
76
|
+
private resampleRatio;
|
|
77
|
+
private sourcePhase;
|
|
78
|
+
private ring;
|
|
79
|
+
private writeIndex;
|
|
80
|
+
private readIndex;
|
|
81
|
+
private gateGain;
|
|
82
|
+
private waitingForBuffer;
|
|
83
|
+
private destroyed;
|
|
84
|
+
private inputChunkCount;
|
|
85
|
+
private inputBytes;
|
|
86
|
+
private processCallbackCount;
|
|
87
|
+
private underflowCount;
|
|
88
|
+
private overflowCount;
|
|
89
|
+
constructor(options?: G711AudioPlayerOptions);
|
|
90
|
+
get isReady(): boolean;
|
|
91
|
+
getDiagnosticState(): G711DiagnosticState;
|
|
92
|
+
/** Initialize Web Audio. Call this from a click/tap handler when possible. */
|
|
93
|
+
init(): void;
|
|
94
|
+
/** Resume an AudioContext suspended by the browser autoplay policy. */
|
|
95
|
+
resume(): Promise<void>;
|
|
96
|
+
/** Decode and enqueue one raw PCMA or PCMU packet. */
|
|
97
|
+
pushChunk(data: Uint8Array, codec: G711CodecType): void;
|
|
98
|
+
/** Smoothly mute or unmute the output. */
|
|
99
|
+
setMuted(muted: boolean): void;
|
|
100
|
+
/** Set output volume in the inclusive range 0..1. */
|
|
101
|
+
setVolume(volume: number): void;
|
|
102
|
+
/** Drop queued audio and rebuild the initial jitter buffer. */
|
|
103
|
+
flush(): void;
|
|
104
|
+
/** Disconnect audio nodes and close the underlying AudioContext. */
|
|
105
|
+
destroy(): void;
|
|
106
|
+
private get readable();
|
|
107
|
+
private get writable();
|
|
108
|
+
private sampleAt;
|
|
109
|
+
private process;
|
|
110
|
+
private applyNoiseGate;
|
|
111
|
+
private cubic;
|
|
112
|
+
private rampGain;
|
|
113
|
+
private emit;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface FlvAudioCallbacks {
|
|
117
|
+
onAudioData?: (data: Uint8Array, codec: G711CodecType, timestamp: number) => void;
|
|
118
|
+
onCodecDetected?: (codec: G711CodecType) => void;
|
|
119
|
+
onUnsupportedAudioFormat?: (soundFormat: number) => void;
|
|
120
|
+
onError?: (error: Error) => void;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Incremental FLV demuxer focused on G.711 audio tags.
|
|
124
|
+
* Feed it arbitrary network chunks; incomplete headers/tags remain buffered.
|
|
125
|
+
*/
|
|
126
|
+
declare class FlvG711Demuxer {
|
|
127
|
+
private readonly callbacks;
|
|
128
|
+
private buffer;
|
|
129
|
+
private headerParsed;
|
|
130
|
+
private detectedCodec;
|
|
131
|
+
private readonly unsupportedFormats;
|
|
132
|
+
constructor(callbacks?: FlvAudioCallbacks);
|
|
133
|
+
append(chunk: Uint8Array): void;
|
|
134
|
+
reset(): void;
|
|
135
|
+
private parse;
|
|
136
|
+
private emitAudio;
|
|
137
|
+
}
|
|
138
|
+
interface FlvAudioExtractorOptions {
|
|
139
|
+
fetch?: typeof fetch;
|
|
140
|
+
requestInit?: Omit<RequestInit, 'signal'>;
|
|
141
|
+
}
|
|
142
|
+
/** Fetch and incrementally demux a live HTTP-FLV stream. */
|
|
143
|
+
declare class FlvAudioExtractor {
|
|
144
|
+
private readonly options;
|
|
145
|
+
private controller;
|
|
146
|
+
private stopped;
|
|
147
|
+
constructor(options?: FlvAudioExtractorOptions);
|
|
148
|
+
start(url: string, callbacks?: FlvAudioCallbacks): Promise<void>;
|
|
149
|
+
stop(): void;
|
|
150
|
+
}
|
|
151
|
+
interface FlvAudioStreamerOptions {
|
|
152
|
+
player?: G711AudioPlayerOptions;
|
|
153
|
+
extractor?: FlvAudioExtractorOptions;
|
|
154
|
+
}
|
|
155
|
+
/** One-step HTTP-FLV → G.711 → Web Audio streaming pipeline. */
|
|
156
|
+
declare class FlvAudioStreamer {
|
|
157
|
+
readonly player: G711AudioPlayer;
|
|
158
|
+
private readonly extractor;
|
|
159
|
+
constructor(options?: FlvAudioStreamerOptions);
|
|
160
|
+
get isReady(): boolean;
|
|
161
|
+
start(url: string, callbacks?: FlvAudioCallbacks): Promise<void>;
|
|
162
|
+
resume(): Promise<void>;
|
|
163
|
+
setMuted(muted: boolean): void;
|
|
164
|
+
setVolume(volume: number): void;
|
|
165
|
+
flush(): void;
|
|
166
|
+
stop(): void;
|
|
167
|
+
destroy(): void;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { type FlvAudioCallbacks, FlvAudioExtractor, type FlvAudioExtractorOptions, FlvAudioStreamer, type FlvAudioStreamerOptions, FlvG711Demuxer, G711AudioPlayer, type G711AudioPlayerOptions, type G711CodecType, type G711DiagnosticEvent, type G711DiagnosticState, decodeALaw, decodeG711Chunk, decodeG711ToFloat32, decodeMuLaw, pcm16ToFloat32 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/** Supported ITU-T G.711 companding variants. */
|
|
2
|
+
type G711CodecType = 'pcma' | 'pcmu';
|
|
3
|
+
/** Decode one G.711 A-law byte to a signed 16-bit PCM sample. */
|
|
4
|
+
declare function decodeALaw(encoded: number): number;
|
|
5
|
+
/** Decode one G.711 μ-law byte to a signed 16-bit PCM sample. */
|
|
6
|
+
declare function decodeMuLaw(encoded: number): number;
|
|
7
|
+
/** Decode a complete G.711 packet into signed 16-bit PCM samples. */
|
|
8
|
+
declare function decodeG711Chunk(data: Uint8Array, codec: G711CodecType): Int16Array;
|
|
9
|
+
/** Convert signed 16-bit PCM into Web Audio's normalized Float32 format. */
|
|
10
|
+
declare function pcm16ToFloat32(pcm: Int16Array): Float32Array;
|
|
11
|
+
/** Decode a G.711 packet directly into samples accepted by the Web Audio API. */
|
|
12
|
+
declare function decodeG711ToFloat32(data: Uint8Array, codec: G711CodecType): Float32Array;
|
|
13
|
+
|
|
14
|
+
interface G711AudioPlayerOptions {
|
|
15
|
+
/** G.711 input rate. Telephony streams normally use 8000 Hz. */
|
|
16
|
+
inputSampleRate?: number;
|
|
17
|
+
/** Maximum queued audio, in milliseconds. */
|
|
18
|
+
bufferDurationMs?: number;
|
|
19
|
+
/** Audio collected before playback starts or resumes after an underflow. */
|
|
20
|
+
prebufferMs?: number;
|
|
21
|
+
/** Old audio discarded when the ring buffer overflows. */
|
|
22
|
+
overflowDropMs?: number;
|
|
23
|
+
/** ScriptProcessor buffer size; must be one of the Web Audio supported sizes. */
|
|
24
|
+
processorBufferSize?: 256 | 512 | 1024 | 2048 | 4096 | 8192 | 16384;
|
|
25
|
+
/** Enable Catmull-Rom interpolation instead of linear interpolation. */
|
|
26
|
+
cubicInterpolation?: boolean;
|
|
27
|
+
/** RMS value below which the noise gate closes. Set to 0 to disable it. */
|
|
28
|
+
noiseGateThreshold?: number;
|
|
29
|
+
/** Gain used while the gate is closed, from 0 to 1. */
|
|
30
|
+
noiseGateFloor?: number;
|
|
31
|
+
/** Gate closing speed, from 0 (slow) to 1 (immediate). */
|
|
32
|
+
noiseGateRelease?: number;
|
|
33
|
+
/** High-pass cutoff in hertz. Set to 0 to disable the filter. */
|
|
34
|
+
highpassHz?: number;
|
|
35
|
+
/** High-shelf start frequency. Set to 0 to disable the filter. */
|
|
36
|
+
highshelfHz?: number;
|
|
37
|
+
/** High-shelf gain in dB. */
|
|
38
|
+
highshelfGainDb?: number;
|
|
39
|
+
/** Initial output volume. */
|
|
40
|
+
volume?: number;
|
|
41
|
+
/** Start muted. */
|
|
42
|
+
muted?: boolean;
|
|
43
|
+
/** Emit diagnostic events without logging stream URLs or packet contents. */
|
|
44
|
+
onDiagnostic?: (event: G711DiagnosticEvent) => void;
|
|
45
|
+
}
|
|
46
|
+
interface G711DiagnosticState {
|
|
47
|
+
contextState: AudioContextState | 'not-created';
|
|
48
|
+
muted: boolean;
|
|
49
|
+
volume: number;
|
|
50
|
+
outputSampleRate: number;
|
|
51
|
+
queuedSamples: number;
|
|
52
|
+
queuedMilliseconds: number;
|
|
53
|
+
inputChunkCount: number;
|
|
54
|
+
inputBytes: number;
|
|
55
|
+
processCallbackCount: number;
|
|
56
|
+
underflowCount: number;
|
|
57
|
+
overflowCount: number;
|
|
58
|
+
waitingForBuffer: boolean;
|
|
59
|
+
destroyed: boolean;
|
|
60
|
+
}
|
|
61
|
+
interface G711DiagnosticEvent {
|
|
62
|
+
type: 'initialized' | 'context-state' | 'underflow' | 'overflow' | 'destroyed';
|
|
63
|
+
state: G711DiagnosticState;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Browser G.711 player with jitter buffering, resampling and speech-oriented
|
|
67
|
+
* noise filtering. Create one instance per independently controlled stream.
|
|
68
|
+
*/
|
|
69
|
+
declare class G711AudioPlayer {
|
|
70
|
+
private readonly options;
|
|
71
|
+
private context;
|
|
72
|
+
private gainNode;
|
|
73
|
+
private scriptNode;
|
|
74
|
+
private nodes;
|
|
75
|
+
private outputSampleRate;
|
|
76
|
+
private resampleRatio;
|
|
77
|
+
private sourcePhase;
|
|
78
|
+
private ring;
|
|
79
|
+
private writeIndex;
|
|
80
|
+
private readIndex;
|
|
81
|
+
private gateGain;
|
|
82
|
+
private waitingForBuffer;
|
|
83
|
+
private destroyed;
|
|
84
|
+
private inputChunkCount;
|
|
85
|
+
private inputBytes;
|
|
86
|
+
private processCallbackCount;
|
|
87
|
+
private underflowCount;
|
|
88
|
+
private overflowCount;
|
|
89
|
+
constructor(options?: G711AudioPlayerOptions);
|
|
90
|
+
get isReady(): boolean;
|
|
91
|
+
getDiagnosticState(): G711DiagnosticState;
|
|
92
|
+
/** Initialize Web Audio. Call this from a click/tap handler when possible. */
|
|
93
|
+
init(): void;
|
|
94
|
+
/** Resume an AudioContext suspended by the browser autoplay policy. */
|
|
95
|
+
resume(): Promise<void>;
|
|
96
|
+
/** Decode and enqueue one raw PCMA or PCMU packet. */
|
|
97
|
+
pushChunk(data: Uint8Array, codec: G711CodecType): void;
|
|
98
|
+
/** Smoothly mute or unmute the output. */
|
|
99
|
+
setMuted(muted: boolean): void;
|
|
100
|
+
/** Set output volume in the inclusive range 0..1. */
|
|
101
|
+
setVolume(volume: number): void;
|
|
102
|
+
/** Drop queued audio and rebuild the initial jitter buffer. */
|
|
103
|
+
flush(): void;
|
|
104
|
+
/** Disconnect audio nodes and close the underlying AudioContext. */
|
|
105
|
+
destroy(): void;
|
|
106
|
+
private get readable();
|
|
107
|
+
private get writable();
|
|
108
|
+
private sampleAt;
|
|
109
|
+
private process;
|
|
110
|
+
private applyNoiseGate;
|
|
111
|
+
private cubic;
|
|
112
|
+
private rampGain;
|
|
113
|
+
private emit;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface FlvAudioCallbacks {
|
|
117
|
+
onAudioData?: (data: Uint8Array, codec: G711CodecType, timestamp: number) => void;
|
|
118
|
+
onCodecDetected?: (codec: G711CodecType) => void;
|
|
119
|
+
onUnsupportedAudioFormat?: (soundFormat: number) => void;
|
|
120
|
+
onError?: (error: Error) => void;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Incremental FLV demuxer focused on G.711 audio tags.
|
|
124
|
+
* Feed it arbitrary network chunks; incomplete headers/tags remain buffered.
|
|
125
|
+
*/
|
|
126
|
+
declare class FlvG711Demuxer {
|
|
127
|
+
private readonly callbacks;
|
|
128
|
+
private buffer;
|
|
129
|
+
private headerParsed;
|
|
130
|
+
private detectedCodec;
|
|
131
|
+
private readonly unsupportedFormats;
|
|
132
|
+
constructor(callbacks?: FlvAudioCallbacks);
|
|
133
|
+
append(chunk: Uint8Array): void;
|
|
134
|
+
reset(): void;
|
|
135
|
+
private parse;
|
|
136
|
+
private emitAudio;
|
|
137
|
+
}
|
|
138
|
+
interface FlvAudioExtractorOptions {
|
|
139
|
+
fetch?: typeof fetch;
|
|
140
|
+
requestInit?: Omit<RequestInit, 'signal'>;
|
|
141
|
+
}
|
|
142
|
+
/** Fetch and incrementally demux a live HTTP-FLV stream. */
|
|
143
|
+
declare class FlvAudioExtractor {
|
|
144
|
+
private readonly options;
|
|
145
|
+
private controller;
|
|
146
|
+
private stopped;
|
|
147
|
+
constructor(options?: FlvAudioExtractorOptions);
|
|
148
|
+
start(url: string, callbacks?: FlvAudioCallbacks): Promise<void>;
|
|
149
|
+
stop(): void;
|
|
150
|
+
}
|
|
151
|
+
interface FlvAudioStreamerOptions {
|
|
152
|
+
player?: G711AudioPlayerOptions;
|
|
153
|
+
extractor?: FlvAudioExtractorOptions;
|
|
154
|
+
}
|
|
155
|
+
/** One-step HTTP-FLV → G.711 → Web Audio streaming pipeline. */
|
|
156
|
+
declare class FlvAudioStreamer {
|
|
157
|
+
readonly player: G711AudioPlayer;
|
|
158
|
+
private readonly extractor;
|
|
159
|
+
constructor(options?: FlvAudioStreamerOptions);
|
|
160
|
+
get isReady(): boolean;
|
|
161
|
+
start(url: string, callbacks?: FlvAudioCallbacks): Promise<void>;
|
|
162
|
+
resume(): Promise<void>;
|
|
163
|
+
setMuted(muted: boolean): void;
|
|
164
|
+
setVolume(volume: number): void;
|
|
165
|
+
flush(): void;
|
|
166
|
+
stop(): void;
|
|
167
|
+
destroy(): void;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { type FlvAudioCallbacks, FlvAudioExtractor, type FlvAudioExtractorOptions, FlvAudioStreamer, type FlvAudioStreamerOptions, FlvG711Demuxer, G711AudioPlayer, type G711AudioPlayerOptions, type G711CodecType, type G711DiagnosticEvent, type G711DiagnosticState, decodeALaw, decodeG711Chunk, decodeG711ToFloat32, decodeMuLaw, pcm16ToFloat32 };
|