UNPKG

node-diarization

Version:

Transcription and diarization using Whisper and Pyannote with NodeJS

117 lines (116 loc) 5.16 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkPythonScripts = exports.checkTask = exports.checkFileAndConvertPathToAbsolute = void 0; const path_1 = __importDefault(require("path")); const fs_1 = require("fs"); const constants_1 = require("./constants"); const shell_1 = __importStar(require("./shell")); const checkFileAndConvertPathToAbsolute = (filePath, errorText) => { if (!filePath) { throw `No file path provided`; } filePath = path_1.default.resolve(filePath); // check is file existed if (!(0, fs_1.existsSync)(filePath)) { throw errorText; } return filePath; }; exports.checkFileAndConvertPathToAbsolute = checkFileAndConvertPathToAbsolute; const checkTask = (options) => { if (options?.tasks && !options?.tasks.some((ct) => constants_1.TASKS.some((t) => ct === t))) { throw "No correct task provided"; } if (!options?.tasks || options?.tasks.some(t => t === 'recognition')) { if (!options?.recognition?.model) { throw "No model name or path provided"; } // check if not model from hf repo if (!options?.recognition?.hfRepoModel) { // check is standard whisper model if (!constants_1.WHISPER_MODELS.some(wm => wm === options.recognition?.model)) { // check is path to model, // throw if no path to model.bin options.recognition.model = (0, exports.checkFileAndConvertPathToAbsolute)(options.recognition.model, `No original whisper model name provided, and model.bin file not existed in provided path.\n` + `Available standard whisper models is: ${constants_1.WHISPER_MODELS.join(', ')}.`); } } } if (!options?.tasks || options?.tasks.some(t => t === 'diarization')) { if (!options?.diarization?.pyannote_auth_token) { throw 'No pyannote auth token provided'; } } return options; }; exports.checkTask = checkTask; const checkPythonScripts = async (options) => { if (options.consoleTextInfo) { console.log('********** Python prerequisites check start **********'); } let text = ''; const checkPythonVar = await (0, shell_1.default)(`${options.python?.var} --version`, options); if (checkPythonVar.code !== 0) { throw 'Python is not detected. Try use in python options another var - python, python3, etc., ' + 'or check your system settings'; } if (!checkPythonVar.data) { throw 'Response from getting python version is not provided'; } const pyVersion = checkPythonVar.data.match(/.*(\d+\.\d+\.\d+.*)/); if (!pyVersion) { throw 'Python version is not detected'; } const pyVersionSplit = pyVersion[1].split('.').map(d => Number(d)); if (pyVersionSplit[0] !== 3 || pyVersionSplit[1] < 9) { throw 'Minimum required python version is 3.9'; } text += checkPythonVar.data; const checkPyannoteScripts = await (0, shell_1.default)((0, shell_1.formatCommandString)('checks', '', options), options); text += checkPyannoteScripts.data; if (checkPyannoteScripts.code !== 0) { console.log('Python prerequisites check failed, aborted. Try to set venv path (https://docs.python.org/3/library/venv.html), if not done yet.'); throw text + (checkPyannoteScripts.errors ? '\nShell errors: ' + checkPyannoteScripts.errors : ''); } if (options.consoleTextInfo) { console.log('Python prerequisites check done successful'); console.log(text); } }; exports.checkPythonScripts = checkPythonScripts;