MCPcopy Create free account
hub / github.com/AS-AIGC/TranscriptHub / execute_task

Function execute_task

apps/backend/main.js:204–371  ·  view source on GitHub ↗

* @brief Execute audio transcription task using WhisperX * * This function handles the complete lifecycle of a transcription task: * 1. Task selection and validation * 2. Python subprocess execution for transcription * 3. Result processing and file cleanup * 4. Status updates and

()

Source from the content-addressed store, hash-verified

202 * @return {Promise<void>} Resolves when task completes or fails
203 */
204 async function execute_task() {
205 var task_objid = 0;
206 var task_filename = '';
207 var task_diarize = 0; // Speaker Diarization
208
209 try {
210 const selected_task = await select_task();
211
212 // Check if selected_task is null
213 if (!selected_task) {
214 return; // Exit if selected_task is null or has no records
215 }
216
217 task_objid = selected_task.OBJID;
218 task_filename = selected_task.FILENAME;
219 task_diarize = selected_task.DIARIZE;
220
221 logger(LOG_LEVEL.INFO, `Execution of the task ${task_objid} has begun.`);
222
223 } catch (err) {
224 logger(LOG_LEVEL.ERROR, `execute_task ${err}.`);
225 return;
226 }
227
228 // Ensure this path is the correct path to Python in your Anaconda environment
229 const python_bin = `${cfg.paths.python_bin}`;
230 // The python script to run whisperx
231 const transcribe_script_path = `${cfg.paths.task_script_path}/${cfg.paths.task_script}`;
232 const transcribe_txt_path = cfg.paths.transcribe_txt_path;
233
234 const parsed = path.parse(task_filename);
235
236 update_task({
237 objid: task_objid,
238 pid: process.pid,
239 status: TASK_STATUS.IN_PROGRESS
240 });
241
242 // chcp 65001 ensures that when Node.js calls a Python script, and it involves
243 // outputting Unicode characters to Windows cmd (default cp950 encoding), errors
244 // may occur due to incompatible encodings. Therefore, before calling exec
245 // in the Node.js script, you can set the Windows cmd encoding to UTF-8 (i.e., chcp 65001),
246 // which allows for the correct handling of Unicode characters.
247 // Execute the script using Python from the Anaconda environment, where 'chcp 65001 > null'
248 // directs the message from changing the encoding to null.
249 // child_process = exec(`chcp 65001 >nul && ${python_bin} ${python_script_path} ${task_filename}`, (err, stdout, stderr) => {
250 // Use spawn instead of exec
251 child_process = spawn(python_bin, [transcribe_script_path, task_filename, task_diarize]);
252
253 // Listen to stdout data
254 child_process.stdout.on('data', (data) => {
255 if (__DEV__)
256 logger(LOG_LEVEL.INFO, `execute_task (transcribe script) stdout:\n${data}`);
257 });
258
259 // Listen to stderr data
260 child_process.stderr.on('data', (data) => {
261 if (__DEV__)

Callers 1

main.jsFile · 0.85

Calls 5

select_taskFunction · 0.85
loggerFunction · 0.85
update_taskFunction · 0.85
operation_memoFunction · 0.85
send_notificationFunction · 0.85

Tested by

no test coverage detected