mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-16 02:11:52 +02:00
merge: Resolve conflicts with develop
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
name:"assembly", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()"
|
||||
type:"transcription", // value used to differentiate each module to order them in the UI
|
||||
displayname:"Assembly", // The displayname used within the UI
|
||||
async function(parameter){
|
||||
// TODO add code to actually process the audio file
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
name:"example", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()"
|
||||
type:"example-type", // value used to differentiate each module to order them in the UI
|
||||
displayname:"Example", // The displayname used within the UI
|
||||
async function(randomParameter){
|
||||
// Here we put a simple console.log to show how the system works
|
||||
// This function will be called from the @startup.js function in the utility folder
|
||||
console.log(`\n------------\nThis is the example function called by the ${randomParameter} function\n------------\n`);
|
||||
}
|
||||
}
|
||||
+1
Submodule services/modules/transcription/local/whisper.cpp added at 999a7e0cbf
@@ -0,0 +1,55 @@
|
||||
import { exec } from "child_process"; // Node.js built-in module
|
||||
import path from "path"; // Path module
|
||||
import fs from "fs"; // File system module
|
||||
import { fileURLToPath } from "url"; // To handle __dirname in ES modules
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url); // Get current file path
|
||||
const __dirname = path.dirname(__filename); // Get current directory path
|
||||
const transcriptsDir = path.resolve(__dirname, "../../storage/transcriptions");
|
||||
|
||||
|
||||
export class whisperLocal { // is called by transcribe.ts
|
||||
private whisperBinary: string; // Path to the whisper.cpp binary
|
||||
private modelPath: string; // Path to the model file
|
||||
|
||||
constructor() {
|
||||
this.whisperBinary = path.resolve(
|
||||
__dirname,
|
||||
"whisper.cpp/build/bin/whisper-cli" //Path to the compiled whisper binary
|
||||
);
|
||||
|
||||
this.modelPath = path.resolve(
|
||||
__dirname,
|
||||
"whisper.cpp/models/ggml-base.en.bin" // Path to the English model file
|
||||
);
|
||||
}
|
||||
|
||||
async transcribe(audioPath: string): Promise<string> { //asyncronous function to transcribe audio
|
||||
return new Promise((resolve, reject) => {
|
||||
const transcriptsDir = path.resolve(__dirname, "../../../../storage/transcripts"); //storage directory for transcripts
|
||||
|
||||
if (!fs.existsSync(transcriptsDir)) { //if transcripts directory does not exist, create it
|
||||
fs.mkdirSync(transcriptsDir, { recursive: true });
|
||||
}
|
||||
|
||||
const outputBase = path.resolve( // Base path for output transcript files, name is same as audio file (video file)
|
||||
transcriptsDir,
|
||||
path.basename(audioPath, path.extname(audioPath))
|
||||
);
|
||||
|
||||
const command = `"${this.whisperBinary}" -m "${this.modelPath}" -f "${audioPath}" -otxt -of "${outputBase}"`; // Command to execute whisper binary with model and audio file, outputting text file
|
||||
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) return reject(error);
|
||||
|
||||
const outputTxt = `${outputBase}.txt`;
|
||||
if (fs.existsSync(outputTxt)) {
|
||||
const transcript = fs.readFileSync(outputTxt, "utf8");
|
||||
resolve(transcript);
|
||||
} else {
|
||||
reject(new Error("No transcript file found"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user