echogarden 2.5.2 → 2.7.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/data/lexicons/heteronyms.en.json +39 -5
- package/data/lexicons/words.en.json +1336 -1470
- package/dist/api/SourceSeparation.js +1 -1
- package/dist/audio/AudioBufferConversion.d.ts +5 -6
- package/dist/audio/AudioBufferConversion.js +16 -248
- package/dist/audio/AudioBufferConversion.js.map +1 -1
- package/dist/audio/AudioPlayer.js.map +1 -1
- package/dist/audio/AudioRecorder.js +1 -1
- package/dist/audio/AudioRecorder.js.map +1 -1
- package/dist/audio/AudioUtilities.d.ts +3 -9
- package/dist/audio/AudioUtilities.js +4 -3
- package/dist/audio/AudioUtilities.js.map +1 -1
- package/dist/codecs/FFMpegTranscoder.d.ts +1 -4
- package/dist/codecs/TIMITCodec.js +1 -2
- package/dist/codecs/TIMITCodec.js.map +1 -1
- package/dist/encodings/Ascii.js +1 -1
- package/dist/encodings/Ascii.js.map +1 -1
- package/dist/encodings/Utf16.js +1 -1
- package/dist/encodings/Utf16.js.map +1 -1
- package/dist/encodings/Utf8.js +1 -1
- package/dist/encodings/Utf8.js.map +1 -1
- package/dist/math/VectorMath.js +8 -7
- package/dist/math/VectorMath.js.map +1 -1
- package/dist/nlp/CompromiseNLP.js +4 -1
- package/dist/nlp/CompromiseNLP.js.map +1 -1
- package/dist/nlp/Lexicon.d.ts +1 -1
- package/dist/nlp/Lexicon.js +4 -1
- package/dist/nlp/Lexicon.js.map +1 -1
- package/dist/nlp/PhoneConversion.js +17 -5
- package/dist/nlp/PhoneConversion.js.map +1 -1
- package/dist/recognition/WhisperCppSTT.js +6 -3
- package/dist/recognition/WhisperCppSTT.js.map +1 -1
- package/dist/recognition/WhisperSTT.js +18 -17
- package/dist/recognition/WhisperSTT.js.map +1 -1
- package/dist/synthesis/AwsPollyTTS.d.ts +1 -4
- package/dist/synthesis/CoquiServerTTS.d.ts +1 -4
- package/dist/synthesis/DeepgramTTS.d.ts +1 -4
- package/dist/synthesis/ElevenLabsTTS.d.ts +1 -4
- package/dist/synthesis/FliteTTS.d.ts +1 -4
- package/dist/synthesis/GnuSpeechTTS.d.ts +1 -7
- package/dist/synthesis/GoogleCloudTTS.d.ts +1 -4
- package/dist/synthesis/SapiTTS.js +1 -2
- package/dist/synthesis/SapiTTS.js.map +1 -1
- package/dist/synthesis/SvoxPicoTTS.js +1 -2
- package/dist/synthesis/SvoxPicoTTS.js.map +1 -1
- package/dist/utilities/PackageManager.js +4 -3
- package/dist/utilities/PackageManager.js.map +1 -1
- package/dist/utilities/StringUtilities.d.ts +2 -2
- package/dist/utilities/StringUtilities.js +7 -7
- package/dist/utilities/StringUtilities.js.map +1 -1
- package/dist/utilities/Utilities.d.ts +1 -0
- package/dist/utilities/Utilities.js +48 -0
- package/dist/utilities/Utilities.js.map +1 -1
- package/dist/utilities/WasmMemoryManager.d.ts +1 -1
- package/docs/Options.md +2 -2
- package/package.json +7 -7
- package/src/api/SourceSeparation.ts +1 -1
- package/src/audio/AudioBufferConversion.ts +17 -263
- package/src/audio/AudioPlayer.ts +1 -1
- package/src/audio/AudioRecorder.ts +1 -1
- package/src/audio/AudioUtilities.ts +5 -3
- package/src/codecs/TIMITCodec.ts +1 -2
- package/src/encodings/Ascii.ts +1 -1
- package/src/encodings/Utf16.ts +1 -1
- package/src/encodings/Utf8.ts +1 -1
- package/src/math/VectorMath.ts +9 -7
- package/src/nlp/CompromiseNLP.ts +5 -1
- package/src/nlp/Lexicon.ts +6 -2
- package/src/nlp/PhoneConversion.ts +20 -6
- package/src/recognition/WhisperCppSTT.ts +5 -3
- package/src/recognition/WhisperSTT.ts +19 -18
- package/src/synthesis/SapiTTS.ts +1 -2
- package/src/synthesis/SvoxPicoTTS.ts +1 -2
- package/src/utilities/PackageManager.ts +4 -3
- package/src/utilities/StringUtilities.ts +7 -7
- package/src/utilities/Utilities.ts +64 -0
- package/dist/codecs/WaveCodec.d.ts +0 -19
- package/dist/codecs/WaveCodec.js +0 -224
- package/dist/codecs/WaveCodec.js.map +0 -1
- package/dist/utilities/BinaryArrayConversion.d.ts +0 -14
- package/dist/utilities/BinaryArrayConversion.js +0 -92
- package/dist/utilities/BinaryArrayConversion.js.map +0 -1
- package/src/codecs/WaveCodec.ts +0 -281
- package/src/utilities/BinaryArrayConversion.ts +0 -117
package/dist/codecs/WaveCodec.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import * as AudioBufferConversion from '../audio/AudioBufferConversion.js';
|
|
2
|
-
import { readUint16LE, readUint32LE, writeAscii, writeUint16LE, writeUint32LE } from '../utilities/BinaryUtilities.js';
|
|
3
|
-
import { encodeHex, decodeHex } from '../encodings/Hex.js';
|
|
4
|
-
import { concatUint8Arrays, logToStderr } from '../utilities/Utilities.js';
|
|
5
|
-
import { decodeAscii } from '../encodings/Ascii.js';
|
|
6
|
-
const log = logToStderr;
|
|
7
|
-
export function encodeWave(rawAudio, bitDepth = 16, sampleFormat = SampleFormat.PCM, speakerPositionMask = 0) {
|
|
8
|
-
const audioChannels = rawAudio.audioChannels;
|
|
9
|
-
const sampleRate = rawAudio.sampleRate;
|
|
10
|
-
const audioBuffer = AudioBufferConversion.encodeToAudioBuffer(audioChannels, bitDepth, sampleFormat);
|
|
11
|
-
const audioDataLength = audioBuffer.length;
|
|
12
|
-
const shouldUseExtensibleFormat = bitDepth > 16 || audioChannels.length > 2;
|
|
13
|
-
const formatSubChunk = new WaveFormat(audioChannels.length, sampleRate, bitDepth, sampleFormat, speakerPositionMask);
|
|
14
|
-
const formatSubChunkBuffer = formatSubChunk.serialize(shouldUseExtensibleFormat);
|
|
15
|
-
const dataSubChunkBuffer = new Uint8Array(4 + 4 + audioDataLength);
|
|
16
|
-
writeAscii(dataSubChunkBuffer, 'data', 0);
|
|
17
|
-
const dataChunkLength = Math.min(audioDataLength, 4294967295); // Ensure large data chunk length is clipped to max
|
|
18
|
-
writeUint32LE(dataSubChunkBuffer, dataChunkLength, 4);
|
|
19
|
-
dataSubChunkBuffer.set(audioBuffer, 8);
|
|
20
|
-
const riffChunkHeaderBuffer = new Uint8Array(12);
|
|
21
|
-
writeAscii(riffChunkHeaderBuffer, 'RIFF', 0);
|
|
22
|
-
const riffChunkLength = Math.min(4 + formatSubChunkBuffer.length + dataSubChunkBuffer.length, 4294967295); // Ensure large RIFF chunk length is clipped to max
|
|
23
|
-
writeUint32LE(riffChunkHeaderBuffer, riffChunkLength, 4);
|
|
24
|
-
writeAscii(riffChunkHeaderBuffer, 'WAVE', 8);
|
|
25
|
-
return concatUint8Arrays([riffChunkHeaderBuffer, formatSubChunkBuffer, dataSubChunkBuffer]);
|
|
26
|
-
}
|
|
27
|
-
export function decodeWave(waveData, ignoreTruncatedChunks = true, ignoreOverflowingDataChunks = true) {
|
|
28
|
-
let readOffset = 0;
|
|
29
|
-
const riffId = decodeAscii(waveData.subarray(readOffset, readOffset + 4));
|
|
30
|
-
if (riffId != 'RIFF') {
|
|
31
|
-
throw new Error('Not a valid wave file. No RIFF id found at offset 0.');
|
|
32
|
-
}
|
|
33
|
-
readOffset += 4;
|
|
34
|
-
let riffChunkSize = readUint32LE(waveData, readOffset);
|
|
35
|
-
readOffset += 4;
|
|
36
|
-
const waveId = decodeAscii(waveData.subarray(readOffset, readOffset + 4));
|
|
37
|
-
if (waveId != 'WAVE') {
|
|
38
|
-
throw new Error('Not a valid wave file. No WAVE id found at offset 8.');
|
|
39
|
-
}
|
|
40
|
-
if (ignoreOverflowingDataChunks && riffChunkSize === 4294967295) {
|
|
41
|
-
riffChunkSize = waveData.length - 8;
|
|
42
|
-
}
|
|
43
|
-
if (riffChunkSize < waveData.length - 8) {
|
|
44
|
-
throw new Error(`RIFF chunk length ${riffChunkSize} is smaller than the remaining size of the buffer (${waveData.length - 8})`);
|
|
45
|
-
}
|
|
46
|
-
if (!ignoreTruncatedChunks && riffChunkSize > waveData.length - 8) {
|
|
47
|
-
throw new Error(`RIFF chunk length (${riffChunkSize}) is greater than the remaining size of the buffer (${waveData.length - 8})`);
|
|
48
|
-
}
|
|
49
|
-
readOffset += 4;
|
|
50
|
-
let formatSubChunkBodyBuffer;
|
|
51
|
-
const dataBuffers = [];
|
|
52
|
-
while (true) {
|
|
53
|
-
const subChunkIdentifier = decodeAscii(waveData.subarray(readOffset, readOffset + 4));
|
|
54
|
-
readOffset += 4;
|
|
55
|
-
let subChunkSize = readUint32LE(waveData, readOffset);
|
|
56
|
-
readOffset += 4;
|
|
57
|
-
if (!ignoreTruncatedChunks && subChunkSize > waveData.length - readOffset) {
|
|
58
|
-
throw new Error(`Encountered a '${subChunkIdentifier}' subchunk with a size of ${subChunkSize} which is greater than the remaining size of the buffer (${waveData.length - readOffset})`);
|
|
59
|
-
}
|
|
60
|
-
if (subChunkIdentifier == 'fmt ') {
|
|
61
|
-
formatSubChunkBodyBuffer = waveData.subarray(readOffset, readOffset + subChunkSize);
|
|
62
|
-
}
|
|
63
|
-
else if (subChunkIdentifier == 'data') {
|
|
64
|
-
if (!formatSubChunkBodyBuffer) {
|
|
65
|
-
throw new Error('A data subchunk was encountered before a format subchunk');
|
|
66
|
-
}
|
|
67
|
-
// If the data chunk is truncated or extended beyond 4 GiB,
|
|
68
|
-
// the data would be read up to the end of the buffer
|
|
69
|
-
if (ignoreOverflowingDataChunks && subChunkSize === 4294967295) {
|
|
70
|
-
subChunkSize = waveData.length - readOffset;
|
|
71
|
-
}
|
|
72
|
-
const subChunkData = waveData.subarray(readOffset, readOffset + subChunkSize);
|
|
73
|
-
dataBuffers.push(subChunkData);
|
|
74
|
-
}
|
|
75
|
-
// All sub chunks other than 'data' (e.g. 'LIST', 'fact', 'plst', 'junk' etc.) are ignored
|
|
76
|
-
// This addition operation may overflow if JavaScript integers were 32 bits,
|
|
77
|
-
// but since they are 52 bits, it is okay:
|
|
78
|
-
readOffset += subChunkSize;
|
|
79
|
-
// Break if readOffset is equal to or is greater than the size of the buffer
|
|
80
|
-
if (readOffset >= waveData.length) {
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (!formatSubChunkBodyBuffer) {
|
|
85
|
-
throw new Error('No format subchunk was found in the wave file');
|
|
86
|
-
}
|
|
87
|
-
if (dataBuffers.length === 0) {
|
|
88
|
-
throw new Error('No data subchunks were found in the wave file');
|
|
89
|
-
}
|
|
90
|
-
const waveFormat = WaveFormat.deserializeFrom(formatSubChunkBodyBuffer);
|
|
91
|
-
const sampleFormat = waveFormat.sampleFormat;
|
|
92
|
-
const channelCount = waveFormat.channelCount;
|
|
93
|
-
const sampleRate = waveFormat.sampleRate;
|
|
94
|
-
const bitDepth = waveFormat.bitDepth;
|
|
95
|
-
const speakerPositionMask = waveFormat.speakerPositionMask;
|
|
96
|
-
const concatenatedDataBuffers = concatUint8Arrays(dataBuffers);
|
|
97
|
-
dataBuffers.length = 0; // Allow the garbage collector to free up memory held by the data buffers
|
|
98
|
-
const audioChannels = AudioBufferConversion.decodeToChannels(concatenatedDataBuffers, channelCount, bitDepth, sampleFormat);
|
|
99
|
-
return {
|
|
100
|
-
rawAudio: { audioChannels, sampleRate },
|
|
101
|
-
sourceSampleFormat: sampleFormat,
|
|
102
|
-
sourceBitDepth: bitDepth,
|
|
103
|
-
sourceSpeakerPositionMask: speakerPositionMask
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
export function repairWave(waveData) {
|
|
107
|
-
const { rawAudio, sourceSampleFormat, sourceBitDepth } = decodeWave(waveData);
|
|
108
|
-
return encodeWave(rawAudio, sourceBitDepth, sourceSampleFormat);
|
|
109
|
-
}
|
|
110
|
-
class WaveFormat {
|
|
111
|
-
sampleFormat; // 2 bytes LE
|
|
112
|
-
channelCount; // 2 bytes LE
|
|
113
|
-
sampleRate; // 4 bytes LE
|
|
114
|
-
get byteRate() { return this.sampleRate * this.bytesPerSample * this.channelCount; } // 4 bytes LE
|
|
115
|
-
get blockAlign() { return this.bytesPerSample * this.channelCount; } // 2 bytes LE
|
|
116
|
-
bitDepth; // 2 bytes LE
|
|
117
|
-
speakerPositionMask; // 4 bytes LE
|
|
118
|
-
get guid() { return sampleFormatToGuid[this.sampleFormat]; } // 16 bytes BE
|
|
119
|
-
// helpers:
|
|
120
|
-
get bytesPerSample() { return this.bitDepth / 8; }
|
|
121
|
-
constructor(channelCount, sampleRate, bitDepth, sampleFormat, speakerPositionMask = 0) {
|
|
122
|
-
this.sampleFormat = sampleFormat;
|
|
123
|
-
this.channelCount = channelCount;
|
|
124
|
-
this.sampleRate = sampleRate;
|
|
125
|
-
this.bitDepth = bitDepth;
|
|
126
|
-
this.speakerPositionMask = speakerPositionMask;
|
|
127
|
-
}
|
|
128
|
-
serialize(useExtensibleFormat) {
|
|
129
|
-
let sampleFormatId = this.sampleFormat;
|
|
130
|
-
if (useExtensibleFormat) {
|
|
131
|
-
sampleFormatId = 65534;
|
|
132
|
-
}
|
|
133
|
-
const serializedSize = sampleFormatToSerializedSize[sampleFormatId];
|
|
134
|
-
const result = new Uint8Array(serializedSize);
|
|
135
|
-
writeAscii(result, 'fmt ', 0); // + 4
|
|
136
|
-
writeUint32LE(result, serializedSize - 8, 4); // + 4
|
|
137
|
-
writeUint16LE(result, sampleFormatId, 8); // + 2
|
|
138
|
-
writeUint16LE(result, this.channelCount, 10); // + 2
|
|
139
|
-
writeUint32LE(result, this.sampleRate, 12); // + 4
|
|
140
|
-
writeUint32LE(result, this.byteRate, 16); // + 4
|
|
141
|
-
writeUint16LE(result, this.blockAlign, 20); // + 2
|
|
142
|
-
writeUint16LE(result, this.bitDepth, 22); // + 2
|
|
143
|
-
if (useExtensibleFormat) {
|
|
144
|
-
writeUint16LE(result, serializedSize - 26, 24); // + 2 (extension size)
|
|
145
|
-
writeUint16LE(result, this.bitDepth, 26); // + 2 (valid bits per sample)
|
|
146
|
-
writeUint32LE(result, this.speakerPositionMask, 28); // + 2 (speaker position mask)
|
|
147
|
-
if (this.sampleFormat == SampleFormat.PCM || this.sampleFormat == SampleFormat.Float) {
|
|
148
|
-
result.set(decodeHex(this.guid), 32);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
throw new Error(`Extensible format is not supported for sample format ${this.sampleFormat}`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return result;
|
|
155
|
-
}
|
|
156
|
-
static deserializeFrom(formatChunkBody) {
|
|
157
|
-
let sampleFormat = readUint16LE(formatChunkBody, 0); // + 2
|
|
158
|
-
const channelCount = readUint16LE(formatChunkBody, 2); // + 2
|
|
159
|
-
const sampleRate = readUint32LE(formatChunkBody, 4); // + 4
|
|
160
|
-
const bitDepth = readUint16LE(formatChunkBody, 14);
|
|
161
|
-
let speakerPositionMask = 0;
|
|
162
|
-
if (sampleFormat == 65534) {
|
|
163
|
-
if (formatChunkBody.length < 40) {
|
|
164
|
-
throw new Error(`Format subchunk specifies a format id of 65534 (extensible) but its body size is ${formatChunkBody.length} bytes, which is smaller than the minimum expected of 40 bytes`);
|
|
165
|
-
}
|
|
166
|
-
speakerPositionMask = readUint16LE(formatChunkBody, 20);
|
|
167
|
-
const guid = encodeHex(formatChunkBody.subarray(24, 40));
|
|
168
|
-
if (guid == sampleFormatToGuid[SampleFormat.PCM]) {
|
|
169
|
-
sampleFormat = SampleFormat.PCM;
|
|
170
|
-
}
|
|
171
|
-
else if (guid == sampleFormatToGuid[SampleFormat.Float]) {
|
|
172
|
-
sampleFormat = SampleFormat.Float;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
throw new Error(`Unsupported format GUID in extended format subchunk: ${guid}`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (sampleFormat == SampleFormat.PCM) {
|
|
179
|
-
if (bitDepth != 8 && bitDepth != 16 && bitDepth != 24 && bitDepth != 32) {
|
|
180
|
-
throw new Error(`PCM audio has a bit depth of ${bitDepth}, which is not supported`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
else if (sampleFormat == SampleFormat.Float) {
|
|
184
|
-
if (bitDepth != 32 && bitDepth != 64) {
|
|
185
|
-
throw new Error(`IEEE float audio has a bit depth of ${bitDepth}, which is not supported`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
else if (sampleFormat == SampleFormat.Alaw) {
|
|
189
|
-
if (bitDepth != 8) {
|
|
190
|
-
throw new Error(`Alaw audio has a bit depth of ${bitDepth}, which is not supported`);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else if (sampleFormat == SampleFormat.Mulaw) {
|
|
194
|
-
if (bitDepth != 8) {
|
|
195
|
-
throw new Error(`Mulaw audio has a bit depth of ${bitDepth}, which is not supported`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
throw new Error(`Wave audio format id ${sampleFormat} is not supported`);
|
|
200
|
-
}
|
|
201
|
-
return new WaveFormat(channelCount, sampleRate, bitDepth, sampleFormat, speakerPositionMask);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
export var SampleFormat;
|
|
205
|
-
(function (SampleFormat) {
|
|
206
|
-
SampleFormat[SampleFormat["PCM"] = 1] = "PCM";
|
|
207
|
-
SampleFormat[SampleFormat["Float"] = 3] = "Float";
|
|
208
|
-
SampleFormat[SampleFormat["Alaw"] = 6] = "Alaw";
|
|
209
|
-
SampleFormat[SampleFormat["Mulaw"] = 7] = "Mulaw";
|
|
210
|
-
})(SampleFormat || (SampleFormat = {}));
|
|
211
|
-
const sampleFormatToSerializedSize = {
|
|
212
|
-
[SampleFormat.PCM]: 24,
|
|
213
|
-
[SampleFormat.Float]: 26,
|
|
214
|
-
[SampleFormat.Alaw]: 26,
|
|
215
|
-
[SampleFormat.Mulaw]: 26,
|
|
216
|
-
65534: 48
|
|
217
|
-
};
|
|
218
|
-
const sampleFormatToGuid = {
|
|
219
|
-
[SampleFormat.PCM]: '0100000000001000800000aa00389b71',
|
|
220
|
-
[SampleFormat.Float]: '0300000000001000800000aa00389b71',
|
|
221
|
-
[SampleFormat.Alaw]: '',
|
|
222
|
-
[SampleFormat.Mulaw]: '',
|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|
-
export declare function int8ToBuffer(int8s: Int8Array): Uint8Array<ArrayBufferLike>;
|
|
2
|
-
export declare function bufferToInt8(buffer: Uint8Array): Int8Array<ArrayBufferLike>;
|
|
3
|
-
export declare function int16ToBufferLE(int16s: Int16Array): Uint8Array<ArrayBufferLike>;
|
|
4
|
-
export declare function bufferLEToInt16(buffer: Uint8Array): Int16Array<ArrayBufferLike>;
|
|
5
|
-
export declare function int24ToBufferLE(int24s: Int32Array): Uint8Array<ArrayBuffer>;
|
|
6
|
-
export declare function bufferLEToInt24(buffer: Uint8Array): Int32Array<ArrayBuffer>;
|
|
7
|
-
export declare function int32ToBufferLE(int32s: Int32Array): Uint8Array<ArrayBufferLike>;
|
|
8
|
-
export declare function bufferLEToInt32(buffer: Uint8Array): Int32Array<ArrayBufferLike>;
|
|
9
|
-
export declare function float32ToBufferLE(float32s: Float32Array): Uint8Array<ArrayBufferLike>;
|
|
10
|
-
export declare function bufferLEToFloat32(buffer: Uint8Array): Float32Array<ArrayBufferLike>;
|
|
11
|
-
export declare function float64ToBufferLE(float64s: Float64Array): Uint8Array<ArrayBufferLike>;
|
|
12
|
-
export declare function bufferLEToFloat64(buffer: Uint8Array): Float64Array<ArrayBufferLike>;
|
|
13
|
-
export declare function float64Tofloat32(float64s: Float64Array): Float32Array<ArrayBuffer>;
|
|
14
|
-
export declare function float32Tofloat64(float32s: Float32Array): Float64Array<ArrayBuffer>;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// Typed arrays to Uint8Array buffers (little endian) conversions
|
|
2
|
-
//
|
|
3
|
-
// The conversion methods (other than the methods for int8 and int24) would only work correctly
|
|
4
|
-
// on little-endian architectures, since they assume the byte order of the underlying architecture.
|
|
5
|
-
//
|
|
6
|
-
// Since Echogarden only supports little-endian architectures, this shouldn't matter.
|
|
7
|
-
// int8 <-> bufferLE
|
|
8
|
-
export function int8ToBuffer(int8s) {
|
|
9
|
-
return new Uint8Array(int8s.buffer, int8s.byteOffset, int8s.byteLength);
|
|
10
|
-
}
|
|
11
|
-
export function bufferToInt8(buffer) {
|
|
12
|
-
return new Int8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
13
|
-
}
|
|
14
|
-
// int16 <-> bufferLE
|
|
15
|
-
export function int16ToBufferLE(int16s) {
|
|
16
|
-
return new Uint8Array(int16s.buffer, int16s.byteOffset, int16s.byteLength);
|
|
17
|
-
}
|
|
18
|
-
export function bufferLEToInt16(buffer) {
|
|
19
|
-
return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2);
|
|
20
|
-
}
|
|
21
|
-
// int24 <-> bufferLE (uses int32 for storage)
|
|
22
|
-
export function int24ToBufferLE(int24s) {
|
|
23
|
-
const buffer = new Uint8Array(int24s.length * 3);
|
|
24
|
-
let readOffset = 0;
|
|
25
|
-
let writeOffset = 0;
|
|
26
|
-
while (readOffset < int24s.length) {
|
|
27
|
-
const signedValue = int24s[readOffset++];
|
|
28
|
-
let unsignedValue;
|
|
29
|
-
if (signedValue >= 0) {
|
|
30
|
-
unsignedValue = signedValue;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
unsignedValue = signedValue + (2 ** 24);
|
|
34
|
-
}
|
|
35
|
-
buffer[writeOffset++] = (unsignedValue) & 0xff;
|
|
36
|
-
buffer[writeOffset++] = (unsignedValue >> 8) & 0xff;
|
|
37
|
-
buffer[writeOffset++] = (unsignedValue >> 16) & 0xff;
|
|
38
|
-
}
|
|
39
|
-
return buffer;
|
|
40
|
-
}
|
|
41
|
-
export function bufferLEToInt24(buffer) {
|
|
42
|
-
if (buffer.length % 3 !== 0) {
|
|
43
|
-
throw new Error(`Buffer has a length of ${buffer.length}, which is not a multiple of 3`);
|
|
44
|
-
}
|
|
45
|
-
const result = new Int32Array(buffer.length / 3);
|
|
46
|
-
let readOffset = 0;
|
|
47
|
-
let writeOffset = 0;
|
|
48
|
-
while (writeOffset < result.length) {
|
|
49
|
-
const b0 = buffer[readOffset++];
|
|
50
|
-
const b1 = buffer[readOffset++];
|
|
51
|
-
const b2 = buffer[readOffset++];
|
|
52
|
-
const unsignedValue = (b0) | (b1 << 8) | (b2 << 16);
|
|
53
|
-
let signedValue;
|
|
54
|
-
if (unsignedValue < 2 ** 23) {
|
|
55
|
-
signedValue = unsignedValue;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
signedValue = unsignedValue - (2 ** 24);
|
|
59
|
-
}
|
|
60
|
-
result[writeOffset++] = signedValue;
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
// int32 <-> bufferLE
|
|
65
|
-
export function int32ToBufferLE(int32s) {
|
|
66
|
-
return new Uint8Array(int32s.buffer, int32s.byteOffset, int32s.byteLength);
|
|
67
|
-
}
|
|
68
|
-
export function bufferLEToInt32(buffer) {
|
|
69
|
-
return new Int32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4);
|
|
70
|
-
}
|
|
71
|
-
// float32 <-> bufferLE
|
|
72
|
-
export function float32ToBufferLE(float32s) {
|
|
73
|
-
return new Uint8Array(float32s.buffer, float32s.byteOffset, float32s.byteLength);
|
|
74
|
-
}
|
|
75
|
-
export function bufferLEToFloat32(buffer) {
|
|
76
|
-
return new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4);
|
|
77
|
-
}
|
|
78
|
-
// float64 <-> bufferLE
|
|
79
|
-
export function float64ToBufferLE(float64s) {
|
|
80
|
-
return new Uint8Array(float64s.buffer, float64s.byteOffset, float64s.byteLength);
|
|
81
|
-
}
|
|
82
|
-
export function bufferLEToFloat64(buffer) {
|
|
83
|
-
return new Float64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8);
|
|
84
|
-
}
|
|
85
|
-
// float64 <-> float32
|
|
86
|
-
export function float64Tofloat32(float64s) {
|
|
87
|
-
return Float32Array.from(float64s);
|
|
88
|
-
}
|
|
89
|
-
export function float32Tofloat64(float32s) {
|
|
90
|
-
return Float64Array.from(float32s);
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=BinaryArrayConversion.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BinaryArrayConversion.js","sourceRoot":"","sources":["../../src/utilities/BinaryArrayConversion.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,+FAA+F;AAC/F,mGAAmG;AACnG,EAAE;AACF,qFAAqF;AAErF,oBAAoB;AACpB,MAAM,UAAU,YAAY,CAAC,KAAgB;IAC5C,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;AACxE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC9C,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAC1E,CAAC;AAED,qBAAqB;AACrB,MAAM,UAAU,eAAe,CAAC,MAAkB;IACjD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAC3E,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAkB;IACjD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;AAC/E,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,eAAe,CAAC,MAAkB;IACjD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEhD,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,IAAI,WAAW,GAAG,CAAC,CAAA;IAEnB,OAAO,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACnC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,EAAE,CAA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,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;AACjF,CAAC;AAED,sBAAsB;AACtB,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACtD,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACtD,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACnC,CAAC"}
|
package/src/codecs/WaveCodec.ts
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import * as AudioBufferConversion from '../audio/AudioBufferConversion.js'
|
|
2
|
-
import { RawAudio } from '../audio/AudioUtilities.js'
|
|
3
|
-
import { readUint16LE, readUint32LE, writeAscii, writeUint16LE, writeUint32LE } from '../utilities/BinaryUtilities.js'
|
|
4
|
-
import { encodeHex, decodeHex } from '../encodings/Hex.js'
|
|
5
|
-
import { concatUint8Arrays, logToStderr } from '../utilities/Utilities.js'
|
|
6
|
-
import { decodeAscii } from '../encodings/Ascii.js'
|
|
7
|
-
|
|
8
|
-
const log = logToStderr
|
|
9
|
-
|
|
10
|
-
export function encodeWave(rawAudio: RawAudio, bitDepth: BitDepth = 16, sampleFormat: SampleFormat = SampleFormat.PCM, speakerPositionMask = 0) {
|
|
11
|
-
const audioChannels = rawAudio.audioChannels
|
|
12
|
-
const sampleRate = rawAudio.sampleRate
|
|
13
|
-
|
|
14
|
-
const audioBuffer = AudioBufferConversion.encodeToAudioBuffer(audioChannels, bitDepth, sampleFormat)
|
|
15
|
-
const audioDataLength = audioBuffer.length
|
|
16
|
-
|
|
17
|
-
const shouldUseExtensibleFormat = bitDepth > 16 || audioChannels.length > 2
|
|
18
|
-
|
|
19
|
-
const formatSubChunk = new WaveFormat(audioChannels.length, sampleRate, bitDepth, sampleFormat, speakerPositionMask)
|
|
20
|
-
const formatSubChunkBuffer = formatSubChunk.serialize(shouldUseExtensibleFormat)
|
|
21
|
-
|
|
22
|
-
const dataSubChunkBuffer = new Uint8Array(4 + 4 + audioDataLength)
|
|
23
|
-
writeAscii(dataSubChunkBuffer, 'data', 0)
|
|
24
|
-
const dataChunkLength = Math.min(audioDataLength, 4294967295) // Ensure large data chunk length is clipped to max
|
|
25
|
-
writeUint32LE(dataSubChunkBuffer, dataChunkLength, 4)
|
|
26
|
-
dataSubChunkBuffer.set(audioBuffer, 8)
|
|
27
|
-
|
|
28
|
-
const riffChunkHeaderBuffer = new Uint8Array(12)
|
|
29
|
-
writeAscii(riffChunkHeaderBuffer, 'RIFF', 0)
|
|
30
|
-
const riffChunkLength = Math.min(4 + formatSubChunkBuffer.length + dataSubChunkBuffer.length, 4294967295) // Ensure large RIFF chunk length is clipped to max
|
|
31
|
-
writeUint32LE(riffChunkHeaderBuffer, riffChunkLength, 4)
|
|
32
|
-
writeAscii(riffChunkHeaderBuffer, 'WAVE', 8)
|
|
33
|
-
|
|
34
|
-
return concatUint8Arrays([riffChunkHeaderBuffer, formatSubChunkBuffer, dataSubChunkBuffer])
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function decodeWave(waveData: Uint8Array, ignoreTruncatedChunks = true, ignoreOverflowingDataChunks = true) {
|
|
38
|
-
let readOffset = 0
|
|
39
|
-
|
|
40
|
-
const riffId = decodeAscii(waveData.subarray(readOffset, readOffset + 4))
|
|
41
|
-
|
|
42
|
-
if (riffId != 'RIFF') {
|
|
43
|
-
throw new Error('Not a valid wave file. No RIFF id found at offset 0.')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
readOffset += 4
|
|
47
|
-
|
|
48
|
-
let riffChunkSize = readUint32LE(waveData, readOffset)
|
|
49
|
-
|
|
50
|
-
readOffset += 4
|
|
51
|
-
|
|
52
|
-
const waveId = decodeAscii(waveData.subarray(readOffset, readOffset + 4))
|
|
53
|
-
|
|
54
|
-
if (waveId != 'WAVE') {
|
|
55
|
-
throw new Error('Not a valid wave file. No WAVE id found at offset 8.')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (ignoreOverflowingDataChunks && riffChunkSize === 4294967295) {
|
|
59
|
-
riffChunkSize = waveData.length - 8
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (riffChunkSize < waveData.length - 8) {
|
|
63
|
-
throw new Error(`RIFF chunk length ${riffChunkSize} is smaller than the remaining size of the buffer (${waveData.length - 8})`)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!ignoreTruncatedChunks && riffChunkSize > waveData.length - 8) {
|
|
67
|
-
throw new Error(`RIFF chunk length (${riffChunkSize}) is greater than the remaining size of the buffer (${waveData.length - 8})`)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
readOffset += 4
|
|
71
|
-
|
|
72
|
-
let formatSubChunkBodyBuffer: Uint8Array | undefined
|
|
73
|
-
const dataBuffers: Uint8Array[] = []
|
|
74
|
-
|
|
75
|
-
while (true) {
|
|
76
|
-
const subChunkIdentifier = decodeAscii(waveData.subarray(readOffset, readOffset + 4))
|
|
77
|
-
readOffset += 4
|
|
78
|
-
|
|
79
|
-
let subChunkSize = readUint32LE(waveData, readOffset)
|
|
80
|
-
readOffset += 4
|
|
81
|
-
|
|
82
|
-
if (!ignoreTruncatedChunks && subChunkSize > waveData.length - readOffset) {
|
|
83
|
-
throw new Error(`Encountered a '${subChunkIdentifier}' subchunk with a size of ${subChunkSize} which is greater than the remaining size of the buffer (${waveData.length - readOffset})`)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (subChunkIdentifier == 'fmt ') {
|
|
87
|
-
formatSubChunkBodyBuffer = waveData.subarray(readOffset, readOffset + subChunkSize)
|
|
88
|
-
} else if (subChunkIdentifier == 'data') {
|
|
89
|
-
if (!formatSubChunkBodyBuffer) {
|
|
90
|
-
throw new Error('A data subchunk was encountered before a format subchunk')
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// If the data chunk is truncated or extended beyond 4 GiB,
|
|
94
|
-
// the data would be read up to the end of the buffer
|
|
95
|
-
if (ignoreOverflowingDataChunks && subChunkSize === 4294967295) {
|
|
96
|
-
subChunkSize = waveData.length - readOffset
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const subChunkData = waveData.subarray(readOffset, readOffset + subChunkSize)
|
|
100
|
-
|
|
101
|
-
dataBuffers.push(subChunkData)
|
|
102
|
-
}
|
|
103
|
-
// All sub chunks other than 'data' (e.g. 'LIST', 'fact', 'plst', 'junk' etc.) are ignored
|
|
104
|
-
|
|
105
|
-
// This addition operation may overflow if JavaScript integers were 32 bits,
|
|
106
|
-
// but since they are 52 bits, it is okay:
|
|
107
|
-
readOffset += subChunkSize
|
|
108
|
-
|
|
109
|
-
// Break if readOffset is equal to or is greater than the size of the buffer
|
|
110
|
-
if (readOffset >= waveData.length) {
|
|
111
|
-
break
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!formatSubChunkBodyBuffer) {
|
|
116
|
-
throw new Error('No format subchunk was found in the wave file')
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (dataBuffers.length === 0) {
|
|
120
|
-
throw new Error('No data subchunks were found in the wave file')
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const waveFormat = WaveFormat.deserializeFrom(formatSubChunkBodyBuffer)
|
|
124
|
-
|
|
125
|
-
const sampleFormat = waveFormat.sampleFormat
|
|
126
|
-
const channelCount = waveFormat.channelCount
|
|
127
|
-
const sampleRate = waveFormat.sampleRate
|
|
128
|
-
const bitDepth = waveFormat.bitDepth
|
|
129
|
-
const speakerPositionMask = waveFormat.speakerPositionMask
|
|
130
|
-
|
|
131
|
-
const concatenatedDataBuffers = concatUint8Arrays(dataBuffers)
|
|
132
|
-
dataBuffers.length = 0 // Allow the garbage collector to free up memory held by the data buffers
|
|
133
|
-
|
|
134
|
-
const audioChannels = AudioBufferConversion.decodeToChannels(concatenatedDataBuffers, channelCount, bitDepth, sampleFormat)
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
rawAudio: { audioChannels, sampleRate },
|
|
138
|
-
|
|
139
|
-
sourceSampleFormat: sampleFormat,
|
|
140
|
-
sourceBitDepth: bitDepth,
|
|
141
|
-
sourceSpeakerPositionMask: speakerPositionMask
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function repairWave(waveData: Uint8Array) {
|
|
146
|
-
const { rawAudio, sourceSampleFormat, sourceBitDepth } = decodeWave(waveData)
|
|
147
|
-
|
|
148
|
-
return encodeWave(rawAudio, sourceBitDepth, sourceSampleFormat)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
class WaveFormat { // 24 bytes total for PCM, 26 for float
|
|
152
|
-
sampleFormat: SampleFormat // 2 bytes LE
|
|
153
|
-
channelCount: number // 2 bytes LE
|
|
154
|
-
sampleRate: number // 4 bytes LE
|
|
155
|
-
get byteRate() { return this.sampleRate * this.bytesPerSample * this.channelCount } // 4 bytes LE
|
|
156
|
-
get blockAlign() { return this.bytesPerSample * this.channelCount } // 2 bytes LE
|
|
157
|
-
bitDepth: BitDepth // 2 bytes LE
|
|
158
|
-
|
|
159
|
-
speakerPositionMask: number // 4 bytes LE
|
|
160
|
-
get guid() { return sampleFormatToGuid[this.sampleFormat] } // 16 bytes BE
|
|
161
|
-
|
|
162
|
-
// helpers:
|
|
163
|
-
get bytesPerSample() { return this.bitDepth / 8 }
|
|
164
|
-
|
|
165
|
-
constructor(channelCount: number, sampleRate: number, bitDepth: BitDepth, sampleFormat: SampleFormat, speakerPositionMask = 0) {
|
|
166
|
-
this.sampleFormat = sampleFormat
|
|
167
|
-
this.channelCount = channelCount
|
|
168
|
-
this.sampleRate = sampleRate
|
|
169
|
-
this.bitDepth = bitDepth
|
|
170
|
-
|
|
171
|
-
this.speakerPositionMask = speakerPositionMask
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
serialize(useExtensibleFormat: boolean) {
|
|
175
|
-
let sampleFormatId = this.sampleFormat
|
|
176
|
-
|
|
177
|
-
if (useExtensibleFormat) {
|
|
178
|
-
sampleFormatId = 65534 as number
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const serializedSize = sampleFormatToSerializedSize[sampleFormatId]
|
|
182
|
-
|
|
183
|
-
const result = new Uint8Array(serializedSize)
|
|
184
|
-
|
|
185
|
-
writeAscii(result, 'fmt ', 0) // + 4
|
|
186
|
-
writeUint32LE(result, serializedSize - 8, 4) // + 4
|
|
187
|
-
|
|
188
|
-
writeUint16LE(result, sampleFormatId, 8) // + 2
|
|
189
|
-
writeUint16LE(result, this.channelCount, 10) // + 2
|
|
190
|
-
writeUint32LE(result, this.sampleRate, 12) // + 4
|
|
191
|
-
writeUint32LE(result, this.byteRate, 16) // + 4
|
|
192
|
-
writeUint16LE(result, this.blockAlign, 20) // + 2
|
|
193
|
-
writeUint16LE(result, this.bitDepth, 22) // + 2
|
|
194
|
-
|
|
195
|
-
if (useExtensibleFormat) {
|
|
196
|
-
writeUint16LE(result, serializedSize - 26, 24) // + 2 (extension size)
|
|
197
|
-
writeUint16LE(result, this.bitDepth, 26) // + 2 (valid bits per sample)
|
|
198
|
-
writeUint32LE(result, this.speakerPositionMask, 28) // + 2 (speaker position mask)
|
|
199
|
-
|
|
200
|
-
if (this.sampleFormat == SampleFormat.PCM || this.sampleFormat == SampleFormat.Float) {
|
|
201
|
-
result.set(decodeHex(this.guid), 32)
|
|
202
|
-
} else {
|
|
203
|
-
throw new Error(`Extensible format is not supported for sample format ${this.sampleFormat}`)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return result
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
static deserializeFrom(formatChunkBody: Uint8Array) { // chunkBody should not include the first 8 bytes
|
|
211
|
-
let sampleFormat = readUint16LE(formatChunkBody, 0) // + 2
|
|
212
|
-
const channelCount = readUint16LE(formatChunkBody, 2) // + 2
|
|
213
|
-
const sampleRate = readUint32LE(formatChunkBody, 4) // + 4
|
|
214
|
-
const bitDepth = readUint16LE(formatChunkBody, 14)
|
|
215
|
-
let speakerPositionMask = 0
|
|
216
|
-
|
|
217
|
-
if (sampleFormat == 65534) {
|
|
218
|
-
if (formatChunkBody.length < 40) {
|
|
219
|
-
throw new Error(`Format subchunk specifies a format id of 65534 (extensible) but its body size is ${formatChunkBody.length} bytes, which is smaller than the minimum expected of 40 bytes`)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
speakerPositionMask = readUint16LE(formatChunkBody, 20)
|
|
223
|
-
|
|
224
|
-
const guid = encodeHex(formatChunkBody.subarray(24, 40))
|
|
225
|
-
|
|
226
|
-
if (guid == sampleFormatToGuid[SampleFormat.PCM]) {
|
|
227
|
-
sampleFormat = SampleFormat.PCM
|
|
228
|
-
} else if (guid == sampleFormatToGuid[SampleFormat.Float]) {
|
|
229
|
-
sampleFormat = SampleFormat.Float
|
|
230
|
-
} else {
|
|
231
|
-
throw new Error(`Unsupported format GUID in extended format subchunk: ${guid}`)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (sampleFormat == SampleFormat.PCM) {
|
|
236
|
-
if (bitDepth != 8 && bitDepth != 16 && bitDepth != 24 && bitDepth != 32) {
|
|
237
|
-
throw new Error(`PCM audio has a bit depth of ${bitDepth}, which is not supported`)
|
|
238
|
-
}
|
|
239
|
-
} else if (sampleFormat == SampleFormat.Float) {
|
|
240
|
-
if (bitDepth != 32 && bitDepth != 64) {
|
|
241
|
-
throw new Error(`IEEE float audio has a bit depth of ${bitDepth}, which is not supported`)
|
|
242
|
-
}
|
|
243
|
-
} else if (sampleFormat == SampleFormat.Alaw) {
|
|
244
|
-
if (bitDepth != 8) {
|
|
245
|
-
throw new Error(`Alaw audio has a bit depth of ${bitDepth}, which is not supported`)
|
|
246
|
-
}
|
|
247
|
-
} else if (sampleFormat == SampleFormat.Mulaw) {
|
|
248
|
-
if (bitDepth != 8) {
|
|
249
|
-
throw new Error(`Mulaw audio has a bit depth of ${bitDepth}, which is not supported`)
|
|
250
|
-
}
|
|
251
|
-
} else {
|
|
252
|
-
throw new Error(`Wave audio format id ${sampleFormat} is not supported`)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return new WaveFormat(channelCount, sampleRate, bitDepth, sampleFormat, speakerPositionMask)
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export enum SampleFormat {
|
|
260
|
-
PCM = 1,
|
|
261
|
-
Float = 3,
|
|
262
|
-
Alaw = 6,
|
|
263
|
-
Mulaw = 7,
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export type BitDepth = 8 | 16 | 24 | 32 | 64
|
|
267
|
-
|
|
268
|
-
const sampleFormatToSerializedSize = {
|
|
269
|
-
[SampleFormat.PCM]: 24,
|
|
270
|
-
[SampleFormat.Float]: 26,
|
|
271
|
-
[SampleFormat.Alaw]: 26,
|
|
272
|
-
[SampleFormat.Mulaw]: 26,
|
|
273
|
-
65534: 48
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const sampleFormatToGuid = {
|
|
277
|
-
[SampleFormat.PCM]: '0100000000001000800000aa00389b71',
|
|
278
|
-
[SampleFormat.Float]: '0300000000001000800000aa00389b71',
|
|
279
|
-
[SampleFormat.Alaw]: '',
|
|
280
|
-
[SampleFormat.Mulaw]: '',
|
|
281
|
-
}
|