echogarden 1.6.2 → 1.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/schemas/options.json +30 -4
- package/dist/api/SourceSeparation.d.ts +3 -2
- package/dist/api/SourceSeparation.js +10 -8
- package/dist/api/SourceSeparation.js.map +1 -1
- package/dist/api/Synthesis.js +3 -1
- package/dist/api/Synthesis.js.map +1 -1
- package/dist/api/TextTranslation.d.ts +3 -1
- package/dist/api/TextTranslation.js +12 -6
- package/dist/api/TextTranslation.js.map +1 -1
- package/dist/build-tools/MakeTarballsForInstalledPackages.d.ts +1 -0
- package/dist/build-tools/MakeTarballsForInstalledPackages.js +20 -0
- package/dist/build-tools/MakeTarballsForInstalledPackages.js.map +1 -0
- package/dist/cli/CLI.js +4 -3
- package/dist/cli/CLI.js.map +1 -1
- package/dist/dsp/FFT.d.ts +2 -3
- package/dist/dsp/FFT.js +25 -23
- package/dist/dsp/FFT.js.map +1 -1
- package/dist/nlp/Segmentation.js +2 -1
- package/dist/nlp/Segmentation.js.map +1 -1
- package/dist/nlp/TextNormalizer.d.ts +2 -0
- package/dist/nlp/TextNormalizer.js +51 -0
- package/dist/nlp/TextNormalizer.js.map +1 -1
- package/dist/recognition/WhisperSTT.d.ts +2 -0
- package/dist/recognition/WhisperSTT.js +7 -6
- package/dist/recognition/WhisperSTT.js.map +1 -1
- package/dist/source-separation/MDXNetSourceSeparation.d.ts +20 -2
- package/dist/source-separation/MDXNetSourceSeparation.js +134 -76
- package/dist/source-separation/MDXNetSourceSeparation.js.map +1 -1
- package/dist/subtitles/Subtitles.js +2 -1
- package/dist/subtitles/Subtitles.js.map +1 -1
- package/dist/synthesis/EspeakTTS.js +5 -5
- package/dist/synthesis/EspeakTTS.js.map +1 -1
- package/dist/tests/Test.js +0 -1
- package/dist/tests/Test.js.map +1 -1
- package/dist/text-translation/GoogleTranslateTextTranslation.d.ts +9 -3
- package/dist/text-translation/GoogleTranslateTextTranslation.js +59 -29
- package/dist/text-translation/GoogleTranslateTextTranslation.js.map +1 -1
- package/dist/utilities/OnnxUtilities.d.ts +1 -0
- package/dist/utilities/OnnxUtilities.js +5 -5
- package/dist/utilities/OnnxUtilities.js.map +1 -1
- package/dist/utilities/PackageManager.js +3 -0
- package/dist/utilities/PackageManager.js.map +1 -1
- package/dist/utilities/StringUtilities.d.ts +28 -0
- package/dist/utilities/StringUtilities.js +150 -0
- package/dist/utilities/StringUtilities.js.map +1 -0
- package/dist/utilities/TarballMaker.d.ts +3 -4
- package/dist/utilities/TarballMaker.js +6 -19
- package/dist/utilities/TarballMaker.js.map +1 -1
- package/dist/utilities/Timeline.js +2 -1
- package/dist/utilities/Timeline.js.map +1 -1
- package/dist/utilities/Utilities.d.ts +1 -33
- package/dist/utilities/Utilities.js +3 -176
- package/dist/utilities/Utilities.js.map +1 -1
- package/dist/utilities/WebReader.js +1 -1
- package/dist/utilities/WebReader.js.map +1 -1
- package/dist/utilities/WikipediaReader.js +1 -1
- package/dist/utilities/WikipediaReader.js.map +1 -1
- package/dist/utilities/WindowedList.d.ts +10 -0
- package/dist/utilities/WindowedList.js +36 -0
- package/dist/utilities/WindowedList.js.map +1 -0
- package/docs/Engines.md +1 -1
- package/docs/Options.md +8 -2
- package/package.json +8 -9
- package/src/api/SourceSeparation.ts +15 -10
- package/src/api/Synthesis.ts +3 -1
- package/src/api/TextTranslation.ts +17 -9
- package/src/build-tools/MakeTarballsForInstalledPackages.ts +25 -0
- package/src/cli/CLI.ts +4 -3
- package/src/dsp/FFT.ts +30 -33
- package/src/nlp/Segmentation.ts +2 -1
- package/src/nlp/TextNormalizer.ts +60 -0
- package/src/recognition/WhisperSTT.ts +7 -6
- package/src/source-separation/MDXNetSourceSeparation.ts +183 -85
- package/src/subtitles/Subtitles.ts +2 -1
- package/src/synthesis/EspeakTTS.ts +5 -5
- package/src/tests/Test.ts +0 -4
- package/src/text-translation/GoogleTranslateTextTranslation.ts +91 -30
- package/src/utilities/OnnxUtilities.ts +7 -8
- package/src/utilities/PackageManager.ts +3 -0
- package/src/utilities/StringUtilities.ts +203 -0
- package/src/utilities/TarballMaker.ts +6 -23
- package/src/utilities/Timeline.ts +2 -1
- package/src/utilities/Utilities.ts +4 -237
- package/src/utilities/WebReader.ts +1 -1
- package/src/utilities/WikipediaReader.ts +1 -1
- package/src/utilities/WindowedList.ts +45 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as readline from 'node:readline'
|
|
2
2
|
import { IncomingMessage } from 'node:http'
|
|
3
|
-
import { inspect } from 'node:util'
|
|
4
3
|
|
|
5
4
|
import { RandomGenerator } from './RandomGenerator.js'
|
|
6
5
|
import { randomUUID, randomBytes } from 'node:crypto'
|
|
7
6
|
import { Logger } from './Logger.js'
|
|
8
|
-
import { ChildProcessWithoutNullStreams
|
|
7
|
+
import { ChildProcessWithoutNullStreams } from 'node:child_process'
|
|
8
|
+
import { inspect } from 'node:util'
|
|
9
9
|
|
|
10
10
|
const log = logToStderr
|
|
11
11
|
|
|
@@ -50,31 +50,6 @@ export function shuffleArrayInPlace<T>(array: T[], randomGen: RandomGenerator) {
|
|
|
50
50
|
return array
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export function simplifyPunctuationCharacters(text: string) {
|
|
54
|
-
return text
|
|
55
|
-
.replaceAll(`“`, `"`)
|
|
56
|
-
.replaceAll(`”`, `"`)
|
|
57
|
-
.replaceAll(`„`, `"`)
|
|
58
|
-
.replaceAll(`ߵ`, `"`)
|
|
59
|
-
.replaceAll(`ߴ`, `"`)
|
|
60
|
-
.replaceAll(`«`, `"`)
|
|
61
|
-
.replaceAll(`»`, `"`)
|
|
62
|
-
|
|
63
|
-
.replaceAll(`’`, `'`)
|
|
64
|
-
.replaceAll(`ʼ`, `'`)
|
|
65
|
-
.replaceAll(`ʼ`, `'`)
|
|
66
|
-
.replaceAll(`'`, `'`)
|
|
67
|
-
.replaceAll(`,`, `,`)
|
|
68
|
-
.replaceAll(`、`, `,`)
|
|
69
|
-
.replaceAll(`:`, `:`)
|
|
70
|
-
.replaceAll(`;`, `;`)
|
|
71
|
-
.replaceAll(`。`, `.`)
|
|
72
|
-
|
|
73
|
-
.replaceAll(`?`, `?`)
|
|
74
|
-
.replaceAll(`!`, `!`)
|
|
75
|
-
.replaceAll(`؟`, `?`)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
53
|
export function writeToStderr(message: any) {
|
|
79
54
|
process.stderr.write(message)
|
|
80
55
|
}
|
|
@@ -83,7 +58,7 @@ export function printToStderr(message: any) {
|
|
|
83
58
|
if (typeof message == 'string') {
|
|
84
59
|
writeToStderr(message)
|
|
85
60
|
} else {
|
|
86
|
-
writeToStderr(
|
|
61
|
+
writeToStderr(formatObjectToString(message))
|
|
87
62
|
}
|
|
88
63
|
}
|
|
89
64
|
|
|
@@ -92,7 +67,7 @@ export function logToStderr(message: any) {
|
|
|
92
67
|
writeToStderr('\n')
|
|
93
68
|
}
|
|
94
69
|
|
|
95
|
-
export function
|
|
70
|
+
export function formatObjectToString(obj: any) {
|
|
96
71
|
const formattedString = inspect(obj, {
|
|
97
72
|
showHidden: false,
|
|
98
73
|
depth: null,
|
|
@@ -139,32 +114,6 @@ export function sumArray<T>(arr: Array<T>, valueGetter: (item: T) => number) {
|
|
|
139
114
|
return sum
|
|
140
115
|
}
|
|
141
116
|
|
|
142
|
-
export function includesAnyOf(str: string, substrings: string[]) {
|
|
143
|
-
return indexOfAnyOf(str, substrings) >= 0
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function indexOfAnyOf(str: string, substrings: string[]) {
|
|
147
|
-
for (const substring of substrings) {
|
|
148
|
-
const index = str.indexOf(substring)
|
|
149
|
-
|
|
150
|
-
if (index >= 0) {
|
|
151
|
-
return index
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return -1
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function startsWithAnyOf(str: string, prefixes: string[]) {
|
|
159
|
-
for (const prefix of prefixes) {
|
|
160
|
-
if (str.startsWith(prefix)) {
|
|
161
|
-
return true
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return false
|
|
166
|
-
}
|
|
167
|
-
|
|
168
117
|
export function roundToDigits(val: number, digits = 3) {
|
|
169
118
|
const multiplier = 10 ** digits
|
|
170
119
|
return Math.round(val * multiplier) / multiplier
|
|
@@ -217,26 +166,6 @@ export function secondsToMS(totalSeconds: number) {
|
|
|
217
166
|
return { minutes: (hours * 60) + minutes, seconds, milliseconds }
|
|
218
167
|
}
|
|
219
168
|
|
|
220
|
-
export function formatHMS(timeHMS: { hours: number, minutes: number, seconds: number, milliseconds: number }, decimalSeparator = '.') {
|
|
221
|
-
return `${formatIntegerWithLeadingZeros(timeHMS.hours, 2)}:${formatIntegerWithLeadingZeros(timeHMS.minutes, 2)}:${formatIntegerWithLeadingZeros(timeHMS.seconds, 2)}${decimalSeparator}${formatIntegerWithLeadingZeros(timeHMS.milliseconds, 3)}`
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export function formatMS(timeMS: { minutes: number, seconds: number, milliseconds: number }, decimalSeparator = '.') {
|
|
225
|
-
return `${formatIntegerWithLeadingZeros(timeMS.minutes, 2)}:${formatIntegerWithLeadingZeros(timeMS.seconds, 2)}${decimalSeparator}${formatIntegerWithLeadingZeros(timeMS.milliseconds, 3)}`
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export function formatIntegerWithLeadingZeros(num: number, minDigitCount: number) {
|
|
229
|
-
num = Math.floor(num)
|
|
230
|
-
|
|
231
|
-
let numAsString = `${num}`
|
|
232
|
-
|
|
233
|
-
while (numAsString.length < minDigitCount) {
|
|
234
|
-
numAsString = `0${numAsString}`
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return numAsString
|
|
238
|
-
}
|
|
239
|
-
|
|
240
169
|
export function intsInRange(start: number, end: number) {
|
|
241
170
|
const result: number[] = []
|
|
242
171
|
|
|
@@ -247,34 +176,6 @@ export function intsInRange(start: number, end: number) {
|
|
|
247
176
|
return result
|
|
248
177
|
}
|
|
249
178
|
|
|
250
|
-
export function randomIntsInRange(count: number, min: number, max: number) {
|
|
251
|
-
const randomArray: number[] = []
|
|
252
|
-
|
|
253
|
-
for (let i = 0; i < count; i++) {
|
|
254
|
-
randomArray.push(randomIntInRange(min, max))
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return randomArray
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export function randomIntInRange(min: number, max: number) {
|
|
261
|
-
return Math.floor(randomFloatInRange(min, max))
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export function randomFloatsInRange(count: number, min = 0.0, max = 1.0) {
|
|
265
|
-
const randomVector: number[] = []
|
|
266
|
-
|
|
267
|
-
for (let i = 0; i < count; i++) {
|
|
268
|
-
randomVector.push(randomFloatInRange(min, max))
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return randomVector
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export function randomFloatInRange(min: number, max: number) {
|
|
275
|
-
return min + Math.random() * (max - min)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
179
|
export function serializeMapToObject<V>(map: Map<string, V>) {
|
|
279
180
|
const obj: { [key: string]: V } = {}
|
|
280
181
|
|
|
@@ -403,30 +304,6 @@ export async function commandExists(command: string) {
|
|
|
403
304
|
}
|
|
404
305
|
}
|
|
405
306
|
|
|
406
|
-
export async function convertHtmlToText(html: string) {
|
|
407
|
-
const { htmlToText } = await import('html-to-text')
|
|
408
|
-
|
|
409
|
-
const text = htmlToText(html, {
|
|
410
|
-
wordwrap: false,
|
|
411
|
-
|
|
412
|
-
selectors: [
|
|
413
|
-
{ selector: 'a', options: { ignoreHref: true } },
|
|
414
|
-
{ selector: 'img', format: 'skip' },
|
|
415
|
-
{ selector: 'h1', options: { uppercase: false } },
|
|
416
|
-
{ selector: 'h2', options: { uppercase: false } },
|
|
417
|
-
{ selector: 'h3', options: { uppercase: false } },
|
|
418
|
-
{ selector: 'h4', options: { uppercase: false } },
|
|
419
|
-
{ selector: 'table', options: { uppercaseHeaderCells: false } }
|
|
420
|
-
]
|
|
421
|
-
})
|
|
422
|
-
|
|
423
|
-
return text || ''
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
export function formatListWithQuotedElements(strings: string[], quoteSymbol = `'`) {
|
|
427
|
-
return strings.map(str => `${quoteSymbol}${str}${quoteSymbol}`).join(', ')
|
|
428
|
-
}
|
|
429
|
-
|
|
430
307
|
export async function resolveModuleMainPath(moduleName: string) {
|
|
431
308
|
const { resolve } = await import('import-meta-resolve')
|
|
432
309
|
const { fileURLToPath } = await import('url')
|
|
@@ -463,70 +340,6 @@ export function splitFilenameOnExtendedExtension(filenameWithExtension: string)
|
|
|
463
340
|
return [name, ext]
|
|
464
341
|
}
|
|
465
342
|
|
|
466
|
-
export function getUTF32Chars(str: string) {
|
|
467
|
-
const utf32chars: string[] = []
|
|
468
|
-
const mapping: number[] = []
|
|
469
|
-
|
|
470
|
-
let utf32Index = 0
|
|
471
|
-
|
|
472
|
-
for (const utf32char of str) {
|
|
473
|
-
utf32chars.push(utf32char)
|
|
474
|
-
|
|
475
|
-
for (let i = 0; i < utf32char.length; i++) {
|
|
476
|
-
mapping.push(utf32Index)
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
utf32Index += 1
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
mapping.push(utf32Index)
|
|
483
|
-
|
|
484
|
-
return { utf32chars, mapping }
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
export function getTokenRepetitionScore(tokens: string[] | number[]) {
|
|
488
|
-
const maxCycleLength = Math.floor(tokens.length / 2)
|
|
489
|
-
|
|
490
|
-
const matchLengthForCycleLength: number[] = [0]
|
|
491
|
-
|
|
492
|
-
for (let cycleLength = 1; cycleLength <= maxCycleLength; cycleLength++) {
|
|
493
|
-
let matchCount = 0
|
|
494
|
-
|
|
495
|
-
for (let leftIndex = cycleLength; leftIndex < tokens.length; leftIndex++) {
|
|
496
|
-
const referenceIndex = leftIndex - cycleLength
|
|
497
|
-
|
|
498
|
-
if (tokens[leftIndex] !== tokens[referenceIndex]) {
|
|
499
|
-
break
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
matchCount += 1
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
const score = matchCount
|
|
506
|
-
|
|
507
|
-
matchLengthForCycleLength.push(score)
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
let longestMatch = -Infinity
|
|
511
|
-
let longestCycleRepetition = -Infinity
|
|
512
|
-
|
|
513
|
-
for (let i = 1; i <= matchLengthForCycleLength.length; i++) {
|
|
514
|
-
const matchLength = matchLengthForCycleLength[i]
|
|
515
|
-
|
|
516
|
-
if (matchLength > longestMatch) {
|
|
517
|
-
longestMatch = matchLength
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
const cycleCount = (matchLength / i) + 1
|
|
521
|
-
|
|
522
|
-
if (cycleCount > longestCycleRepetition) {
|
|
523
|
-
longestCycleRepetition = cycleCount
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
return { longestMatch, longestCycleRepetition }
|
|
528
|
-
}
|
|
529
|
-
|
|
530
343
|
export async function resolveModuleScriptPath(moduleName: string) {
|
|
531
344
|
const { resolve } = await import('import-meta-resolve')
|
|
532
345
|
|
|
@@ -610,49 +423,3 @@ export function getIntegerRange(start: number, end: number): number[] {
|
|
|
610
423
|
return result
|
|
611
424
|
}
|
|
612
425
|
|
|
613
|
-
export function containsInvalidCodepoint(str: string) {
|
|
614
|
-
for (const char of str) {
|
|
615
|
-
if (char.codePointAt(0) === 65533) {
|
|
616
|
-
return true
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
return false
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
export function splitAndPreserveSeparators(text: string, separatorRegex: RegExp): string[] {
|
|
624
|
-
if (!separatorRegex.flags.includes('g')) {
|
|
625
|
-
throw new Error('RegExp must be global')
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// Use the match method to find all matches for the separators
|
|
629
|
-
const matches = text.match(separatorRegex)
|
|
630
|
-
|
|
631
|
-
// If no matches are found, return the original text as a single element array
|
|
632
|
-
if (!matches) {
|
|
633
|
-
return [text]
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
// Initialize the result array
|
|
637
|
-
const result: string[] = []
|
|
638
|
-
|
|
639
|
-
// Initialize the start position
|
|
640
|
-
let lastIndex = 0
|
|
641
|
-
|
|
642
|
-
// Iterate through the matches
|
|
643
|
-
matches.forEach(match => {
|
|
644
|
-
// Get the index of the current match
|
|
645
|
-
const matchIndex = text.indexOf(match, lastIndex)
|
|
646
|
-
|
|
647
|
-
// Add the substring before the match to the result, joined with the match itself
|
|
648
|
-
result.push(text.substring(lastIndex, matchIndex) + match)
|
|
649
|
-
|
|
650
|
-
// Update the last index to the end of the current match
|
|
651
|
-
lastIndex = matchIndex + match.length
|
|
652
|
-
})
|
|
653
|
-
|
|
654
|
-
// Add the remaining substring after the last match to the result
|
|
655
|
-
result.push(text.substring(lastIndex))
|
|
656
|
-
|
|
657
|
-
return result
|
|
658
|
-
}
|
|
@@ -2,8 +2,8 @@ import { Readability } from '@mozilla/readability'
|
|
|
2
2
|
import { JSDOM, VirtualConsole } from 'jsdom'
|
|
3
3
|
import { request } from 'gaxios'
|
|
4
4
|
import { Logger } from './Logger.js'
|
|
5
|
-
import { convertHtmlToText } from './Utilities.js'
|
|
6
5
|
import { getChromeOnWindowsHeaders } from './BrowserRequestHeaders.js'
|
|
6
|
+
import { convertHtmlToText } from './StringUtilities.js'
|
|
7
7
|
|
|
8
8
|
export async function fetchDocumentText(url: string) {
|
|
9
9
|
const progressLogger = new Logger()
|
|
@@ -4,7 +4,7 @@ import { Logger } from './Logger.js'
|
|
|
4
4
|
export async function parseWikipediaArticle(articleName: string, language: string) {
|
|
5
5
|
const logger = new Logger()
|
|
6
6
|
|
|
7
|
-
logger.startAsync('Fetching Wikipedia article')
|
|
7
|
+
await logger.startAsync('Fetching Wikipedia article')
|
|
8
8
|
|
|
9
9
|
const { default: wtf } = await import('wtf_wikipedia')
|
|
10
10
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class WindowedList<T> {
|
|
2
|
+
elements: T[] = []
|
|
3
|
+
startOffset = 0
|
|
4
|
+
|
|
5
|
+
constructor(public readonly maxWindowLength: number) {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
add(value: T) {
|
|
9
|
+
if (this.elements.length === this.maxWindowLength) {
|
|
10
|
+
this.elements.shift()
|
|
11
|
+
|
|
12
|
+
this.startOffset += 1
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.elements.push(value)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get(index: number) {
|
|
19
|
+
if (index < this.startOffset) {
|
|
20
|
+
throw new Error(`Index is smaller than to window start offset.`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (index >= this.endOffset) {
|
|
24
|
+
throw new Error(`Index is beyond window end offset.`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return this.elements[index - this.startOffset]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
slice(startIndex: number, endIndex: number) {
|
|
31
|
+
const result: T[] = []
|
|
32
|
+
|
|
33
|
+
endIndex = Math.min(endIndex, this.endOffset)
|
|
34
|
+
|
|
35
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
36
|
+
result.push(this.get(i))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get endOffset() {
|
|
43
|
+
return this.startOffset + this.elements.length
|
|
44
|
+
}
|
|
45
|
+
}
|