mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
worked on fixing the code
This commit is contained in:
@@ -139,7 +139,7 @@ electron.ipcMain.on("file_submit", async (event, args) => {
|
|||||||
let audiopath = ""
|
let audiopath = ""
|
||||||
let transcriptpath = ""
|
let transcriptpath = ""
|
||||||
|
|
||||||
console.log("\n\n Running the Video to Audio Extractor");
|
/* console.log("\n\n Running the Video to Audio Extractor");
|
||||||
// This code handles the Video to Audio extraction module call
|
// This code handles the Video to Audio extraction module call
|
||||||
await mapFunctions.get("module-handler").function(args.video.module, {inputVideoPath: args.video.inputVideoPath, outputType: args.video.outputType}).then(resp => {
|
await mapFunctions.get("module-handler").function(args.video.module, {inputVideoPath: args.video.inputVideoPath, outputType: args.video.outputType}).then(resp => {
|
||||||
console.log(resp);
|
console.log(resp);
|
||||||
@@ -164,11 +164,13 @@ electron.ipcMain.on("file_submit", async (event, args) => {
|
|||||||
mainWindow.webContents.send("error", err)
|
mainWindow.webContents.send("error", err)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
|
|
||||||
console.log("\n\n Running the Transcription Summarizer module");
|
console.log("\n\n Running the Transcription Summarizer module");
|
||||||
// This code summarises the transcript, so that it can be used by an llm
|
// This code summarises the transcript, so that it can be used by an llm
|
||||||
await mapFunctions.get("summarize-transcription").function(transcriptpath).then(resp => {
|
// await mapFunctions.get("summarize-transcription").function(transcriptpath).then(resp => {
|
||||||
|
await mapFunctions.get("summarize-transcription").function('/Users/santa/Proj25/video2document/storage/transcripts/IMG_2978.json').then(resp => {
|
||||||
|
|
||||||
console.log(resp);
|
console.log(resp);
|
||||||
transcriptpath = resp
|
transcriptpath = resp
|
||||||
curstep++
|
curstep++
|
||||||
|
|||||||
Generated
+2
@@ -299,6 +299,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.2.tgz",
|
||||||
"integrity": "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA==",
|
"integrity": "sha512-uWN8YqxXxqFMX2RqGOrumsKeti4LlmIMIyV0lgut4jx7KQBcBiW6vkDtIBvHnHIquwNfJhk8v2OtmO8zXWHfPA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~7.16.0"
|
"undici-types": "~7.16.0"
|
||||||
}
|
}
|
||||||
@@ -2534,6 +2535,7 @@
|
|||||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
"peer": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
"tsserver": "bin/tsserver"
|
"tsserver": "bin/tsserver"
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
const fs = require("fs");
|
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
// Prepare output directory (always storage/transcriptionSummaries under project root)
|
// Prepare output directory (always storage/transcriptionSummaries under project root)
|
||||||
const outputDir = `${__dirname}/../../../storage/transcriptionSummaries`;
|
const outputDir = `${__dirname}/../../../storage/transcriptionSummaries`;
|
||||||
@@ -14,49 +12,98 @@ module.exports = {
|
|||||||
type: "summarizer", // value used to differentiate each module to order them in the UI
|
type: "summarizer", // value used to differentiate each module to order them in the UI
|
||||||
displayname: "Summarizer", // The displayname used within the UI
|
displayname: "Summarizer", // The displayname used within the UI
|
||||||
async function(args) {
|
async function(args) {
|
||||||
let inputJson = args.json;
|
return new Promise(async (resolve, reject) => {
|
||||||
|
let inputJson = args.json;
|
||||||
|
|
||||||
//JSON Path
|
//JSON Path
|
||||||
if (args.jsonPath) {
|
if (args.jsonPath) {
|
||||||
try {
|
try {
|
||||||
const raw = fs.readFileSync(args.jsonPath, "utf-8");
|
const raw = fs.readFileSync(args.jsonPath, "utf-8");
|
||||||
inputJson = JSON.parse(raw);
|
inputJson = JSON.parse(raw);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to load JSON from file:", e);
|
console.error("Failed to load JSON from file:", e);
|
||||||
return { error: "Could not read JSON from file path." };
|
return { error: "Could not read JSON from file path." };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// JSON parsen
|
||||||
// JSON parsen
|
if (typeof args === "string") {
|
||||||
if (typeof inputJson === "string") {
|
try {
|
||||||
try {
|
await fs.readFile(args, 'utf8', function (err, data) {
|
||||||
inputJson = JSON.parse(inputJson);
|
if (err) throw err;
|
||||||
} catch (e) {
|
inputJson = JSON.parse(data);
|
||||||
console.log("Invalid JSON in summarize-transcription");
|
});
|
||||||
return { error: "Invalid JSON" };
|
} catch (e) {
|
||||||
|
console.log("Invalid JSON in summarize-transcription");
|
||||||
|
console.log(e)
|
||||||
|
return { error: "Invalid JSON" };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const words = inputJson.words;
|
const words = inputJson.words;
|
||||||
if (!Array.isArray(words)) {
|
if (!Array.isArray(words)) {
|
||||||
return { error: "No words Array found" };
|
return { error: "No words Array found" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const ENDINGS = [".", "!", "?"]; // '...' auch als Satzende ?
|
const ENDINGS = [".", "!", "?"]; // '...' auch als Satzende ?
|
||||||
const ABBREVIATIONS = new Set(["z.B.", "bzw.", "u.a.", "Dr.", "Mr.", "Mrs.", "Prof.", "etc."]); //TODO weitere Ergaenzen
|
const ABBREVIATIONS = new Set(["z.B.", "bzw.", "u.a.", "Dr.", "Mr.", "Mrs.", "Prof.", "etc."]); //TODO weitere Ergaenzen
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
let currentSentence = "";
|
let currentSentence = "";
|
||||||
let currentSpeaker = null;
|
let currentSpeaker = null;
|
||||||
let startTime = null;
|
let startTime = null;
|
||||||
let endTime = null;
|
let endTime = null;
|
||||||
|
|
||||||
for (const w of words) {
|
for (const w of words) {
|
||||||
if (!currentSpeaker) currentSpeaker = w.speaker;
|
if (!currentSpeaker) currentSpeaker = w.speaker;
|
||||||
if (startTime === null) startTime = w.start;
|
if (startTime === null) startTime = w.start;
|
||||||
endTime = w.end;
|
endTime = w.end;
|
||||||
|
|
||||||
//speaker changing
|
//speaker changing
|
||||||
if (currentSpeaker !== w.speaker && currentSentence) {
|
if (currentSpeaker !== w.speaker && currentSentence) {
|
||||||
|
const lastEntry = result[result.length - 1];
|
||||||
|
if (lastEntry && lastEntry.speaker === currentSpeaker) {
|
||||||
|
lastEntry.sentence += " " + currentSentence;
|
||||||
|
lastEntry.end = endTime;
|
||||||
|
} else {
|
||||||
|
result.push({
|
||||||
|
speaker: currentSpeaker,
|
||||||
|
sentence: currentSentence,
|
||||||
|
start: startTime,
|
||||||
|
end: endTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
currentSentence = "";
|
||||||
|
startTime = w.start;
|
||||||
|
}
|
||||||
|
currentSpeaker = w.speaker;
|
||||||
|
currentSentence += (currentSentence ? " " : "") + w.text; //sentence beginning or not
|
||||||
|
const lastWord = w.text.trim();
|
||||||
|
const lastChar = lastWord.slice(-1);
|
||||||
|
const isAbbreviation = ABBREVIATIONS.has(lastWord);
|
||||||
|
|
||||||
|
//sentence ending
|
||||||
|
if (ENDINGS.includes(lastChar) && !isAbbreviation) {
|
||||||
|
const lastEntry = result[result.length - 1];
|
||||||
|
if (lastEntry && lastEntry.speaker === currentSpeaker) {
|
||||||
|
lastEntry.sentence += " " + currentSentence;
|
||||||
|
lastEntry.end = endTime;
|
||||||
|
} else {
|
||||||
|
result.push({
|
||||||
|
speaker: currentSpeaker,
|
||||||
|
sentence: currentSentence,
|
||||||
|
start: startTime,
|
||||||
|
end: endTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
currentSentence = "";
|
||||||
|
startTime = null;
|
||||||
|
endTime = null;
|
||||||
|
currentSpeaker = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// safe last sentence
|
||||||
|
if (currentSentence) {
|
||||||
const lastEntry = result[result.length - 1];
|
const lastEntry = result[result.length - 1];
|
||||||
if (lastEntry && lastEntry.speaker === currentSpeaker) {
|
if (lastEntry && lastEntry.speaker === currentSpeaker) {
|
||||||
lastEntry.sentence += " " + currentSentence;
|
lastEntry.sentence += " " + currentSentence;
|
||||||
@@ -69,70 +116,30 @@ module.exports = {
|
|||||||
end: endTime
|
end: endTime
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
currentSentence = "";
|
|
||||||
startTime = w.start;
|
|
||||||
}
|
}
|
||||||
currentSpeaker = w.speaker;
|
|
||||||
currentSentence += (currentSentence ? " " : "") + w.text; //sentence beginning or not
|
|
||||||
const lastWord = w.text.trim();
|
|
||||||
const lastChar = lastWord.slice(-1);
|
|
||||||
const isAbbreviation = ABBREVIATIONS.has(lastWord);
|
|
||||||
|
|
||||||
//sentence ending
|
// Output as Text
|
||||||
if (ENDINGS.includes(lastChar) && !isAbbreviation) {
|
const output = result.map(r =>
|
||||||
const lastEntry = result[result.length - 1];
|
`Sprecher ${r.speaker} [${r.start.toFixed(2)} - ${r.end.toFixed(2)}]: ${r.sentence}`
|
||||||
if (lastEntry && lastEntry.speaker === currentSpeaker) {
|
);
|
||||||
lastEntry.sentence += " " + currentSentence;
|
|
||||||
lastEntry.end = endTime;
|
// Output on cosole
|
||||||
} else {
|
//console.log("\n------------\nMerged Transcription Result:\n", output, "\n------------\n");
|
||||||
result.push({
|
|
||||||
speaker: currentSpeaker,
|
try {
|
||||||
sentence: currentSentence,
|
const jsonPath = path.join(outputDir, "transcription_result.json");
|
||||||
start: startTime,
|
fs.writeFileSync(jsonPath, JSON.stringify(result, null, 2), "utf-8");
|
||||||
end: endTime
|
|
||||||
});
|
const txtPath = path.join(outputDir, "transcription_result.txt");
|
||||||
}
|
fs.writeFileSync(txtPath, output.join("\n"), "utf-8");
|
||||||
currentSentence = "";
|
|
||||||
startTime = null;
|
console.log(`Summary successfully saved:\n- ${jsonPath}\n- ${txtPath}`);
|
||||||
endTime = null;
|
|
||||||
currentSpeaker = null;
|
resolve(jsonPath);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error saving Summary:", err);
|
||||||
|
reject(err);
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
// safe last sentence
|
|
||||||
if (currentSentence) {
|
|
||||||
const lastEntry = result[result.length - 1];
|
|
||||||
if (lastEntry && lastEntry.speaker === currentSpeaker) {
|
|
||||||
lastEntry.sentence += " " + currentSentence;
|
|
||||||
lastEntry.end = endTime;
|
|
||||||
} else {
|
|
||||||
result.push({
|
|
||||||
speaker: currentSpeaker,
|
|
||||||
sentence: currentSentence,
|
|
||||||
start: startTime,
|
|
||||||
end: endTime
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output as Text
|
|
||||||
const output = result.map(r =>
|
|
||||||
`Sprecher ${r.speaker} [${r.start.toFixed(2)} - ${r.end.toFixed(2)}]: ${r.sentence}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Output on cosole
|
|
||||||
//console.log("\n------------\nMerged Transcription Result:\n", output, "\n------------\n");
|
|
||||||
|
|
||||||
try {
|
|
||||||
const jsonPath = path.join(outputDir, "transcription_result.json");
|
|
||||||
fs.writeFileSync(jsonPath, JSON.stringify(result, null, 2), "utf-8");
|
|
||||||
|
|
||||||
const txtPath = path.join(outputDir, "transcription_result.txt");
|
|
||||||
fs.writeFileSync(txtPath, output.join("\n"), "utf-8");
|
|
||||||
|
|
||||||
console.log(`Summary successfully saved:\n- ${jsonPath}\n- ${txtPath}`);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error saving Summary:", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ function saveTranscript(transcript, sessionId) {
|
|||||||
fs.writeFileSync(outputPath, JSON.stringify(transcript, null, 2));
|
fs.writeFileSync(outputPath, JSON.stringify(transcript, null, 2));
|
||||||
|
|
||||||
console.log(`Transcript saved: ${outputPath}`);
|
console.log(`Transcript saved: ${outputPath}`);
|
||||||
|
|
||||||
|
return outputPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------Modul---------------------------------------------------
|
//---------------------------------------------------Modul---------------------------------------------------
|
||||||
@@ -89,29 +91,33 @@ module.exports = {
|
|||||||
displayname: 'AssemblyAI',
|
displayname: 'AssemblyAI',
|
||||||
|
|
||||||
async function(audioFileName) {
|
async function(audioFileName) {
|
||||||
try {
|
return new Promise(async (resolve, reject) => {
|
||||||
// audioFileName ist nur "datei.mp3"
|
try {
|
||||||
const audioPath = audioFileName;
|
// audioFileName ist nur "datei.mp3"
|
||||||
|
const audioPath = audioFileName;
|
||||||
|
|
||||||
let audioUrl;
|
let audioUrl;
|
||||||
|
|
||||||
if (/^https?:\/\//i.test(audioFileName)) {
|
if (/^https?:\/\//i.test(audioFileName)) {
|
||||||
audioUrl = audioFileName;
|
audioUrl = audioFileName;
|
||||||
} else {
|
} else {
|
||||||
if (!fs.existsSync(audioPath)) {
|
if (!fs.existsSync(audioPath)) {
|
||||||
throw new Error(`Audio file not found: ${audioPath}`);
|
throw new Error(`Audio file not found: ${audioPath}`);
|
||||||
|
}
|
||||||
|
audioUrl = await uploadAudio(audioPath);
|
||||||
}
|
}
|
||||||
audioUrl = await uploadAudio(audioPath);
|
|
||||||
|
const transcriptId = await createTranscript(audioUrl);
|
||||||
|
const transcript = await pollTranscript(transcriptId);
|
||||||
|
|
||||||
|
const sessionId = getSessionId(audioFileName);
|
||||||
|
|
||||||
|
resolve(saveTranscript(transcript, sessionId));
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Transcription error:', error.message);
|
||||||
|
reject(error);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
const transcriptId = await createTranscript(audioUrl);
|
|
||||||
const transcript = await pollTranscript(transcriptId);
|
|
||||||
|
|
||||||
const sessionId = getSessionId(audioFileName);
|
|
||||||
saveTranscript(transcript, sessionId);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Transcription error:', error.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user