Compare commits

...

6 Commits

Author SHA1 Message Date
santa 2f5efee9c7 Summarizer und weiters angepasst 2025-11-24 14:27:49 +01:00
santa 465fe8bd41 Summarizer angepasst 2025-11-24 14:25:29 +01:00
santa b87bfd444d Test erstellt 2025-11-20 13:27:15 +01:00
santa 97b571b7f9 Einbindung des Summarizer 2025-11-20 11:51:34 +01:00
santa 455147a41b Summarizer Tool erstellt zur zusammenfassung der vom TranskriptionTool kommenden json 2025-11-20 10:15:11 +01:00
santa 9441699561 if Pruefung fuer Datei Endung gefixt 2025-11-16 14:46:19 +01:00
11 changed files with 12805 additions and 54 deletions
+3
View File
@@ -12,6 +12,9 @@ try {
contextBridge.exposeInMainWorld("electronAPI", { contextBridge.exposeInMainWorld("electronAPI", {
getFilePath: (file) => {return webUtils.getPathForFile(file)} getFilePath: (file) => {return webUtils.getPathForFile(file)}
}) })
contextBridge.exposeInMainWorld("summarizer", {
runFile: (file) => ipcRenderer.send("summarize-transcription", file)
});
} catch (error) { } catch (error) {
console.log("Error in preload.js"); console.log("Error in preload.js");
} }
+9 -3
View File
@@ -16,15 +16,21 @@ uploadContainer.addEventListener("drop", (e) => {
e.preventDefault() e.preventDefault()
const files = e.dataTransfer.files const files = e.dataTransfer.files
const filePath = window.explorer.onFileDrop(files[0]) const filePath = window.explorer.onFileDrop(files[0])
var holdy = filePath + "";
if(holdy.endsWith(".mp4") || holdy.endsWith(".mov") || holdy.endsWith(".avi") || holdy.endsWith( ".mkv")){
console.log(filePath)
var holdy = String(filePath);
const lower = holdy.toLowerCase();
const validExt = [".mp4", ".mov", ".avi", ".mkv"];
if(validExt.some(ext => lower.endsWith(ext))){
console.log(filePath);
const files1 = e.dataTransfer.files; const files1 = e.dataTransfer.files;
handleFiles(files1); handleFiles(files1);
}else{
console.log('Video format invalid!');
} }
} catch (error) { } catch (error) {
console.log("Error in renderer.js with the listerner for the drop function"); console.log("Error in renderer.js with the listerner for the drop function");
console.log(error);
} }
+14 -8
View File
@@ -15,18 +15,24 @@ function checkBoxes() {
const checkboxes = document.querySelectorAll('input[name="docFormat"]'); const checkboxes = document.querySelectorAll('input[name="docFormat"]');
let isChecked = false; let isChecked = false;
checkboxes.forEach(function(checkbox){ checkboxes.forEach(function (checkbox) {
if(checkbox.checked){ if (checkbox.checked) {
isChecked = true; isChecked = true;
} }
}); });
if(isChecked){ if (isChecked) {
//Code to submit the video //Code to submit the video
var pathTest = window.electronAPI.getFilePath(videoUpload.files[0]); var pathTest = window.electronAPI.getFilePath(videoUpload.files[0]);
if(pathTest.endsWith(".mp4") || holdy.endsWith(".mov") || holdy.endsWith(".avi") || holdy.endsWith( ".mkv")){
window.extractor.extract({inputVideoPath: pathTest, outputType:"wav"}) const lower = pathTest.toLowerCase();
const validExt = [".mp4", ".mov", ".avi", ".mkv"];
if(validExt.some(ext => lower.endsWith(ext))){
window.extractor.extract({ inputVideoPath: pathTest, outputType: "wav" });
} }
} else { } else {
//language only english at the moment //language only english at the moment
alert('Please select at least one document type.'); alert('Please select at least one document type.');
@@ -35,7 +41,7 @@ function checkBoxes() {
console.log(error) console.log(error)
} }
// mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./a.mp4", outputType:"wav"}) // mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./a.mp4", outputType:"wav"})
} }
//language changing feature //language changing feature
@@ -60,7 +66,7 @@ function changeLanguage(language) {
document.getElementById('label_format').textContent = 'Meeting Bericht'; document.getElementById('label_format').textContent = 'Meeting Bericht';
document.getElementById('label_summary').textContent = 'Zusammenfassung mit Zeitstempeln'; document.getElementById('label_summary').textContent = 'Zusammenfassung mit Zeitstempeln';
document.getElementById('submitButton').textContent = 'Absenden'; document.getElementById('submitButton').textContent = 'Absenden';
} else if(language == "in") { } else if (language == "in") {
document.getElementById('title').textContent = 'दस्तावेज़ के लिए वीडियो'; document.getElementById('title').textContent = 'दस्तावेज़ के लिए वीडियो';
document.getElementById('h1').textContent = 'दस्तावेज़ के लिए वीडियो'; document.getElementById('h1').textContent = 'दस्तावेज़ के लिए वीडियो';
document.getElementById('p1').textContent = 'वीडियो फ़ाइल खींचें और छोड़ें'; document.getElementById('p1').textContent = 'वीडियो फ़ाइल खींचें और छोड़ें';
@@ -103,7 +109,7 @@ function handleFiles(files) {
} }
//function to regulate the progress on the progressbar //function to regulate the progress on the progressbar
function updateProgressBar(bar, value){ function updateProgressBar(bar, value) {
try { try {
value = Math.round(value); value = Math.round(value);
bar.querySelector(".progress_fill").style.width = `${value}%`; bar.querySelector(".progress_fill").style.width = `${value}%`;
+5
View File
@@ -77,3 +77,8 @@ electron.app.whenReady().then(createWindow);
electron.ipcMain.on("extract", (event, args) => { electron.ipcMain.on("extract", (event, args) => {
mapFunctions.get("extraction-video-to-audio").function(args) mapFunctions.get("extraction-video-to-audio").function(args)
}) })
electron.ipcMain.on("summarize-transcription", (event, args) => {
mapFunctions.get("summarize-transcription").function(args);
});
@@ -0,0 +1,138 @@
const fs = require("fs");
const path = require("path");
// Prepare output directory (always storage/transcriptionSummaries under project root)
const outputDir = `${__dirname}/../../../storage/transcriptionSummaries`;
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
//Speaker, ALL-Sentences, Start, End
module.exports = {
name: "summarize-transcription", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()"
type: "summarizer", // value used to differentiate each module to order them in the UI
displayname: "Summarizer", // The displayname used within the UI
async function(args) {
let inputJson = args.json;
//JSON Path
if (args.jsonPath) {
try {
const raw = fs.readFileSync(args.jsonPath, "utf-8");
inputJson = JSON.parse(raw);
} catch (e) {
console.error("Failed to load JSON from file:", e);
return { error: "Could not read JSON from file path." };
}
}
// JSON parsen
if (typeof inputJson === "string") {
try {
inputJson = JSON.parse(inputJson);
} catch (e) {
console.log("Invalid JSON in summarize-transcription");
return { error: "Invalid JSON" };
}
}
const words = inputJson.words;
if (!Array.isArray(words)) {
return { error: "No words Array found" };
}
const ENDINGS = [".", "!", "?"]; // '...' auch als Satzende ?
const ABBREVIATIONS = new Set(["z.B.", "bzw.", "u.a.", "Dr.", "Mr.", "Mrs.", "Prof.", "etc."]); //TODO weitere Ergaenzen
const result = [];
let currentSentence = "";
let currentSpeaker = null;
let startTime = null;
let endTime = null;
for (const w of words) {
if (!currentSpeaker) currentSpeaker = w.speaker;
if (startTime === null) startTime = w.start;
endTime = w.end;
//speaker changing
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];
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);
}
}
}
@@ -0,0 +1,121 @@
const fs = require("fs");
const path = require("path");
// Prepare output directory (always storage/transcriptionSummaries under project root)
const outputDir = `${__dirname}/../../../storage/transcriptionSummaries`;
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
//Speaker, Sentence, Start, End
module.exports = {
name: "summarize-transcription2", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()"
type: "summarizer", // value used to differentiate each module to order them in the UI
displayname: "Summarizer", // The displayname used within the UI
async function(args) {
let inputJson = args.json;
//JSON Path
if (args.jsonPath) {
try {
const raw = fs.readFileSync(args.jsonPath, "utf-8");
inputJson = JSON.parse(raw);
} catch (e) {
console.error("Failed to load JSON from file:", e);
return { error: "Could not read JSON from file path." };
}
}
// JSON parsen
if (typeof inputJson === "string") {
try {
inputJson = JSON.parse(inputJson);
} catch (e) {
console.log("Invalid JSON in summarize-transcription");
return { error: "Invalid JSON" };
}
}
const words = inputJson.words;
if (!Array.isArray(words)) {
return { error: "No words Array found" };
}
const ENDINGS = [".", "!", "?"]; // '...' auch als Satzende ?
const ABBREVIATIONS = new Set(["z.B.", "bzw.", "u.a.", "Dr.", "Mr.", "Mrs.", "Prof.", "etc."]); //TODO weitere Ergaenzen
const result = [];
let currentSentence = "";
let currentSpeaker = null;
let startTime = null;
let endTime = null;
for (const w of words) {
if (!currentSpeaker) currentSpeaker = w.speaker;
if (startTime === null) startTime = w.start;
endTime = w.end;
//speaker changing
if (currentSpeaker !== w.speaker && currentSentence) {
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) {
result.push({
speaker: currentSpeaker,
sentence: currentSentence,
start: startTime,
end: endTime
});
currentSentence = "";
startTime = null;
endTime = null;
currentSpeaker = null;
}
}
// safe last sentence
if (currentSentence) {
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);
}
}
}
@@ -1,8 +1,123 @@
module.exports = { require('dotenv').config();
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 const API_KEY = process.env.API_KEY;
displayname:"Assembly", // The displayname used within the UI const BASE_URL = 'https://api.assemblyai.com/v2';
async function(parameter){
// TODO add code to actually process the audio file //---------------------------------------------------Upload audio---------------------------------------------------
async function uploadAudio(audioPath) {
const audioData = fs.readFileSync(audioPath);
const response = await axios.post(`${BASE_URL}/upload`, audioData, {
headers: {
authorization: API_KEY,
'content-type': 'application/octet-stream'
}
});
return response.data.upload_url;
}
////---------------------------------------------------Extract session id---------------------------------------------------
function getSessionId(inputPath) {
try {
const parsed = new URL(inputPath);
const base = path.basename(parsed.pathname);
return base.replace(/\.[^.]+$/, '');
} catch {
return path.basename(inputPath, path.extname(inputPath));
} }
} }
//---------------------------------------------------Create transcript---------------------------------------------------
async function createTranscript(audioUrl) {
const response = await axios.post(
`${BASE_URL}/transcript`,
{
audio_url: audioUrl,
speaker_labels: true,
language_detection: true
},
{
headers: {
authorization: API_KEY,
'content-type': 'application/json'
}
}
);
return response.data.id;
}
//---------------------------------------------------Poll transcript---------------------------------------------------
async function pollTranscript(transcriptId) {
while (true) {
const response = await axios.get(`${BASE_URL}/transcript/${transcriptId}`, {
headers: { authorization: API_KEY }
});
const status = response.data.status;
if (status === 'completed') return response.data;
if (status === 'error') throw new Error(`Transcription failed: ${response.data.error}`);
await new Promise(res => setTimeout(res, 3000));
}
}
//---------------------------------------------------Save transcript---------------------------------------------------
function saveTranscript(transcript, sessionId) {
const outputDir = path.join(__dirname, '../../../storage/transcripts');
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
const outputPath = path.join(outputDir, `${sessionId}.json`);
fs.writeFileSync(outputPath, JSON.stringify(transcript, null, 2));
console.log(`Transcript saved: ${outputPath}`);
}
//---------------------------------------------------Modul---------------------------------------------------
module.exports = {
name: 'assembly',
type: 'transcription',
displayname: 'AssemblyAI',
async function(audioFileName) {
try {
// audioFileName ist nur "datei.mp3"
const audioPath = path.join(
__dirname,
'../../../storage/audio',
audioFileName
);
let audioUrl;
if (/^https?:\/\//i.test(audioFileName)) {
audioUrl = audioFileName;
} else {
if (!fs.existsSync(audioPath)) {
throw new Error(`Audio file not found: ${audioPath}`);
}
audioUrl = await uploadAudio(audioPath);
}
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);
}
}
};
+7
View File
@@ -6,6 +6,13 @@ module.exports = {
// We are now calling the example function from the example folder // We are now calling the example function from the example folder
mapFunctions.get("example").function("Startup") mapFunctions.get("example").function("Startup")
let transcript = await mapFunctions.get("assembly").function('../../storage/audio/IMG_2978.wav');
let summary = await mapFunctions.get("summarize-transcription").function({jsonPath:'/Users/santa/Proj25/video2document/storage/transcripts/IMG_2978.json'});
// mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./a.mp4", outputType:"wav"}) // mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./a.mp4", outputType:"wav"})
// mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./b.mp4", outputType:"wav"}) // mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./b.mp4", outputType:"wav"})
// mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./b.mp4", outputType:"flac"}) // mapFunctions.get("extraction-video-to-audio").function({inputVideoPath:"./b.mp4", outputType:"flac"})
+18
View File
@@ -0,0 +1,18 @@
require('dotenv').config();
const path = require('path');
const assemblyModule = require('../../services/modules/transcription-remote/assembly.js');
// Audio-Datei oder URL aus Kommandozeile, Standard: test.wav
const audioPath = process.argv[2] || './storage/audio/IMG_2978.wav';
(async () => {
try {
const transcript = await assemblyModule.run(audioPath);
console.log('Transcription succesful');
console.log('Transcript ID:', transcript?.id);
console.log('Speaker labels:', transcript?.utterances?.length || 0);
} catch (error) {
console.error('Error in Transcription:', error?.message || error);
}
})();
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,12 @@
const fs = require('fs');
const transSummarizer = require("../../services/modules/jsonTools/transcriptionSummarizer.js");
// JSON-Datei laden
const inputJson = JSON.parse(fs.readFileSync("./testFile.json", "utf8"));
// Übergabe an den Summarizer
transSummarizer.function({
json: inputJson
});