echogarden 2.0.12 → 2.0.14
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/README.md +8 -6
- package/dist/data-structures/DynamicTypedArray.d.ts +2 -1
- package/dist/data-structures/DynamicTypedArray.js +14 -9
- package/dist/data-structures/DynamicTypedArray.js.map +1 -1
- package/dist/nlp/IPA.d.ts +3 -3
- package/dist/recognition/WhisperSTT.js +6 -3
- package/dist/recognition/WhisperSTT.js.map +1 -1
- package/dist/utilities/WasmMemoryManager.d.ts +1 -1
- package/docs/CLI.md +3 -3
- package/docs/Tasklist.md +12 -17
- package/package.json +9 -9
- package/src/data-structures/DynamicTypedArray.ts +16 -10
- package/src/recognition/WhisperSTT.ts +7 -3
- package/dist/encodings/LPVarInt.d.ts +0 -11
- package/dist/encodings/LPVarInt.js +0 -187
- package/dist/encodings/LPVarInt.js.map +0 -1
- package/src/encodings/LPVarInt.ts +0 -292
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { createDynamicUint8Array, DynamicUint8Array } from "../data-structures/DynamicTypedArray.js"
|
|
2
|
-
import { logToStderr } from "../utilities/Utilities.js"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
6
|
-
// Encode unsigned integer
|
|
7
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
8
|
-
export function encodeUnsignedInt31(value: number, outEncodedData: DynamicUint8Array) {
|
|
9
|
-
value = value >>> 0
|
|
10
|
-
|
|
11
|
-
if (value < (2 ** 7)) {
|
|
12
|
-
outEncodedData.add(
|
|
13
|
-
value
|
|
14
|
-
)
|
|
15
|
-
} else if (value < (2 ** 14)) {
|
|
16
|
-
outEncodedData.addMany(
|
|
17
|
-
(value & 0b00111111) | 0b10000000,
|
|
18
|
-
value >>> 6,
|
|
19
|
-
)
|
|
20
|
-
} else if (value < (2 ** 21)) {
|
|
21
|
-
outEncodedData.addMany(
|
|
22
|
-
(value & 0b00011111) | 0b11000000,
|
|
23
|
-
value >>> 5,
|
|
24
|
-
value >>> 13,
|
|
25
|
-
)
|
|
26
|
-
} else if (value < (2 ** 28)) {
|
|
27
|
-
outEncodedData.addMany(
|
|
28
|
-
(value & 0b00001111) | 0b11100000,
|
|
29
|
-
value >>> 4,
|
|
30
|
-
value >>> 12,
|
|
31
|
-
value >>> 20,
|
|
32
|
-
)
|
|
33
|
-
} else {
|
|
34
|
-
outEncodedData.addMany(
|
|
35
|
-
0b11110000,
|
|
36
|
-
value,
|
|
37
|
-
value >>> 8,
|
|
38
|
-
value >>> 16,
|
|
39
|
-
value >>> 24,
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
45
|
-
// Decode unsigned integer
|
|
46
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
47
|
-
export function decodeUnsignedInt31(encodedData: ArrayLike<number>, readOffset: number): DecodedValueAndReadOffset {
|
|
48
|
-
readOffset = readOffset | 0
|
|
49
|
-
|
|
50
|
-
const byte0 = encodedData[readOffset++]
|
|
51
|
-
|
|
52
|
-
if ((byte0 & 0b10000000) === 0) {
|
|
53
|
-
// 1 byte
|
|
54
|
-
let decodedValue =
|
|
55
|
-
byte0
|
|
56
|
-
|
|
57
|
-
return { decodedValue, readOffset }
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const byte1 = encodedData[readOffset++]
|
|
61
|
-
|
|
62
|
-
if ((byte0 & 0b01000000) === 0) {
|
|
63
|
-
// 2 bytes
|
|
64
|
-
let decodedValue =
|
|
65
|
-
(byte0 & 0b00111111) |
|
|
66
|
-
(byte1 << 6)
|
|
67
|
-
|
|
68
|
-
return { decodedValue, readOffset }
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const byte2 = encodedData[readOffset++]
|
|
72
|
-
|
|
73
|
-
if ((byte0 & 0b00100000) === 0) {
|
|
74
|
-
// 3 bytes
|
|
75
|
-
let decodedValue =
|
|
76
|
-
(byte0 & 0b00011111) |
|
|
77
|
-
(byte1 << 5) |
|
|
78
|
-
(byte2 << 13)
|
|
79
|
-
|
|
80
|
-
return { decodedValue, readOffset }
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const byte3 = encodedData[readOffset++]
|
|
84
|
-
|
|
85
|
-
if ((byte0 & 0b00010000) === 0) {
|
|
86
|
-
// 4 bytes
|
|
87
|
-
let decodedValue =
|
|
88
|
-
(byte0 & 0b00001111) |
|
|
89
|
-
(byte1 << 4) |
|
|
90
|
-
(byte2 << 12) |
|
|
91
|
-
(byte3 << 20)
|
|
92
|
-
|
|
93
|
-
return { decodedValue, readOffset }
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const byte4 = encodedData[readOffset++]
|
|
97
|
-
|
|
98
|
-
if (byte0 === 0b11110000) {
|
|
99
|
-
// 5 bytes
|
|
100
|
-
let decodedValue =
|
|
101
|
-
(byte1) |
|
|
102
|
-
(byte2 << 8) |
|
|
103
|
-
(byte3 << 16) |
|
|
104
|
-
(byte4 << 24)
|
|
105
|
-
|
|
106
|
-
return { decodedValue, readOffset }
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
throw new Error(`Encountered a value that is encoded with more than 5 bytes (beyond Unsigned Int31 range).`)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
113
|
-
// Encode signed integer
|
|
114
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
115
|
-
export function encodeSignedInt32(value: number, outEncodedData: DynamicUint8Array) {
|
|
116
|
-
const absValue = Math.abs(value | 0)
|
|
117
|
-
|
|
118
|
-
if (absValue < (2 ** 6)) {
|
|
119
|
-
outEncodedData.add(
|
|
120
|
-
value & 0b01111111
|
|
121
|
-
)
|
|
122
|
-
} else if (absValue < (2 ** 13)) {
|
|
123
|
-
outEncodedData.addMany(
|
|
124
|
-
(value & 0b00111111) | 0b10000000,
|
|
125
|
-
value >> 6
|
|
126
|
-
)
|
|
127
|
-
} else if (absValue < (2 ** 20)) {
|
|
128
|
-
outEncodedData.addMany(
|
|
129
|
-
(value & 0b00011111) | 0b11000000,
|
|
130
|
-
value >> 5,
|
|
131
|
-
value >> 13,
|
|
132
|
-
)
|
|
133
|
-
} else if (absValue < (2 ** 27)) {
|
|
134
|
-
outEncodedData.addMany(
|
|
135
|
-
(value & 0b00001111) | 0b11100000,
|
|
136
|
-
value >> 4,
|
|
137
|
-
value >> 12,
|
|
138
|
-
value >> 20,
|
|
139
|
-
)
|
|
140
|
-
} else {
|
|
141
|
-
outEncodedData.addMany(
|
|
142
|
-
0b11110000,
|
|
143
|
-
value,
|
|
144
|
-
value >> 8,
|
|
145
|
-
value >> 16,
|
|
146
|
-
value >> 24,
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
152
|
-
// Decode signed integer
|
|
153
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
154
|
-
export function decodeSignedInt32(encodedData: ArrayLike<number>, readOffset: number): DecodedValueAndReadOffset {
|
|
155
|
-
const byte0 = encodedData[readOffset++]
|
|
156
|
-
|
|
157
|
-
if ((byte0 & 0b10000000) === 0) {
|
|
158
|
-
// 1 byte
|
|
159
|
-
let decodedValue =
|
|
160
|
-
byte0
|
|
161
|
-
|
|
162
|
-
if ((byte0 & 0b01000000) !== 0) {
|
|
163
|
-
decodedValue |= (-1 << 7)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return { decodedValue, readOffset }
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const byte1 = encodedData[readOffset++]
|
|
170
|
-
|
|
171
|
-
if ((byte0 & 0b01000000) === 0) {
|
|
172
|
-
// 2 bytes
|
|
173
|
-
let decodedValue =
|
|
174
|
-
(byte0 & 0b00111111) |
|
|
175
|
-
(byte1 << 6)
|
|
176
|
-
|
|
177
|
-
if ((byte1 & 0b10000000) !== 0) {
|
|
178
|
-
decodedValue |= (-1 << 14)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return { decodedValue, readOffset }
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const byte2 = encodedData[readOffset++]
|
|
185
|
-
|
|
186
|
-
if ((byte0 & 0b00100000) === 0) {
|
|
187
|
-
// 3 bytes
|
|
188
|
-
let decodedValue =
|
|
189
|
-
(byte0 & 0b00011111) |
|
|
190
|
-
(byte1 << 5) |
|
|
191
|
-
(byte2 << 13)
|
|
192
|
-
|
|
193
|
-
if ((byte2 & 0b10000000) !== 0) {
|
|
194
|
-
decodedValue |= (-1 << 21)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return { decodedValue, readOffset }
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const byte3 = encodedData[readOffset++]
|
|
201
|
-
|
|
202
|
-
if ((byte0 & 0b00010000) === 0) {
|
|
203
|
-
// 4 bytes
|
|
204
|
-
let decodedValue =
|
|
205
|
-
(byte0 & 0b00001111) |
|
|
206
|
-
(byte1 << 4) |
|
|
207
|
-
(byte2 << 12) |
|
|
208
|
-
(byte3 << 20)
|
|
209
|
-
|
|
210
|
-
if ((byte3 & 0b10000000) !== 0) {
|
|
211
|
-
decodedValue |= (-1 << 28)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return { decodedValue, readOffset }
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const byte4 = encodedData[readOffset++]
|
|
218
|
-
|
|
219
|
-
if (byte0 === 0b11110000) {
|
|
220
|
-
// 5 bytes
|
|
221
|
-
let decodedValue =
|
|
222
|
-
(byte1) |
|
|
223
|
-
(byte2 << 8) |
|
|
224
|
-
(byte3 << 16) |
|
|
225
|
-
(byte4 << 24)
|
|
226
|
-
|
|
227
|
-
return { decodedValue, readOffset }
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
throw new Error(`Encountered a value that is encoded with more than 5 bytes (beyond int32 range).`)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
234
|
-
// Types
|
|
235
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
236
|
-
export interface DecodedValueAndReadOffset {
|
|
237
|
-
decodedValue: number
|
|
238
|
-
readOffset: number
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
242
|
-
// Tests
|
|
243
|
-
////////////////////////////////////////////////////////////////////////////////////
|
|
244
|
-
export function testLPVarintSigned() {
|
|
245
|
-
const encodedBytes = createDynamicUint8Array()
|
|
246
|
-
|
|
247
|
-
function runTest(testValue: number) {
|
|
248
|
-
encodedBytes.clear()
|
|
249
|
-
|
|
250
|
-
encodeSignedInt32(testValue, encodedBytes)
|
|
251
|
-
const { decodedValue } = decodeSignedInt32(encodedBytes.elements, 0)
|
|
252
|
-
|
|
253
|
-
if (decodedValue !== testValue) {
|
|
254
|
-
throw new Error(`Expected ${testValue} but got ${decodedValue}`)
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
for (let i = -(2 ** 26); i < 2 ** 26; i++) {
|
|
259
|
-
if (i % 1000000 === 0) {
|
|
260
|
-
logToStderr(i)
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
runTest(i)
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const x = 1
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export function testLPVarintUnsigned() {
|
|
270
|
-
const encodedBytes = createDynamicUint8Array()
|
|
271
|
-
|
|
272
|
-
function runTest(testValue: number) {
|
|
273
|
-
encodedBytes.clear()
|
|
274
|
-
|
|
275
|
-
encodeUnsignedInt31(testValue, encodedBytes)
|
|
276
|
-
const { decodedValue } = decodeUnsignedInt31(encodedBytes.elements, 0)
|
|
277
|
-
|
|
278
|
-
if (decodedValue !== testValue) {
|
|
279
|
-
throw new Error(`Expected ${testValue} but got ${decodedValue}`)
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
for (let i = 0; i < 2 ** 31; i++) {
|
|
284
|
-
if (i % 1000000 === 0) {
|
|
285
|
-
logToStderr(i)
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
runTest(i)
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const x = 1
|
|
292
|
-
}
|