echogarden 1.3.0 → 1.3.2
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/dist/alignment/TextAlignment.d.ts +16 -0
- package/dist/alignment/TextAlignment.js +63 -0
- package/dist/alignment/TextAlignment.js.map +1 -0
- package/dist/api/Alignment.js +6 -1
- package/dist/api/Alignment.js.map +1 -1
- package/dist/api/Denoising.js +0 -1
- package/dist/api/Denoising.js.map +1 -1
- package/dist/api/LanguageDetection.js +2 -2
- package/dist/api/LanguageDetection.js.map +1 -1
- package/dist/api/Recognition.js +3 -1
- package/dist/api/Recognition.js.map +1 -1
- package/dist/api/Synthesis.js +1 -1
- package/dist/api/Synthesis.js.map +1 -1
- package/dist/api/Translation.js +3 -1
- package/dist/api/Translation.js.map +1 -1
- package/dist/api/TranslationAlignment.js +4 -1
- package/dist/api/TranslationAlignment.js.map +1 -1
- package/dist/api/VoiceActivityDetection.js +5 -2
- package/dist/api/VoiceActivityDetection.js.map +1 -1
- package/dist/audio/AudioUtilities.d.ts +1 -1
- package/dist/audio/AudioUtilities.js +2 -2
- package/dist/audio/AudioUtilities.js.map +1 -1
- package/dist/cli/CLILauncher.js +1 -2
- package/dist/cli/CLILauncher.js.map +1 -1
- package/dist/codecs/FFMpegTranscoder.js +4 -1
- package/dist/codecs/FFMpegTranscoder.js.map +1 -1
- package/dist/codecs/WaveCodec.d.ts +1 -1
- package/dist/codecs/WaveCodec.js +13 -5
- package/dist/codecs/WaveCodec.js.map +1 -1
- package/dist/dsp/SpeexResampler.js +49 -21
- package/dist/dsp/SpeexResampler.js.map +1 -1
- package/dist/synthesis/CoquiServerTTS.js +1 -1
- package/dist/synthesis/CoquiServerTTS.js.map +1 -1
- package/dist/synthesis/VitsTTS.js +1 -1
- package/dist/synthesis/VitsTTS.js.map +1 -1
- package/dist/text-translation/NLLBTextTranslation.d.ts +1 -0
- package/dist/text-translation/NLLBTextTranslation.js +237 -0
- package/dist/text-translation/NLLBTextTranslation.js.map +1 -0
- package/dist/utilities/BinaryArrayConversion.d.ts +18 -8
- package/dist/utilities/BinaryArrayConversion.js +63 -36
- package/dist/utilities/BinaryArrayConversion.js.map +1 -1
- package/dist/utilities/PackageManager.js +2 -0
- package/dist/utilities/PackageManager.js.map +1 -1
- package/docs/Development.md +1 -1
- package/docs/Server.md +1 -1
- package/docs/Tasklist.md +1 -1
- package/package.json +11 -10
- package/src/alignment/TextAlignment.ts +96 -0
- package/src/api/Alignment.ts +10 -1
- package/src/api/Denoising.ts +0 -2
- package/src/api/LanguageDetection.ts +2 -3
- package/src/api/Recognition.ts +3 -1
- package/src/api/Synthesis.ts +1 -1
- package/src/api/Translation.ts +3 -1
- package/src/api/TranslationAlignment.ts +5 -1
- package/src/api/VoiceActivityDetection.ts +7 -4
- package/src/audio/AudioUtilities.ts +2 -2
- package/src/cli/CLILauncher.ts +1 -2
- package/src/codecs/FFMpegTranscoder.ts +5 -1
- package/src/codecs/WaveCodec.ts +15 -5
- package/src/dsp/SpeexResampler.ts +62 -23
- package/src/synthesis/CoquiServerTTS.ts +1 -1
- package/src/synthesis/VitsTTS.ts +2 -2
- package/src/text-translation/NLLBTextTranslation.ts +252 -0
- package/src/utilities/BinaryArrayConversion.ts +73 -41
- package/src/utilities/PackageManager.ts +3 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Logger } from '../utilities/Logger.js'
|
|
2
|
+
import { loadPackage } from '../utilities/PackageManager.js'
|
|
3
|
+
|
|
4
|
+
export async function translateText(sourceText: string, sourceLanguage: string, targetLanguage: string) {
|
|
5
|
+
const logger = new Logger()
|
|
6
|
+
|
|
7
|
+
const { AutoTokenizer, M2M100ForConditionalGeneration } = await import('@echogarden/transformers-nodejs-lite')
|
|
8
|
+
|
|
9
|
+
const modelPath = await loadPackage(`xenova-nllb-200-distilled-600M-quantized`)
|
|
10
|
+
|
|
11
|
+
const tokenizer = await AutoTokenizer.from_pretrained(modelPath)
|
|
12
|
+
const model = await M2M100ForConditionalGeneration.from_pretrained(modelPath)
|
|
13
|
+
|
|
14
|
+
const config = {
|
|
15
|
+
src_lang: 'eng_Latn',
|
|
16
|
+
tgt_lang: 'fra_Latn'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const inputs = (tokenizer as any)._build_translation_inputs(sourceText, {
|
|
20
|
+
padding: true,
|
|
21
|
+
truncation: true,
|
|
22
|
+
}, config)
|
|
23
|
+
|
|
24
|
+
const result = await model.generate(inputs.input_ids, config)
|
|
25
|
+
|
|
26
|
+
logger.log(tokenizer.model.convert_ids_to_tokens(result[0]))
|
|
27
|
+
|
|
28
|
+
const inputTokens = tokenizer.model.convert_ids_to_tokens(Array.from(inputs.input_ids.data))
|
|
29
|
+
const embeddingResult = await model(inputs)
|
|
30
|
+
|
|
31
|
+
const lastHiddenState = embeddingResult.last_hidden_state
|
|
32
|
+
|
|
33
|
+
const tokenCount = lastHiddenState.dims[1]
|
|
34
|
+
const embeddingSize = lastHiddenState.dims[2]
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < tokenCount; i++) {
|
|
37
|
+
const tokenEmbedding = lastHiddenState.data.slice(i * embeddingSize, (i + 1) * embeddingSize)
|
|
38
|
+
|
|
39
|
+
const tokenId = inputTokens[i]
|
|
40
|
+
|
|
41
|
+
logger.log(`Token ${i} (${tokenId}):`, tokenEmbedding);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
logger.log(inputTokens)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const languageNameToNLLBCode: Record<string, string> = {
|
|
48
|
+
'Acehnese (Arabic script)': 'ace_Arab',
|
|
49
|
+
'Acehnese (Latin script)': 'ace_Latn',
|
|
50
|
+
'Afrikaans': 'afr_Latn',
|
|
51
|
+
'Akan': 'aka_Latn',
|
|
52
|
+
'Amharic': 'amh_Ethi',
|
|
53
|
+
'Armenian': 'hye_Armn',
|
|
54
|
+
'Assamese': 'asm_Beng',
|
|
55
|
+
'Asturian': 'ast_Latn',
|
|
56
|
+
'Awadhi': 'awa_Deva',
|
|
57
|
+
'Ayacucho Quechua': 'quy_Latn',
|
|
58
|
+
'Balinese': 'ban_Latn',
|
|
59
|
+
'Bambara': 'bam_Latn',
|
|
60
|
+
'Banjar (Arabic script)': 'bjn_Arab',
|
|
61
|
+
'Banjar (Latin script)': 'bjn_Latn',
|
|
62
|
+
'Bashkir': 'bak_Cyrl',
|
|
63
|
+
'Basque': 'eus_Latn',
|
|
64
|
+
'Belarusian': 'bel_Cyrl',
|
|
65
|
+
'Bemba': 'bem_Latn',
|
|
66
|
+
'Bengali': 'ben_Beng',
|
|
67
|
+
'Bhojpuri': 'bho_Deva',
|
|
68
|
+
'Bosnian': 'bos_Latn',
|
|
69
|
+
'Buginese': 'bug_Latn',
|
|
70
|
+
'Bulgarian': 'bul_Cyrl',
|
|
71
|
+
'Burmese': 'mya_Mymr',
|
|
72
|
+
'Catalan': 'cat_Latn',
|
|
73
|
+
'Cebuano': 'ceb_Latn',
|
|
74
|
+
'Central Atlas Tamazight': 'tzm_Tfng',
|
|
75
|
+
'Central Aymara': 'ayr_Latn',
|
|
76
|
+
'Central Kanuri (Arabic script)': 'knc_Arab',
|
|
77
|
+
'Central Kanuri (Latin script)': 'knc_Latn',
|
|
78
|
+
'Central Kurdish': 'ckb_Arab',
|
|
79
|
+
'Chhattisgarhi': 'hne_Deva',
|
|
80
|
+
'Chinese (Simplified)': 'zho_Hans',
|
|
81
|
+
'Chinese (Traditional)': 'zho_Hant',
|
|
82
|
+
'Chokwe': 'cjk_Latn',
|
|
83
|
+
'Crimean Tatar': 'crh_Latn',
|
|
84
|
+
'Croatian': 'hrv_Latn',
|
|
85
|
+
'Czech': 'ces_Latn',
|
|
86
|
+
'Danish': 'dan_Latn',
|
|
87
|
+
'Dari': 'prs_Arab',
|
|
88
|
+
'Dutch': 'nld_Latn',
|
|
89
|
+
'Dyula': 'dyu_Latn',
|
|
90
|
+
'Dzongkha': 'dzo_Tibt',
|
|
91
|
+
'Eastern Panjabi': 'pan_Guru',
|
|
92
|
+
'Eastern Yiddish': 'ydd_Hebr',
|
|
93
|
+
'Egyptian Arabic': 'arz_Arab',
|
|
94
|
+
'English': 'eng_Latn',
|
|
95
|
+
'Esperanto': 'epo_Latn',
|
|
96
|
+
'Estonian': 'est_Latn',
|
|
97
|
+
'Ewe': 'ewe_Latn',
|
|
98
|
+
'Faroese': 'fao_Latn',
|
|
99
|
+
'Fijian': 'fij_Latn',
|
|
100
|
+
'Finnish': 'fin_Latn',
|
|
101
|
+
'Fon': 'fon_Latn',
|
|
102
|
+
'French': 'fra_Latn',
|
|
103
|
+
'Friulian': 'fur_Latn',
|
|
104
|
+
'Galician': 'glg_Latn',
|
|
105
|
+
'Ganda': 'lug_Latn',
|
|
106
|
+
'Georgian': 'kat_Geor',
|
|
107
|
+
'German': 'deu_Latn',
|
|
108
|
+
'Greek': 'ell_Grek',
|
|
109
|
+
'Guarani': 'grn_Latn',
|
|
110
|
+
'Gujarati': 'guj_Gujr',
|
|
111
|
+
'Haitian Creole': 'hat_Latn',
|
|
112
|
+
'Halh Mongolian': 'khk_Cyrl',
|
|
113
|
+
'Hausa': 'hau_Latn',
|
|
114
|
+
'Hebrew': 'heb_Hebr',
|
|
115
|
+
'Hindi': 'hin_Deva',
|
|
116
|
+
'Hungarian': 'hun_Latn',
|
|
117
|
+
'Icelandic': 'isl_Latn',
|
|
118
|
+
'Igbo': 'ibo_Latn',
|
|
119
|
+
'Ilocano': 'ilo_Latn',
|
|
120
|
+
'Indonesian': 'ind_Latn',
|
|
121
|
+
'Irish': 'gle_Latn',
|
|
122
|
+
'Italian': 'ita_Latn',
|
|
123
|
+
'Japanese': 'jpn_Jpan',
|
|
124
|
+
'Javanese': 'jav_Latn',
|
|
125
|
+
'Jingpho': 'kac_Latn',
|
|
126
|
+
'Kabiyè': 'kbp_Latn',
|
|
127
|
+
'Kabuverdianu': 'kea_Latn',
|
|
128
|
+
'Kabyle': 'kab_Latn',
|
|
129
|
+
'Kamba': 'kam_Latn',
|
|
130
|
+
'Kannada': 'kan_Knda',
|
|
131
|
+
'Kashmiri (Arabic script)': 'kas_Arab',
|
|
132
|
+
'Kashmiri (Devanagari script)': 'kas_Deva',
|
|
133
|
+
'Kazakh': 'kaz_Cyrl',
|
|
134
|
+
'Khmer': 'khm_Khmr',
|
|
135
|
+
'Kikongo': 'kon_Latn',
|
|
136
|
+
'Kikuyu': 'kik_Latn',
|
|
137
|
+
'Kimbundu': 'kmb_Latn',
|
|
138
|
+
'Kinyarwanda': 'kin_Latn',
|
|
139
|
+
'Korean': 'kor_Hang',
|
|
140
|
+
'Kyrgyz': 'kir_Cyrl',
|
|
141
|
+
'Lao': 'lao_Laoo',
|
|
142
|
+
'Latgalian': 'ltg_Latn',
|
|
143
|
+
'Ligurian': 'lij_Latn',
|
|
144
|
+
'Limburgish': 'lim_Latn',
|
|
145
|
+
'Lingala': 'lin_Latn',
|
|
146
|
+
'Lithuanian': 'lit_Latn',
|
|
147
|
+
'Lombard': 'lmo_Latn',
|
|
148
|
+
'Luba-Kasai': 'lua_Latn',
|
|
149
|
+
'Luo': 'luo_Latn',
|
|
150
|
+
'Luxembourgish': 'ltz_Latn',
|
|
151
|
+
'Macedonian': 'mkd_Cyrl',
|
|
152
|
+
'Magahi': 'mag_Deva',
|
|
153
|
+
'Maithili': 'mai_Deva',
|
|
154
|
+
'Malayalam': 'mal_Mlym',
|
|
155
|
+
'Maltese': 'mlt_Latn',
|
|
156
|
+
'Maori': 'mri_Latn',
|
|
157
|
+
'Marathi': 'mar_Deva',
|
|
158
|
+
'Meitei (Bengali script)': 'mni_Beng',
|
|
159
|
+
'Mesopotamian Arabic': 'acm_Arab',
|
|
160
|
+
'Minangkabau (Arabic script)': 'min_Arab',
|
|
161
|
+
'Minangkabau (Latin script)': 'min_Latn',
|
|
162
|
+
'Mizo': 'lus_Latn',
|
|
163
|
+
'Modern Standard Arabic (Romanized)': 'arb_Latn',
|
|
164
|
+
'Modern Standard Arabic': 'arb_Arab',
|
|
165
|
+
'Moroccan Arabic': 'ary_Arab',
|
|
166
|
+
'Mossi': 'mos_Latn',
|
|
167
|
+
'Najdi Arabic': 'ars_Arab',
|
|
168
|
+
'Nepali': 'npi_Deva',
|
|
169
|
+
'Nigerian Fulfulde': 'fuv_Latn',
|
|
170
|
+
'North Azerbaijani': 'azj_Latn',
|
|
171
|
+
'North Levantine Arabic': 'apc_Arab',
|
|
172
|
+
'Northern Kurdish': 'kmr_Latn',
|
|
173
|
+
'Northern Sotho': 'nso_Latn',
|
|
174
|
+
'Northern Uzbek': 'uzn_Latn',
|
|
175
|
+
'Norwegian Bokmål': 'nob_Latn',
|
|
176
|
+
'Norwegian Nynorsk': 'nno_Latn',
|
|
177
|
+
'Nuer': 'nus_Latn',
|
|
178
|
+
'Nyanja': 'nya_Latn',
|
|
179
|
+
'Occitan': 'oci_Latn',
|
|
180
|
+
'Odia': 'ory_Orya',
|
|
181
|
+
'Pangasinan': 'pag_Latn',
|
|
182
|
+
'Papiamento': 'pap_Latn',
|
|
183
|
+
'Plateau Malagasy': 'plt_Latn',
|
|
184
|
+
'Polish': 'pol_Latn',
|
|
185
|
+
'Portuguese': 'por_Latn',
|
|
186
|
+
'Romanian': 'ron_Latn',
|
|
187
|
+
'Rundi': 'run_Latn',
|
|
188
|
+
'Russian': 'rus_Cyrl',
|
|
189
|
+
'Samoan': 'smo_Latn',
|
|
190
|
+
'Sango': 'sag_Latn',
|
|
191
|
+
'Sanskrit': 'san_Deva',
|
|
192
|
+
'Santali': 'sat_Olck',
|
|
193
|
+
'Sardinian': 'srd_Latn',
|
|
194
|
+
'Scottish Gaelic': 'gla_Latn',
|
|
195
|
+
'Serbian': 'srp_Cyrl',
|
|
196
|
+
'Shan': 'shn_Mymr',
|
|
197
|
+
'Shona': 'sna_Latn',
|
|
198
|
+
'Sicilian': 'scn_Latn',
|
|
199
|
+
'Silesian': 'szl_Latn',
|
|
200
|
+
'Sindhi': 'snd_Arab',
|
|
201
|
+
'Sinhala': 'sin_Sinh',
|
|
202
|
+
'Slovak': 'slk_Latn',
|
|
203
|
+
'Slovenian': 'slv_Latn',
|
|
204
|
+
'Somali': 'som_Latn',
|
|
205
|
+
'South Azerbaijani': 'azb_Arab',
|
|
206
|
+
'South Levantine Arabic': 'ajp_Arab',
|
|
207
|
+
'Southern Pashto': 'pbt_Arab',
|
|
208
|
+
'Southern Sotho': 'sot_Latn',
|
|
209
|
+
'Southwestern Dinka': 'dik_Latn',
|
|
210
|
+
'Spanish': 'spa_Latn',
|
|
211
|
+
'Standard Latvian': 'lvs_Latn',
|
|
212
|
+
'Standard Malay': 'zsm_Latn',
|
|
213
|
+
'Standard Tibetan': 'bod_Tibt',
|
|
214
|
+
'Sundanese': 'sun_Latn',
|
|
215
|
+
'Swahili': 'swh_Latn',
|
|
216
|
+
'Swati': 'ssw_Latn',
|
|
217
|
+
'Swedish': 'swe_Latn',
|
|
218
|
+
'Tagalog': 'tgl_Latn',
|
|
219
|
+
'Tajik': 'tgk_Cyrl',
|
|
220
|
+
'Tamasheq (Latin script)': 'taq_Latn',
|
|
221
|
+
'Tamasheq (Tifinagh script)': 'taq_Tfng',
|
|
222
|
+
'Tamil': 'tam_Taml',
|
|
223
|
+
'Tatar': 'tat_Cyrl',
|
|
224
|
+
'Ta’izzi-Adeni Arabic': 'acq_Arab',
|
|
225
|
+
'Telugu': 'tel_Telu',
|
|
226
|
+
'Thai': 'tha_Thai',
|
|
227
|
+
'Tigrinya': 'tir_Ethi',
|
|
228
|
+
'Tok Pisin': 'tpi_Latn',
|
|
229
|
+
'Tosk Albanian': 'als_Latn',
|
|
230
|
+
'Tsonga': 'tso_Latn',
|
|
231
|
+
'Tswana': 'tsn_Latn',
|
|
232
|
+
'Tumbuka': 'tum_Latn',
|
|
233
|
+
'Tunisian Arabic': 'aeb_Arab',
|
|
234
|
+
'Turkish': 'tur_Latn',
|
|
235
|
+
'Turkmen': 'tuk_Latn',
|
|
236
|
+
'Twi': 'twi_Latn',
|
|
237
|
+
'Ukrainian': 'ukr_Cyrl',
|
|
238
|
+
'Umbundu': 'umb_Latn',
|
|
239
|
+
'Urdu': 'urd_Arab',
|
|
240
|
+
'Uyghur': 'uig_Arab',
|
|
241
|
+
'Venetian': 'vec_Latn',
|
|
242
|
+
'Vietnamese': 'vie_Latn',
|
|
243
|
+
'Waray': 'war_Latn',
|
|
244
|
+
'Welsh': 'cym_Latn',
|
|
245
|
+
'West Central Oromo': 'gaz_Latn',
|
|
246
|
+
'Western Persian': 'pes_Arab',
|
|
247
|
+
'Wolof': 'wol_Latn',
|
|
248
|
+
'Xhosa': 'xho_Latn',
|
|
249
|
+
'Yoruba': 'yor_Latn',
|
|
250
|
+
'Yue Chinese': 'yue_Hant',
|
|
251
|
+
'Zulu': 'zul_Latn',
|
|
252
|
+
}
|
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
// Typed arrays to Buffer (little endian) conversions
|
|
2
|
+
//
|
|
3
|
+
// The faster conversion methods (other than the methods for int8) 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.
|
|
2
7
|
|
|
3
8
|
// int8 <-> bufferLE
|
|
4
|
-
export function int8ToBuffer(
|
|
5
|
-
|
|
9
|
+
export function int8ToBuffer(int8s: Int8Array) {
|
|
10
|
+
return Buffer.copyBytesFrom(int8s)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function int8ToBuffer_Slow(int8s: Int8Array) {
|
|
14
|
+
const buffer = Buffer.alloc(int8s.length)
|
|
6
15
|
|
|
7
|
-
for (let i = 0; i <
|
|
8
|
-
buffer[i] =
|
|
16
|
+
for (let i = 0; i < int8s.length; i++) {
|
|
17
|
+
buffer[i] = int8s[i] + 128
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
return buffer
|
|
12
21
|
}
|
|
13
22
|
|
|
14
23
|
export function bufferToInt8(buffer: Buffer) {
|
|
24
|
+
return new Int8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function bufferToInt8_Slow(buffer: Buffer) {
|
|
15
28
|
const result = new Int8Array(buffer.length)
|
|
16
29
|
|
|
17
30
|
for (let i = 0; i < result.length; i++) {
|
|
@@ -22,17 +35,25 @@ export function bufferToInt8(buffer: Buffer) {
|
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
// int16 <-> bufferLE
|
|
25
|
-
export function int16ToBufferLE(
|
|
26
|
-
|
|
38
|
+
export function int16ToBufferLE(int16s: Int16Array) {
|
|
39
|
+
return Buffer.copyBytesFrom(int16s)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function int16ToBufferLE_Slow(int16s: Int16Array) {
|
|
43
|
+
const buffer = Buffer.alloc(int16s.length * 2)
|
|
27
44
|
|
|
28
|
-
for (let i = 0; i <
|
|
29
|
-
buffer.writeInt16LE(
|
|
45
|
+
for (let i = 0; i < int16s.length; i++) {
|
|
46
|
+
buffer.writeInt16LE(int16s[i], i * 2)
|
|
30
47
|
}
|
|
31
48
|
|
|
32
49
|
return buffer
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
export function bufferLEToInt16(buffer: Buffer) {
|
|
53
|
+
return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function bufferLEToInt16_Slow(buffer: Buffer) {
|
|
36
57
|
const result = new Int16Array(buffer.length / 2)
|
|
37
58
|
|
|
38
59
|
for (let i = 0; i < result.length; i++) {
|
|
@@ -43,11 +64,11 @@ export function bufferLEToInt16(buffer: Buffer) {
|
|
|
43
64
|
}
|
|
44
65
|
|
|
45
66
|
// int24 <-> bufferLE (uses int32 for storage)
|
|
46
|
-
export function int24ToBufferLE(
|
|
47
|
-
const buffer = Buffer.alloc(
|
|
67
|
+
export function int24ToBufferLE(int24s: Int32Array) {
|
|
68
|
+
const buffer = Buffer.alloc(int24s.length * 3)
|
|
48
69
|
|
|
49
|
-
for (let i = 0; i <
|
|
50
|
-
const val =
|
|
70
|
+
for (let i = 0; i < int24s.length; i++) {
|
|
71
|
+
const val = int24s[i]
|
|
51
72
|
const encodedVal = val < 0 ? val + 0x1000000 : val
|
|
52
73
|
|
|
53
74
|
buffer[(i * 3) + 0] = (encodedVal >> 0) & 0xff
|
|
@@ -74,17 +95,25 @@ export function bufferLEToInt24(buffer: Buffer) {
|
|
|
74
95
|
}
|
|
75
96
|
|
|
76
97
|
// int32 <-> bufferLE
|
|
77
|
-
export function int32ToBufferLE(
|
|
78
|
-
|
|
98
|
+
export function int32ToBufferLE(int32s: Int32Array) {
|
|
99
|
+
return Buffer.copyBytesFrom(int32s)
|
|
100
|
+
}
|
|
79
101
|
|
|
80
|
-
|
|
81
|
-
|
|
102
|
+
export function int32ToBufferLE_Slow(int32s: Int32Array) {
|
|
103
|
+
const buffer = Buffer.alloc(int32s.length * 4)
|
|
104
|
+
|
|
105
|
+
for (let i = 0; i < int32s.length; i++) {
|
|
106
|
+
buffer.writeInt32LE(int32s[i], i * 4)
|
|
82
107
|
}
|
|
83
108
|
|
|
84
109
|
return buffer
|
|
85
110
|
}
|
|
86
111
|
|
|
87
112
|
export function bufferLEToInt32(buffer: Buffer) {
|
|
113
|
+
return new Int32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function bufferLEToInt32_Slow(buffer: Buffer) {
|
|
88
117
|
const result = new Int32Array(buffer.length / 4)
|
|
89
118
|
|
|
90
119
|
for (let i = 0; i < result.length; i++) {
|
|
@@ -95,17 +124,25 @@ export function bufferLEToInt32(buffer: Buffer) {
|
|
|
95
124
|
}
|
|
96
125
|
|
|
97
126
|
// float32 <-> bufferLE
|
|
98
|
-
export function float32ToBufferLE(
|
|
99
|
-
|
|
127
|
+
export function float32ToBufferLE(float32s: Float32Array) {
|
|
128
|
+
return Buffer.copyBytesFrom(float32s)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function float32ToBufferLE_Slow(float32s: Float32Array) {
|
|
132
|
+
const buffer = Buffer.alloc(float32s.length * 4)
|
|
100
133
|
|
|
101
|
-
for (let i = 0; i <
|
|
102
|
-
buffer.writeFloatLE(
|
|
134
|
+
for (let i = 0; i < float32s.length; i++) {
|
|
135
|
+
buffer.writeFloatLE(float32s[i], i * 4)
|
|
103
136
|
}
|
|
104
137
|
|
|
105
138
|
return buffer
|
|
106
139
|
}
|
|
107
140
|
|
|
108
141
|
export function bufferLEToFloat32(buffer: Buffer) {
|
|
142
|
+
return new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function bufferLEToFloat32_Slow(buffer: Buffer) {
|
|
109
146
|
const result = new Float32Array(buffer.length / 4)
|
|
110
147
|
|
|
111
148
|
for (let i = 0; i < result.length; i++) {
|
|
@@ -116,17 +153,25 @@ export function bufferLEToFloat32(buffer: Buffer) {
|
|
|
116
153
|
}
|
|
117
154
|
|
|
118
155
|
// float64 <-> bufferLE
|
|
119
|
-
export function float64ToBufferLE(
|
|
120
|
-
|
|
156
|
+
export function float64ToBufferLE(float64s: Float64Array) {
|
|
157
|
+
return Buffer.copyBytesFrom(float64s)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function float64ToBufferLE_Slow(float64s: Float64Array) {
|
|
161
|
+
const buffer = Buffer.alloc(float64s.length * 8)
|
|
121
162
|
|
|
122
|
-
for (let i = 0; i <
|
|
123
|
-
buffer.writeDoubleLE(
|
|
163
|
+
for (let i = 0; i < float64s.length; i++) {
|
|
164
|
+
buffer.writeDoubleLE(float64s[i], i * 8)
|
|
124
165
|
}
|
|
125
166
|
|
|
126
167
|
return buffer
|
|
127
168
|
}
|
|
128
169
|
|
|
129
170
|
export function bufferLEToFloat64(buffer: Buffer) {
|
|
171
|
+
return new Float64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function bufferLEToFloat64_Slow(buffer: Buffer) {
|
|
130
175
|
const result = new Float64Array(buffer.length / 8)
|
|
131
176
|
|
|
132
177
|
for (let i = 0; i < result.length; i++) {
|
|
@@ -137,23 +182,10 @@ export function bufferLEToFloat64(buffer: Buffer) {
|
|
|
137
182
|
}
|
|
138
183
|
|
|
139
184
|
// float64 <-> float32
|
|
140
|
-
export function float64Tofloat32(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
for (let i = 0; i < doubles.length; i++) {
|
|
144
|
-
floats[i] = doubles[i]
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return floats
|
|
185
|
+
export function float64Tofloat32(float64s: Float64Array) {
|
|
186
|
+
return Float32Array.from(float64s)
|
|
148
187
|
}
|
|
149
188
|
|
|
150
|
-
export function float32Tofloat64(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
for (let i = 0; i < floats.length; i++) {
|
|
154
|
-
doubles[i] = floats[i]
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return doubles
|
|
189
|
+
export function float32Tofloat64(float32s: Float32Array) {
|
|
190
|
+
return Float64Array.from(float32s)
|
|
158
191
|
}
|
|
159
|
-
|
|
@@ -182,4 +182,7 @@ const packageVersionTagResolutionLookup: { [packageName: string]: string } = {
|
|
|
182
182
|
|
|
183
183
|
'whisper.cpp-binaries-windows-x64-cublas-12.4.0-latest-patched': '20240409',
|
|
184
184
|
'whisper.cpp-binaries-windows-x64-cublas-11.8.0-latest-patched': '20240409',
|
|
185
|
+
|
|
186
|
+
'xenova-multilingual-e5-small-quantized': '20240504',
|
|
187
|
+
'xenova-nllb-200-distilled-600M-quantized': '20240505',
|
|
185
188
|
}
|