echogarden 1.4.4 → 1.6.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 +310 -25
- package/dist/alignment/DTWMfccSequenceAlignment.d.ts +1 -1
- package/dist/alignment/DTWMfccSequenceAlignment.js +5 -5
- package/dist/alignment/DTWSequenceAlignmentWindowed.js +1 -3
- package/dist/alignment/DTWSequenceAlignmentWindowed.js.map +1 -1
- package/dist/alignment/{TextAlignment.d.ts → SemanticTextAlignment.d.ts} +4 -2
- package/dist/alignment/SemanticTextAlignment.js +336 -0
- package/dist/alignment/SemanticTextAlignment.js.map +1 -0
- package/dist/alignment/SpeechAlignment.d.ts +4 -3
- package/dist/alignment/SpeechAlignment.js +130 -39
- package/dist/alignment/SpeechAlignment.js.map +1 -1
- package/dist/api/API.d.ts +7 -3
- package/dist/api/API.js +7 -2
- package/dist/api/API.js.map +1 -1
- package/dist/api/APIOptions.d.ts +4 -1
- package/dist/api/Alignment.d.ts +1 -1
- package/dist/api/Alignment.js +13 -5
- package/dist/api/Alignment.js.map +1 -1
- package/dist/api/LanguageDetectionCommon.d.ts +6 -0
- package/dist/api/LanguageDetectionCommon.js +2 -0
- package/dist/api/LanguageDetectionCommon.js.map +1 -0
- package/dist/api/Recognition.js.map +1 -1
- package/dist/api/{LanguageDetection.d.ts → SpeechLanguageDetection.d.ts} +1 -25
- package/dist/api/{LanguageDetection.js → SpeechLanguageDetection.js} +1 -68
- package/dist/api/SpeechLanguageDetection.js.map +1 -0
- package/dist/api/{Translation.js → SpeechTranslation.js} +3 -3
- package/dist/api/SpeechTranslation.js.map +1 -0
- package/dist/api/Synthesis.d.ts +0 -1
- package/dist/api/Synthesis.js +4 -4
- package/dist/api/TextLanguageDetection.d.ts +21 -0
- package/dist/api/TextLanguageDetection.js +67 -0
- package/dist/api/TextLanguageDetection.js.map +1 -0
- package/dist/api/TextTranslation.d.ts +25 -0
- package/dist/api/TextTranslation.js +101 -0
- package/dist/api/TextTranslation.js.map +1 -0
- package/dist/api/TimelineTranslationAlignment.d.ts +23 -0
- package/dist/api/TimelineTranslationAlignment.js +92 -0
- package/dist/api/TimelineTranslationAlignment.js.map +1 -0
- package/dist/api/TranscriptAndTranslationAlignment.d.ts +35 -0
- package/dist/api/TranscriptAndTranslationAlignment.js +78 -0
- package/dist/api/TranscriptAndTranslationAlignment.js.map +1 -0
- package/dist/api/TranslationAlignment.d.ts +4 -3
- package/dist/api/TranslationAlignment.js +9 -8
- package/dist/api/TranslationAlignment.js.map +1 -1
- package/dist/api/VoiceActivityDetection.js +16 -1
- package/dist/api/VoiceActivityDetection.js.map +1 -1
- package/dist/audio/AudioBufferConversion.d.ts +0 -1
- package/dist/audio/AudioPlayer.d.ts +0 -1
- package/dist/audio/AudioPlayer.js +62 -41
- package/dist/audio/AudioPlayer.js.map +1 -1
- package/dist/audio/AudioUtilities.d.ts +0 -1
- package/dist/cli/CLI.d.ts +28 -7
- package/dist/cli/CLI.js +265 -37
- package/dist/cli/CLI.js.map +1 -1
- package/dist/codecs/FFMpegTranscoder.d.ts +0 -1
- package/dist/codecs/FFMpegTranscoder.js +7 -0
- package/dist/codecs/FFMpegTranscoder.js.map +1 -1
- package/dist/codecs/TIMITCodec.d.ts +0 -1
- package/dist/codecs/WaveCodec.d.ts +0 -1
- package/dist/dsp/FFT.d.ts +1 -1
- package/dist/dsp/FFT.js +6 -0
- package/dist/dsp/FFT.js.map +1 -1
- package/dist/dsp/KWeightingFilter.js +1 -1
- package/dist/dsp/KWeightingFilter.js.map +1 -1
- package/dist/dsp/MelSpectogram.d.ts +3 -2
- package/dist/dsp/MelSpectogram.js +14 -8
- package/dist/dsp/MelSpectogram.js.map +1 -1
- package/dist/math/VectorMath.d.ts +9 -9
- package/dist/math/VectorMath.js +10 -10
- package/dist/math/VectorMath.js.map +1 -1
- package/dist/nlp/ChineseSegmentation.js +4 -4
- package/dist/nlp/ChineseSegmentation.js.map +1 -1
- package/dist/nlp/Segmentation.d.ts +2 -2
- package/dist/nlp/Segmentation.js +20 -13
- package/dist/nlp/Segmentation.js.map +1 -1
- package/dist/recognition/OpenAICloudSTT.d.ts +2 -1
- package/dist/recognition/OpenAICloudSTT.js +30 -19
- package/dist/recognition/OpenAICloudSTT.js.map +1 -1
- package/dist/recognition/SileroSTT.d.ts +0 -1
- package/dist/recognition/WhisperCppSTT.d.ts +3 -3
- package/dist/recognition/WhisperCppSTT.js +21 -9
- package/dist/recognition/WhisperCppSTT.js.map +1 -1
- package/dist/recognition/WhisperSTT.d.ts +9 -6
- package/dist/recognition/WhisperSTT.js +227 -46
- package/dist/recognition/WhisperSTT.js.map +1 -1
- package/dist/server/Client.d.ts +3 -4
- package/dist/server/Client.js.map +1 -1
- package/dist/server/Worker.d.ts +3 -3
- package/dist/server/Worker.js +3 -2
- package/dist/server/Worker.js.map +1 -1
- package/dist/source-separation/MDXNetSourceSeparation.d.ts +0 -1
- package/dist/source-separation/MDXNetSourceSeparation.js +1 -1
- package/dist/source-separation/MDXNetSourceSeparation.js.map +1 -1
- package/dist/speech-embeddings/WavToVec2BertFeatureEmbeddings.d.ts +12 -0
- package/dist/speech-embeddings/WavToVec2BertFeatureEmbeddings.js +68 -0
- package/dist/speech-embeddings/WavToVec2BertFeatureEmbeddings.js.map +1 -0
- package/dist/speech-language-detection/SileroLanguageDetection.d.ts +1 -2
- package/dist/speech-language-detection/SileroLanguageDetection.js +1 -1
- package/dist/speech-language-detection/SileroLanguageDetection.js.map +1 -1
- package/dist/subtitles/Subtitles.js +2 -2
- package/dist/subtitles/Subtitles.js.map +1 -1
- package/dist/synthesis/GoogleCloudTTS.d.ts +0 -1
- package/dist/synthesis/GoogleTranslateTTS.d.ts +0 -1
- package/dist/synthesis/GoogleTranslateTTS.js +6 -21
- package/dist/synthesis/GoogleTranslateTTS.js.map +1 -1
- package/dist/synthesis/StreamlabsPollyTTS.d.ts +0 -1
- package/dist/synthesis/VitsTTS.d.ts +0 -1
- package/dist/synthesis/VitsTTS.js +30 -0
- package/dist/synthesis/VitsTTS.js.map +1 -1
- package/dist/tests/Test.js +0 -31
- package/dist/tests/Test.js.map +1 -1
- package/dist/text-language-detection/FastTextLanguageDetection.d.ts +1 -1
- package/dist/text-language-detection/FastTextLanguageDetection.js.map +1 -1
- package/dist/text-language-detection/TinyLDLanguageDetection.d.ts +1 -1
- package/dist/text-language-detection/TinyLDLanguageDetection.js.map +1 -1
- package/dist/text-translation/DeepLTextTranslation.d.ts +2 -0
- package/dist/text-translation/DeepLTextTranslation.js +67 -0
- package/dist/text-translation/DeepLTextTranslation.js.map +1 -0
- package/dist/text-translation/GoogleTranslateTextTranslation.d.ts +10 -0
- package/dist/text-translation/GoogleTranslateTextTranslation.js +554 -0
- package/dist/text-translation/GoogleTranslateTextTranslation.js.map +1 -0
- package/dist/text-translation/NLLBTextTranslation.d.ts +2 -1
- package/dist/text-translation/NLLBTextTranslation.js +249 -19
- package/dist/text-translation/NLLBTextTranslation.js.map +1 -1
- package/dist/utilities/BinaryArrayConversion.d.ts +0 -1
- package/dist/utilities/BrowserRequestHeaders.d.ts +6 -0
- package/dist/utilities/BrowserRequestHeaders.js +52 -0
- package/dist/utilities/BrowserRequestHeaders.js.map +1 -0
- package/dist/utilities/BufferFileReadStream.d.ts +20 -0
- package/dist/utilities/BufferFileReadStream.js +81 -0
- package/dist/utilities/BufferFileReadStream.js.map +1 -0
- package/dist/utilities/DynamicUint8Array.d.ts +9 -0
- package/dist/utilities/DynamicUint8Array.js +31 -0
- package/dist/utilities/DynamicUint8Array.js.map +1 -0
- package/dist/utilities/FileSystem.d.ts +0 -2
- package/dist/utilities/Hashing.d.ts +3 -10
- package/dist/utilities/Hashing.js +10 -127
- package/dist/utilities/Hashing.js.map +1 -1
- package/dist/utilities/LEB128.d.ts +15 -5
- package/dist/utilities/LEB128.js +199 -119
- package/dist/utilities/LEB128.js.map +1 -1
- package/dist/utilities/LPVarInt.d.ts +11 -0
- package/dist/utilities/LPVarInt.js +187 -0
- package/dist/utilities/LPVarInt.js.map +1 -0
- package/dist/utilities/Locale.d.ts +1 -1
- package/dist/utilities/Locale.js +1 -1
- package/dist/utilities/OnnxUtilities.d.ts +1 -2
- package/dist/utilities/PVarInt.d.ts +4 -0
- package/dist/utilities/PVarInt.js +166 -0
- package/dist/utilities/PVarInt.js.map +1 -0
- package/dist/utilities/PackageManager.js +48 -25
- package/dist/utilities/PackageManager.js.map +1 -1
- package/dist/utilities/RandomGenerator.d.ts +3 -17
- package/dist/utilities/RandomGenerator.js +12 -81
- package/dist/utilities/RandomGenerator.js.map +1 -1
- package/dist/utilities/Timeline.d.ts +2 -0
- package/dist/utilities/Timeline.js +129 -20
- package/dist/utilities/Timeline.js.map +1 -1
- package/dist/utilities/Utilities.d.ts +1 -3
- package/dist/utilities/Utilities.js +30 -3
- package/dist/utilities/Utilities.js.map +1 -1
- package/dist/utilities/VarInt.d.ts +4 -0
- package/dist/utilities/VarInt.js +166 -0
- package/dist/utilities/VarInt.js.map +1 -0
- package/dist/utilities/VirtualFileReadStream.d.ts +20 -0
- package/dist/utilities/VirtualFileReadStream.js +79 -0
- package/dist/utilities/VirtualFileReadStream.js.map +1 -0
- package/dist/utilities/WebReader.js +7 -23
- package/dist/utilities/WebReader.js.map +1 -1
- package/dist/voice-activity-detection/SileroVAD.d.ts +0 -1
- package/docs/API.md +105 -3
- package/docs/CLI.md +51 -1
- package/docs/Engines.md +32 -3
- package/docs/Options.md +53 -12
- package/docs/Tasklist.md +1 -13
- package/package.json +20 -24
- package/src/alignment/DTWMfccSequenceAlignment.ts +5 -5
- package/src/alignment/DTWSequenceAlignmentWindowed.ts +1 -3
- package/src/alignment/SemanticTextAlignment.ts +467 -0
- package/src/alignment/SpeechAlignment.ts +214 -56
- package/src/api/API.ts +18 -2
- package/src/api/APIOptions.ts +14 -1
- package/src/api/Alignment.ts +31 -9
- package/src/api/LanguageDetectionCommon.ts +7 -0
- package/src/api/Recognition.ts +2 -0
- package/src/api/{LanguageDetection.ts → SpeechLanguageDetection.ts} +1 -119
- package/src/api/{Translation.ts → SpeechTranslation.ts} +2 -2
- package/src/api/Synthesis.ts +4 -4
- package/src/api/TextLanguageDetection.ts +116 -0
- package/src/api/TextTranslation.ts +177 -0
- package/src/api/TimelineTranslationAlignment.ts +162 -0
- package/src/api/TranscriptAndTranslationAlignment.ts +164 -0
- package/src/api/TranslationAlignment.ts +12 -10
- package/src/api/VoiceActivityDetection.ts +24 -3
- package/src/audio/AudioPlayer.ts +2 -0
- package/src/cli/CLI.ts +376 -40
- package/src/codecs/FFMpegTranscoder.ts +6 -0
- package/src/dsp/FFT.ts +8 -2
- package/src/dsp/KWeightingFilter.ts +1 -1
- package/src/dsp/MelSpectogram.ts +17 -8
- package/src/math/VectorMath.ts +15 -15
- package/src/nlp/ChineseSegmentation.ts +6 -4
- package/src/nlp/Segmentation.ts +18 -13
- package/src/recognition/OpenAICloudSTT.ts +47 -29
- package/src/recognition/WhisperCppSTT.ts +26 -11
- package/src/recognition/WhisperSTT.ts +364 -49
- package/src/server/Client.ts +3 -2
- package/src/server/Worker.ts +3 -2
- package/src/source-separation/MDXNetSourceSeparation.ts +1 -1
- package/src/speech-embeddings/WavToVec2BertFeatureEmbeddings.ts +107 -0
- package/src/speech-language-detection/SileroLanguageDetection.ts +2 -1
- package/src/subtitles/Subtitles.ts +2 -2
- package/src/synthesis/GoogleTranslateTTS.ts +7 -21
- package/src/synthesis/VitsTTS.ts +31 -3
- package/src/tests/Test.ts +1 -38
- package/src/text-language-detection/FastTextLanguageDetection.ts +1 -1
- package/src/text-language-detection/TinyLDLanguageDetection.ts +1 -1
- package/src/text-translation/DeepLTextTranslation.ts +88 -0
- package/src/text-translation/GoogleTranslateTextTranslation.ts +667 -0
- package/src/text-translation/NLLBTextTranslation.ts +261 -21
- package/src/typings/Fillers.d.ts +25 -2
- package/src/utilities/BrowserRequestHeaders.ts +59 -0
- package/src/utilities/DynamicUint8Array.ts +39 -0
- package/src/utilities/Hashing.ts +14 -167
- package/src/utilities/LEB128.ts +273 -148
- package/src/utilities/LPVarInt.ts +292 -0
- package/src/utilities/Locale.ts +1 -1
- package/src/utilities/OnnxUtilities.ts +1 -1
- package/src/utilities/PackageManager.ts +51 -30
- package/src/utilities/RandomGenerator.ts +12 -113
- package/src/utilities/Timeline.ts +162 -23
- package/src/utilities/Utilities.ts +40 -3
- package/src/utilities/VirtualFileReadStream.ts +109 -0
- package/src/utilities/WebReader.ts +9 -23
- package/dist/alignment/TextAlignment.js +0 -156
- package/dist/alignment/TextAlignment.js.map +0 -1
- package/dist/api/LanguageDetection.js.map +0 -1
- package/dist/api/Translation.js.map +0 -1
- package/src/alignment/TextAlignment.ts +0 -234
- /package/dist/api/{Translation.d.ts → SpeechTranslation.d.ts} +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Encode signed integer
|
|
3
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
4
|
+
export function encodeSignedInt32(value, outEncodedData) {
|
|
5
|
+
//const absValue = Math.abs(value)
|
|
6
|
+
const absMask = value >> 31;
|
|
7
|
+
const absValue = (value ^ absMask) - absMask;
|
|
8
|
+
if (absValue < (2 ** 6)) {
|
|
9
|
+
outEncodedData.push(value & 0b01111111);
|
|
10
|
+
}
|
|
11
|
+
else if (absValue < (2 ** 13)) {
|
|
12
|
+
outEncodedData.push((value & 0b00111111) | 0b10000000, (value >> 6) & 0b11111111);
|
|
13
|
+
}
|
|
14
|
+
else if (absValue < (2 ** 20)) {
|
|
15
|
+
outEncodedData.push((value & 0b00011111) | 0b11000000, (value >> 5) & 0b11111111, (value >> 13) & 0b11111111);
|
|
16
|
+
}
|
|
17
|
+
else if (absValue < (2 ** 27)) {
|
|
18
|
+
outEncodedData.push((value & 0b00001111) | 0b11100000, (value >> 4) & 0b11111111, (value >> 12) & 0b11111111, (value >> 20) & 0b11111111);
|
|
19
|
+
}
|
|
20
|
+
else if (value < (2 ** 31) && value >= -(2 ** 31)) {
|
|
21
|
+
outEncodedData.push(0b11110000, value & 0b11111111, (value >> 8) & 0b11111111, (value >> 16) & 0b11111111, (value >> 24) & 0b11111111);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw new Error(`Input value must be within the range of an int31: between -(2^31) and 2^31 - 1`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
28
|
+
// Decode signed integer
|
|
29
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
30
|
+
export function decodeSignedInt32s(encodedData, outDecodedValues) {
|
|
31
|
+
for (let readIndex = 0; readIndex < encodedData.length;) {
|
|
32
|
+
const byte0 = encodedData[readIndex++];
|
|
33
|
+
if ((byte0 & 0b10000000) === 0) {
|
|
34
|
+
// 1 byte
|
|
35
|
+
let decodedValue = byte0;
|
|
36
|
+
if ((byte0 & 0b01000000) !== 0) {
|
|
37
|
+
decodedValue |= (-1 << 7);
|
|
38
|
+
}
|
|
39
|
+
outDecodedValues.push(decodedValue);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const byte1 = encodedData[readIndex++];
|
|
43
|
+
if ((byte0 & 0b01000000) === 0) {
|
|
44
|
+
// 2 bytes
|
|
45
|
+
let decodedValue = (byte0 & 0b00111111) |
|
|
46
|
+
(byte1 << 6);
|
|
47
|
+
if ((byte1 & 0b10000000) !== 0) {
|
|
48
|
+
decodedValue |= (-1 << 14);
|
|
49
|
+
}
|
|
50
|
+
outDecodedValues.push(decodedValue);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const byte2 = encodedData[readIndex++];
|
|
54
|
+
if ((byte0 & 0b00100000) === 0) {
|
|
55
|
+
// 3 bytes
|
|
56
|
+
let decodedValue = (byte0 & 0b00011111) |
|
|
57
|
+
(byte1 << 5) |
|
|
58
|
+
(byte2 << 13);
|
|
59
|
+
if ((byte2 & 0b10000000) !== 0) {
|
|
60
|
+
decodedValue |= (-1 << 21);
|
|
61
|
+
}
|
|
62
|
+
outDecodedValues.push(decodedValue);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const byte3 = encodedData[readIndex++];
|
|
66
|
+
if ((byte0 & 0b00010000) === 0) {
|
|
67
|
+
// 4 bytes
|
|
68
|
+
let decodedValue = (byte0 & 0b00001111) |
|
|
69
|
+
(byte1 << 4) |
|
|
70
|
+
(byte2 << 12) |
|
|
71
|
+
(byte3 << 20);
|
|
72
|
+
if ((byte3 & 0b10000000) !== 0) {
|
|
73
|
+
decodedValue |= (-1 << 28);
|
|
74
|
+
}
|
|
75
|
+
outDecodedValues.push(decodedValue);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const byte4 = encodedData[readIndex++];
|
|
79
|
+
if (byte0 === 0b11110000) {
|
|
80
|
+
// 5 bytes
|
|
81
|
+
let decodedValue = (byte1) |
|
|
82
|
+
(byte2 << 8) |
|
|
83
|
+
(byte3 << 16) |
|
|
84
|
+
(byte4 << 24);
|
|
85
|
+
outDecodedValues.push(decodedValue);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`Encountered a value that is encoded with more than 5 bytes (beyond int32 range).`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
92
|
+
// Encode signed integer
|
|
93
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
94
|
+
export function encodeUnsignedInt31(value, outEncodedData) {
|
|
95
|
+
if (value < (2 ** 7)) {
|
|
96
|
+
outEncodedData.push(value);
|
|
97
|
+
}
|
|
98
|
+
else if (value < (2 ** 14)) {
|
|
99
|
+
outEncodedData.push((value & 0b00111111) | 0b10000000, (value >>> 6) & 0b11111111);
|
|
100
|
+
}
|
|
101
|
+
else if (value < (2 ** 21)) {
|
|
102
|
+
outEncodedData.push((value & 0b00011111) | 0b11000000, (value >>> 5) & 0b11111111, (value >>> 13) & 0b11111111);
|
|
103
|
+
}
|
|
104
|
+
else if (value < (2 ** 28)) {
|
|
105
|
+
outEncodedData.push((value & 0b00001111) | 0b11100000, (value >>> 4) & 0b11111111, (value >>> 12) & 0b11111111, (value >>> 20) & 0b11111111);
|
|
106
|
+
}
|
|
107
|
+
else if (value < (2 ** 31)) {
|
|
108
|
+
outEncodedData.push(0b11110000, value & 0b11111111, (value >>> 8) & 0b11111111, (value >>> 16) & 0b11111111, (value >>> 24) & 0b11111111);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
throw new Error(`Input value must be within the range of an int31: between 0 and 2^31 - 1.`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
115
|
+
// Decode unsigned integer
|
|
116
|
+
////////////////////////////////////////////////////////////////////////////////////
|
|
117
|
+
export function decodeUnsignedInt31s(encodedData, outDecodedValues) {
|
|
118
|
+
for (let readIndex = 0; readIndex < encodedData.length;) {
|
|
119
|
+
const byte0 = encodedData[readIndex++];
|
|
120
|
+
if ((byte0 & 0b10000000) === 0) {
|
|
121
|
+
// 1 byte
|
|
122
|
+
let decodedValue = byte0;
|
|
123
|
+
outDecodedValues.push(decodedValue);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const byte1 = encodedData[readIndex++];
|
|
127
|
+
if ((byte0 & 0b01000000) === 0) {
|
|
128
|
+
// 2 bytes
|
|
129
|
+
let decodedValue = (byte0 & 0b00111111) |
|
|
130
|
+
(byte1 << 6);
|
|
131
|
+
outDecodedValues.push(decodedValue);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const byte2 = encodedData[readIndex++];
|
|
135
|
+
if ((byte0 & 0b00100000) === 0) {
|
|
136
|
+
// 3 bytes
|
|
137
|
+
let decodedValue = (byte0 & 0b00011111) |
|
|
138
|
+
(byte1 << 5) |
|
|
139
|
+
(byte2 << 13);
|
|
140
|
+
outDecodedValues.push(decodedValue);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const byte3 = encodedData[readIndex++];
|
|
144
|
+
if ((byte0 & 0b00010000) === 0) {
|
|
145
|
+
// 4 bytes
|
|
146
|
+
let decodedValue = (byte0 & 0b00001111) |
|
|
147
|
+
(byte1 << 4) |
|
|
148
|
+
(byte2 << 12) |
|
|
149
|
+
(byte3 << 20);
|
|
150
|
+
outDecodedValues.push(decodedValue);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const byte4 = encodedData[readIndex++];
|
|
154
|
+
if (byte0 === 0b11110000) {
|
|
155
|
+
// 5 bytes
|
|
156
|
+
let decodedValue = (byte1) |
|
|
157
|
+
(byte2 << 8) |
|
|
158
|
+
(byte3 << 16) |
|
|
159
|
+
(byte4 << 24);
|
|
160
|
+
outDecodedValues.push(decodedValue);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
throw new Error(`Encountered a value that is encoded with more than 5 bytes (beyond uint31 range).`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=VarInt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VarInt.js","sourceRoot":"","sources":["../../src/utilities/VarInt.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,wBAAwB;AACxB,oFAAoF;AACpF,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,cAAwB;IACxE,kCAAkC;IAElC,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE,CAAA;IAC3B,MAAM,QAAQ,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,OAAO,CAAA;IAE5C,IAAI,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACzB,cAAc,CAAC,IAAI,CAClB,KAAK,GAAG,UAAU,CAClB,CAAA;IACF,CAAC;SAAM,IAAI,QAAQ,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QACjC,cAAc,CAAC,IAAI,CAClB,CAAC,KAAK,GAAG,UAAU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,YAAY,GACf,CAAC,KAAK,GAAG,UAAU,CAAC;gBACpB,CAAC,KAAK,IAAI,CAAC,CAAC;gBACZ,CAAC,KAAK,IAAI,EAAE,CAAC;gBACb,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;YAEd,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAEnC,SAAQ;QACT,CAAC;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC,CAAA;QAEtC,IAAI,KAAK,KAAK,UAAU,EAAE,CAAC;YAC1B,UAAU;YACV,IAAI,YAAY,GACf,CAAC,KAAK,CAAC;gBACP,CAAC,KAAK,IAAI,CAAC,CAAC;gBACZ,CAAC,KAAK,IAAI,EAAE,CAAC;gBACb,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;YAEd,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAEnC,SAAQ;QACT,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAA;IACrG,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { ReadStream as FsReadStream } from 'fs';
|
|
4
|
+
export declare function createVirtualFileReadStreamForBuffer(buffer: Buffer, path?: string | Buffer): FsReadStream;
|
|
5
|
+
export declare class VirtualFileReadStream extends Readable {
|
|
6
|
+
private readonly buffer;
|
|
7
|
+
position: number;
|
|
8
|
+
bytesRead: number;
|
|
9
|
+
readonly path: string | Buffer;
|
|
10
|
+
pending: boolean;
|
|
11
|
+
readonly emitter: EventEmitter;
|
|
12
|
+
constructor(buffer: Buffer, virtualPath?: string | Buffer);
|
|
13
|
+
_read(size: number): void;
|
|
14
|
+
close(callback?: (err?: NodeJS.ErrnoException | null) => void): void;
|
|
15
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
16
|
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
17
|
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
18
|
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
19
|
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
20
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { ReadStream as FsReadStream } from 'fs';
|
|
4
|
+
export function createVirtualFileReadStreamForBuffer(buffer, path) {
|
|
5
|
+
const bufferReadStream = new VirtualFileReadStream(buffer, path);
|
|
6
|
+
const proxyStream = new Proxy(bufferReadStream, {
|
|
7
|
+
get(target, prop) {
|
|
8
|
+
if (prop === Symbol.toStringTag) {
|
|
9
|
+
return 'ReadStream';
|
|
10
|
+
}
|
|
11
|
+
return target[prop];
|
|
12
|
+
},
|
|
13
|
+
getPrototypeOf() {
|
|
14
|
+
return FsReadStream.prototype;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return proxyStream;
|
|
18
|
+
}
|
|
19
|
+
export class VirtualFileReadStream extends Readable {
|
|
20
|
+
buffer;
|
|
21
|
+
position;
|
|
22
|
+
bytesRead;
|
|
23
|
+
path;
|
|
24
|
+
pending;
|
|
25
|
+
emitter;
|
|
26
|
+
constructor(buffer, virtualPath) {
|
|
27
|
+
super({ autoDestroy: false });
|
|
28
|
+
this.buffer = buffer;
|
|
29
|
+
this.position = 0;
|
|
30
|
+
this.bytesRead = 0;
|
|
31
|
+
this.path = virtualPath || '';
|
|
32
|
+
this.pending = true;
|
|
33
|
+
this.emitter = new EventEmitter();
|
|
34
|
+
this.emitter.emit('open', 0);
|
|
35
|
+
this.pending = false;
|
|
36
|
+
this.emitter.emit('ready');
|
|
37
|
+
}
|
|
38
|
+
_read(size) {
|
|
39
|
+
if (this.position >= this.buffer.length) {
|
|
40
|
+
this.push(null);
|
|
41
|
+
this.emitter.emit('end');
|
|
42
|
+
this.emitter.emit('finish');
|
|
43
|
+
this.emitter.emit('close');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const chunkSize = Math.min(size, this.buffer.length - this.position);
|
|
47
|
+
const chunk = this.buffer.subarray(this.position, this.position + chunkSize);
|
|
48
|
+
this.position += chunkSize;
|
|
49
|
+
this.bytesRead = this.position;
|
|
50
|
+
this.push(chunk);
|
|
51
|
+
}
|
|
52
|
+
close(callback) {
|
|
53
|
+
this.emitter.emit('close');
|
|
54
|
+
if (callback) {
|
|
55
|
+
callback(null);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
addListener(event, listener) {
|
|
59
|
+
this.emitter.addListener(event, listener);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
on(event, listener) {
|
|
63
|
+
this.emitter.on(event, listener);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
once(event, listener) {
|
|
67
|
+
this.emitter.once(event, listener);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
prependListener(event, listener) {
|
|
71
|
+
this.emitter.prependListener(event, listener);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
prependOnceListener(event, listener) {
|
|
75
|
+
this.emitter.prependOnceListener(event, listener);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=VirtualFileReadStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualFileReadStream.js","sourceRoot":"","sources":["../../src/utilities/VirtualFileReadStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,IAAI,CAAA;AAE/C,MAAM,UAAU,oCAAoC,CAAC,MAAc,EAAE,IAAsB;IAC1F,MAAM,gBAAgB,GAAG,IAAI,q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CAAC,CAAA;QAElC,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,eAAe,CAAC,KAAsB,EAAE,QAAkC;QACzE,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAE7C,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,mBAAmB,CAAC,KAAsB,EAAE,QAAkC;QAC7E,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAEjD,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
|
|
@@ -3,35 +3,19 @@ import { JSDOM, VirtualConsole } from 'jsdom';
|
|
|
3
3
|
import { request } from 'gaxios';
|
|
4
4
|
import { Logger } from './Logger.js';
|
|
5
5
|
import { convertHtmlToText } from './Utilities.js';
|
|
6
|
+
import { getChromeOnWindowsHeaders } from './BrowserRequestHeaders.js';
|
|
6
7
|
export async function fetchDocumentText(url) {
|
|
7
8
|
const progressLogger = new Logger();
|
|
8
9
|
progressLogger.start(`Fetching ${url}`);
|
|
10
|
+
const parsedUrl = new URL(url);
|
|
11
|
+
const origin = parsedUrl.origin;
|
|
9
12
|
const response = await request({
|
|
10
13
|
url,
|
|
11
14
|
responseType: 'text',
|
|
12
|
-
headers: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
17
|
-
'sec-ch-ua-mobile': '?0',
|
|
18
|
-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
|
|
19
|
-
'sec-ch-ua-arch': 'x86',
|
|
20
|
-
'sec-ch-ua-full-version': '103.0.5060.114',
|
|
21
|
-
'sec-ch-ua-platform-version': '10.0.0',
|
|
22
|
-
'sec-ch-ua-full-version-list': `".Not/A)Brand";v="99.0.0.0", "Google Chrome";v="103.0.5060.114", "Chromium";v="103.0.5060.114"`,
|
|
23
|
-
'sec-ch-ua-bitness': '64',
|
|
24
|
-
'sec-ch-ua-model': '',
|
|
25
|
-
'sec-ch-ua-platform': 'Windows',
|
|
26
|
-
'accept': '*/*',
|
|
27
|
-
//'origin': 'https://www.google.com/',
|
|
28
|
-
'sec-fetch-site': 'same-origin',
|
|
29
|
-
'sec-fetch-mode': 'cors',
|
|
30
|
-
'sec-fetch-dest': 'empty',
|
|
31
|
-
'referer': 'https://www.google.com/',
|
|
32
|
-
'accept-encoding': 'gzip, deflate, br',
|
|
33
|
-
'accept-language': 'en-US,en;q=0.9',
|
|
34
|
-
},
|
|
15
|
+
headers: getChromeOnWindowsHeaders({
|
|
16
|
+
origin: origin,
|
|
17
|
+
referrer: `${origin}/`
|
|
18
|
+
}),
|
|
35
19
|
});
|
|
36
20
|
progressLogger.start(`Parsing document body`);
|
|
37
21
|
const doc = new JSDOM(response.data, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebReader.js","sourceRoot":"","sources":["../../src/utilities/WebReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"WebReader.js","sourceRoot":"","sources":["../../src/utilities/WebReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAA;AAEtE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAAW;IAClD,MAAM,cAAc,GAAG,IAAI,MAAM,EAAE,CAAA;IACnC,cAAc,CAAC,KAAK,CAAC,YAAY,GAAG,EAAE,CAAC,CAAA;IAEvC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;IAC9B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAA;IAE/B,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAS;QACtC,GAAG;QACH,YAAY,EAAE,MAAM;QAEpB,OAAO,EAAE,yBAAyB,CAAC;YAClC,MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,GAAG,MAAM,GAAG;SACtB,CAAC;KACF,CAAC,CAAA;IAEF,cAAc,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAE7C,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE;QACpC,GAAG;QACH,cAAc,EAAE,IAAI,cAAc,EAAE;KACpC,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAEnD,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;IAE9B,MAAM,IAAI,GAAW,MAAM,iBAAiB,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC,CAAA;IAEpE,cAAc,CAAC,GAAG,EAAE,CAAA;IAEpB,OAAO,IAAI,CAAA;AACZ,CAAC"}
|
package/docs/API.md
CHANGED
|
@@ -72,10 +72,13 @@ const { audio } = await Echogarden.synthesize("Hello World!", { engine: 'espeak'
|
|
|
72
72
|
{
|
|
73
73
|
index: number // Index of part
|
|
74
74
|
total: number // Total number of parts
|
|
75
|
+
|
|
75
76
|
audio: RawAudio | Buffer // Audio for part
|
|
77
|
+
|
|
76
78
|
timeline: Timeline // Timeline for part
|
|
77
79
|
transcript: string // Transcript for part
|
|
78
80
|
language: string // Language for part
|
|
81
|
+
|
|
79
82
|
peakDecibelsSoFar: number // Peak decibels measured for all synthesized audio, so far
|
|
80
83
|
}
|
|
81
84
|
```
|
|
@@ -109,9 +112,15 @@ Applies speech recognition to the input.
|
|
|
109
112
|
```ts
|
|
110
113
|
{
|
|
111
114
|
transcript: string
|
|
115
|
+
|
|
112
116
|
timeline: Timeline
|
|
113
117
|
wordTimeline: Timeline
|
|
118
|
+
|
|
114
119
|
language: string
|
|
120
|
+
|
|
121
|
+
inputRawAudio: RawAudio
|
|
122
|
+
isolatedRawAudio?: RawAudio
|
|
123
|
+
backgroundRawAudio?: RawAudio
|
|
115
124
|
}
|
|
116
125
|
```
|
|
117
126
|
|
|
@@ -131,8 +140,13 @@ Aligns input audio with the given transcript.
|
|
|
131
140
|
{
|
|
132
141
|
timeline: Timeline
|
|
133
142
|
wordTimeline: Timeline
|
|
143
|
+
|
|
134
144
|
transcript: string
|
|
135
145
|
language: string
|
|
146
|
+
|
|
147
|
+
inputRawAudio: RawAudio
|
|
148
|
+
isolatedRawAudio?: RawAudio
|
|
149
|
+
backgroundRawAudio?: RawAudio
|
|
136
150
|
}
|
|
137
151
|
```
|
|
138
152
|
|
|
@@ -140,7 +154,7 @@ Aligns input audio with the given transcript.
|
|
|
140
154
|
|
|
141
155
|
### `translateSpeech(input, options)`
|
|
142
156
|
|
|
143
|
-
Translates speech audio directly to English
|
|
157
|
+
Translates speech audio directly to a transcript in a different language (only English is currently supported).
|
|
144
158
|
|
|
145
159
|
* `input`: can be an audio file path (`string`), encoded audio (`Buffer` or `Uint8array`) or a raw audio object (`RawAudio`)
|
|
146
160
|
* `options`: speech translation options object
|
|
@@ -150,12 +164,41 @@ Translates speech audio directly to English text.
|
|
|
150
164
|
{
|
|
151
165
|
transcript: string
|
|
152
166
|
timeline: Timeline
|
|
153
|
-
wordTimeline
|
|
167
|
+
wordTimeline?: Timeline
|
|
168
|
+
|
|
169
|
+
sourceLanguage: string
|
|
170
|
+
targetLanguage: string
|
|
171
|
+
|
|
172
|
+
inputRawAudio: RawAudio
|
|
173
|
+
isolatedRawAudio?: RawAudio
|
|
174
|
+
backgroundRawAudio?: RawAudio
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Text-to-text translation
|
|
179
|
+
|
|
180
|
+
### `translateText(input, options)`
|
|
181
|
+
|
|
182
|
+
Translates text to text.
|
|
183
|
+
|
|
184
|
+
* `input`: string
|
|
185
|
+
* `options`: text translation options object
|
|
186
|
+
|
|
187
|
+
#### Returns (via promise):
|
|
188
|
+
```ts
|
|
189
|
+
{
|
|
190
|
+
text: string
|
|
191
|
+
translatedText: string
|
|
192
|
+
|
|
193
|
+
translationPairs: TranslationPair[]
|
|
194
|
+
|
|
154
195
|
sourceLanguage: string
|
|
155
196
|
targetLanguage: string
|
|
156
197
|
}
|
|
157
198
|
```
|
|
158
199
|
|
|
200
|
+
`translationPairs` is an array of objects corresponding to individual segments of the text and their translations.
|
|
201
|
+
|
|
159
202
|
## Speech-to-translated-transcript alignment
|
|
160
203
|
|
|
161
204
|
### `alignTranslation(input, translatedTranscript, options)`
|
|
@@ -172,8 +215,67 @@ Aligns input audio with the given translated transcript.
|
|
|
172
215
|
{
|
|
173
216
|
timeline: Timeline
|
|
174
217
|
wordTimeline: Timeline
|
|
218
|
+
|
|
219
|
+
translatedTranscript: string
|
|
220
|
+
sourceLanguage: string
|
|
221
|
+
targetLanguage: string
|
|
222
|
+
|
|
223
|
+
inputRawAudio: RawAudio
|
|
224
|
+
isolatedRawAudio?: RawAudio
|
|
225
|
+
backgroundRawAudio?: RawAudio
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### `alignTranscriptAndTranslation(input, transcript, translatedTranscript, options)`
|
|
230
|
+
|
|
231
|
+
Aligns input audio to both the native language transcript a translated one.
|
|
232
|
+
|
|
233
|
+
* `input`: can be an audio file path (`string`), encoded audio (`Buffer` or `Uint8array`) or a raw audio object (`RawAudio`)
|
|
234
|
+
* `transcript`: the transcript to align to, in the native speech language
|
|
235
|
+
* `translatedTranscript`: the translated transcript to align to
|
|
236
|
+
* `options`: transcript and translation alignment options object
|
|
237
|
+
|
|
238
|
+
#### Returns (via promise):
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
{
|
|
242
|
+
timeline: Timeline
|
|
243
|
+
wordTimeline: Timeline
|
|
244
|
+
|
|
245
|
+
translatedTimeline: Timeline
|
|
246
|
+
translatedWordTimeline: Timeline
|
|
247
|
+
|
|
175
248
|
transcript: string
|
|
176
|
-
|
|
249
|
+
translatedTranscript: string
|
|
250
|
+
|
|
251
|
+
sourceLanguage: string
|
|
252
|
+
targetLanguage: string
|
|
253
|
+
|
|
254
|
+
inputRawAudio: RawAudio
|
|
255
|
+
isolatedRawAudio?: RawAudio
|
|
256
|
+
backgroundRawAudio?: RawAudio
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### `alignTimelineTranslation(inputTimeline, translatedTranscript, options)`
|
|
261
|
+
|
|
262
|
+
Aligns given timeline with its translated transcript.
|
|
263
|
+
|
|
264
|
+
* `inputTimeline`: input timeline in the native language
|
|
265
|
+
* `translatedTranscript`: the translated transcript to align to
|
|
266
|
+
* `options`: timeline translation alignment options object
|
|
267
|
+
|
|
268
|
+
#### Returns (via promise):
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
{
|
|
272
|
+
timeline: Timeline
|
|
273
|
+
wordTimeline: Timeline
|
|
274
|
+
|
|
275
|
+
sourceLanguage?: string
|
|
276
|
+
targetLanguage: string
|
|
277
|
+
|
|
278
|
+
rawAudio?: RawAudio
|
|
177
279
|
}
|
|
178
280
|
```
|
|
179
281
|
|
package/docs/CLI.md
CHANGED
|
@@ -106,7 +106,8 @@ echogarden translate-speech speech.mp3 translation.txt --sourceLanguage=es --tar
|
|
|
106
106
|
|
|
107
107
|
## Speech-to-translated-transcript alignment
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
### Direct alignment (English target only)
|
|
110
|
+
**Task**: Given a spoken audio file and its English translated transcript, try to approximate the timing of the start and end of each translated word.
|
|
110
111
|
|
|
111
112
|
This would align the audio file `dutch-speech.mp3` with the translated transcript provided in `english-translation.txt`, and would play the synchronized result in the terminal:
|
|
112
113
|
```bash
|
|
@@ -118,6 +119,55 @@ This would align the audio file `dutch-speech.mp3` with the translated transcrip
|
|
|
118
119
|
echogarden align-translation dutch-speech.mp3 english-translation.txt result.srt result.json
|
|
119
120
|
```
|
|
120
121
|
|
|
122
|
+
### Two-stage alignment (any of 96 source and target languages, combined stages)
|
|
123
|
+
**Task**: Given a spoken audio file, its transcript, and its translated transcript, try to approximate the timing of the start and end of each translated word.
|
|
124
|
+
|
|
125
|
+
This would align the audio file `dutch-speech.mp3` with the Dutch (native language) transcript provided in `dutch-transcript.txt` and the translated transcript provided in `russian-translation.txt`, and would play the synchronized result in the terminal:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
echogarden align-transcript-and-translation dutch-speech.mp3 dutch-transcript.txt russian-translation.txt
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
This would perform the same operation but write the results to disk:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
echogarden align-transcript-and-translation dutch-speech.mp3 dutch-transcript.txt russian-translation.txt out.json out.srt
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
The output would include separate files for the native language and the translation language:
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
out.json
|
|
141
|
+
out.srt
|
|
142
|
+
|
|
143
|
+
out.translated.json
|
|
144
|
+
out.translated.srt
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Two-stage alignment (any of 96 source and target languages, separate stages)
|
|
148
|
+
|
|
149
|
+
**Task**: Given an audio file, its transcript, and its translated transcript, try to approximate the timing of the start and end of each translated word. Do this in two, separate stages.
|
|
150
|
+
|
|
151
|
+
This manual two-step approach allows to reuse the already-aligned transcript in the next stage, possibly for several different translation languages. The method used for alignment is otherwise identical to `align-transcript-and-translation`.
|
|
152
|
+
|
|
153
|
+
**Stage 1**:
|
|
154
|
+
|
|
155
|
+
Align the audio with its native language transcript, to produce a timeline in the native language:
|
|
156
|
+
```bash
|
|
157
|
+
echogarden align dutch-speech.mp3 dutch-transcript.txt dutch-timeline.json
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Stage 2**:
|
|
161
|
+
|
|
162
|
+
Align the resulting timeline with the target translation, and play the synchronized result in the terminal.
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
echogarden align-timeline-translation dutch-timeline.json russian-transcript.txt --audio=dutch-speech.mp3
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
(`--audio` is only used for previewing the result in the terminal. Otherwise, it is not necessary)
|
|
169
|
+
|
|
170
|
+
|
|
121
171
|
## Language detection
|
|
122
172
|
|
|
123
173
|
**Task**: Given audio or textual input, try to identify which language it is spoken or written in.
|
package/docs/Engines.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
**Offline**:
|
|
7
7
|
|
|
8
|
-
* [VITS](https://github.com/jaywalnut310/vits) (`vits`): end-to-end neural speech synthesis architecture. Available models were trained by Michael Hansen as part of his [Piper speech synthesis system](https://github.com/rhasspy/piper). Currently, there are
|
|
8
|
+
* [VITS](https://github.com/jaywalnut310/vits) (`vits`): end-to-end neural speech synthesis architecture. Available models were trained by Michael Hansen as part of his [Piper speech synthesis system](https://github.com/rhasspy/piper). Currently, there are 123 voices, in a range of languages, including English (US, UK), Spanish (ES, MX), Portuguese (PT, BR), Italian, French, German, Dutch (NL, BE), Swedish, Norwegian, Danish, Finnish, Polish, Greek, Romanian, Serbian, Czech, Hungarian, Slovak, Slovenian, Turkish, Arabic, Farsi, Russian, Ukrainian, Catalan, Luxembourgish, Icelandic, Swahili, Kazakh, Georgian, Nepali, Vietnamese and Chinese. You can listen to audio samples of all voices and languages in [Piper's samples page](https://rhasspy.github.io/piper-samples/)
|
|
9
9
|
* [SVOX Pico](https://github.com/naggety/picotts) (`pico`): a legacy diphone-based synthesis engine. Supports English (US, UK), Spanish, Italian, French, and German
|
|
10
10
|
* [Flite](https://github.com/festvox/flite) (`flite`): a legacy diphone-based synthesis engine. Supports English (US, Scottish), and several Indic languages: Hindi, Bengali, Marathi, Telugu, Tamil, Gujarati, Kannada and Punjabi
|
|
11
11
|
* [eSpeak-NG](https://github.com/espeak-ng/espeak-ng/) (`espeak`): a lightweight "robot" sounding formant-based synthesizer. Supports 100+ languages. Used internally for speech alignment, phonemization, and other internal tasks
|
|
@@ -58,7 +58,7 @@ These are commercial services that require a subscription and an API key to use:
|
|
|
58
58
|
* [Google Cloud](https://cloud.google.com/speech-to-text) (`google-cloud`)
|
|
59
59
|
* [Azure Cognitive Services](https://azure.microsoft.com/en-us/products/ai-services/speech-to-text/) (`microsoft-azure`)
|
|
60
60
|
* [Amazon Transcribe](https://aws.amazon.com/transcribe/) (`amazon-transcribe`)
|
|
61
|
-
* [OpenAI Cloud Platform](https://platform.openai.com/) (`openai-cloud`): runs the `large-v2` Whisper model on the cloud
|
|
61
|
+
* [OpenAI Cloud Platform](https://platform.openai.com/) (`openai-cloud`): runs the `large-v2` Whisper model on the cloud. Allows setting a custom provider, like [Groq](https://console.groq.com/docs/api-reference#audio), to request from any OpenAI-compatible provider
|
|
62
62
|
|
|
63
63
|
## Speech-to-transcript alignment
|
|
64
64
|
|
|
@@ -68,7 +68,6 @@ These engines' goal is to match (or "align") a given spoken recording with a giv
|
|
|
68
68
|
* Dynamic Time Warping with Recognition Assist (`dtw-ra`): recognition is applied to the audio (any recognition engine can be used), then both the ground-truth transcript and the recognized transcript are synthesized using eSpeak. Then, the best mapping is found between the two synthesized waveforms, using the DTW algorithm, and the result is remapped back to the original audio using the timing information produced by the recognizer
|
|
69
69
|
* Whisper-based alignment (`whisper`): transcript is first tokenized, then, its tokens are decoded, in order, with a guided approach, using the Whisper model. The resulting token timestamps are then used to derive the timing for each word
|
|
70
70
|
|
|
71
|
-
|
|
72
71
|
## Speech-to-text translation
|
|
73
72
|
|
|
74
73
|
**Offline**:
|
|
@@ -78,12 +77,42 @@ These engines' goal is to match (or "align") a given spoken recording with a giv
|
|
|
78
77
|
**Cloud services**:
|
|
79
78
|
* [OpenAI Cloud Platform](https://platform.openai.com/) (`openai-cloud`): runs the `large-v2` Whisper model on the cloud. Only supports English as target
|
|
80
79
|
|
|
80
|
+
## Text-to-text translation
|
|
81
|
+
|
|
82
|
+
**Cloud services (unofficial)**:
|
|
83
|
+
|
|
84
|
+
* Google Translate (`google-translate`): uses the [Google Translate mobile web UI](https://translate.google.com/m) to translate text from and to any one of its supported languages.
|
|
85
|
+
|
|
81
86
|
## Speech-to-translated-transcript alignment
|
|
82
87
|
|
|
83
88
|
The goal here is to match (or "align") a given spoken recording in one language, with a given translated transcript in a different language, as closely as possible.
|
|
84
89
|
|
|
85
90
|
* `whisper`: given a spoken recording in any of the [98 languages](https://platform.openai.com/docs/guides/speech-to-text/supported-languages) supported by Whisper, and an English translation of its transcript, the translated transcript is tokenized and then decoded, in order, using a guided approach, with any multilingual Whisper model, set to its `translate` task mode. In this way, the approximate mapping between the spoken audio and each word of the translation is estimated
|
|
86
91
|
|
|
92
|
+
## Speech-to-transcript-and-translation alignment
|
|
93
|
+
|
|
94
|
+
This is a two-stage approach for translation alignment, that can accept about 100 source and target languages:
|
|
95
|
+
|
|
96
|
+
1. First, the spoken audio is aligned with the native language transcript
|
|
97
|
+
2. Then, the resulting timeline is aligned with the translated text using semantic text-to-text alignment
|
|
98
|
+
|
|
99
|
+
This approach is potentially faster than the single-stage one, because the first stage can use any alignment approach, including the default synthesis-based `dtw` engine, which is much faster than running a full speech recognition engine like Whisper.
|
|
100
|
+
|
|
101
|
+
The second stage uses a multilingual text embedding model (currently defaults to [multilingual E5](https://huggingface.co/intfloat/multilingual-e5-base)) to produce a vector representation of both the transcript and the translated text tokens. Then, it applies DTW over the two vector sequences to align the tokens of the two languages. Since this stage works on tokens only (the audio is not involved), it is generally fast.
|
|
102
|
+
|
|
103
|
+
In terms of accuracy, the two-stage approach can be more accurate than the alignment derived from the Whisper model in the one-stage approach, especially when compared to using the smaller Whisper models like `tiny` or `base`, and for source languages that Whisper generally isn't very good at, like Chinese, Japanese, and less common languages.
|
|
104
|
+
|
|
105
|
+
For a non-English target language, this approach is currently the only one that can be used.
|
|
106
|
+
|
|
107
|
+
## Timeline-to-translation alignment
|
|
108
|
+
|
|
109
|
+
Aligns a timeline with a translation of its text. Does not involve the spoken audio itself.
|
|
110
|
+
|
|
111
|
+
This is used for the second stage of the two-stage approach described above. It can also be used independently. It allows to reuse the same timeline to align with multiple translations, in different languages, without needing to redo the native-language alignment each time.
|
|
112
|
+
|
|
113
|
+
Another use case it to take a timeline produced as part of synthesized or recognized speech and then align it with one or more translations of its text.
|
|
114
|
+
|
|
115
|
+
* [`E5`](https://huggingface.co/intfloat/multilingual-e5-base) (`e5`): E5 is a multilingual text embedding model by Microsoft, supporting 100 languages. This model encodes sequences of text tokens to vectors, in such a way that words with similar meanings in different languages are mapped to similar vectors. This cross-language semantic vector encoding is then used for aligning the tokens between the timeline and the translation. Then, the translated words are mapped to the timestamps of the corresponding words in the timeline.
|
|
87
116
|
|
|
88
117
|
## Language detection
|
|
89
118
|
|