26 lines
1.3 KiB
JavaScript
26 lines
1.3 KiB
JavaScript
import { pipeline, env } from '@huggingface/transformers';
|
|||
|
|
import { createRequire } from 'module';
|
||
|
|
import os from 'os'; import path from 'path';
|
||
|
|
const require = createRequire(import.meta.url);
|
||
|
|
const Guard = require('./mt-guard.js');
|
||
|
|
const B = require('./bible-lexicon.js');
|
||
|
|
env.allowLocalModels = false;
|
||
|
|
env.cacheDir = path.join(os.homedir(), 'Library/Application Support/Church Translate Models');
|
||
|
|
const pipe = await pipeline('translation', 'Xenova/nllb-200-distilled-600M', { dtype: 'fp32' });
|
||
|
|
const say = async (t, l) => {
|
||
|
|
const o = await pipe(t, { src_lang: 'eng_Latn', tgt_lang: l });
|
||
|
|
return (Array.isArray(o) ? o[0] : o).translation_text.trim();
|
||
|
|
};
|
||
|
|
const lex = B.forLanguage('spa_Latn');
|
||
|
|
const BARE = ['Peter.','John.','Matthew.','Noah.','Paul.','Moses.','David.','Abraham.','Jesus.','Mary.','Habakkuk.','Genesis.','Romans.','Peter','John'];
|
||
|
|
console.log('a BARE NAME as the whole utterance:\n');
|
||
|
|
for (const t of BARE) {
|
||
|
|
const raw = await say(t, 'spa_Latn');
|
||
|
|
const g = Guard.clean(t, raw);
|
||
|
|
const bare = t.replace(/\.$/, '');
|
||
|
|
const want = lex[bare] || bare;
|
||
|
|
const kept = g.text.toLowerCase().indexOf(want.toLowerCase()) !== -1 ||
|
||
|
|
g.text.toLowerCase().indexOf(bare.toLowerCase()) !== -1;
|
||
|
|
console.log(' ' + t.padEnd(12) + 'NLLB: ' + raw.padEnd(32) + 'after guard: ' + g.text.padEnd(26) + (kept ? '' : '<-- NAME LOST'));
|
||
|
|
}
|