mirror of
https://gitlab.rlp.net/proj-wise2526-video2document/video2document.git
synced 2026-06-15 18:01:52 +02:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eec0b2d356 | |||
| 77dcf6d812 | |||
| b9881d55e7 | |||
| a7a8170cd5 | |||
| 15a4807567 | |||
| 3bbd82eddc | |||
| 55555bcc37 | |||
| 283b4ed6af |
@@ -88,6 +88,27 @@ Show your appreciation to those who have contributed to the project.
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
For open source projects, say how it is licensed.
|
For open source projects, say how it is licensed.
|
||||||
|
---
|
||||||
|
|
||||||
## Project status
|
## Sprint 4 – Secure API Key Management
|
||||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
||||||
|
In Sprint 4, secure handling of API keys was implemented for the V2D (Video to Document) framework.
|
||||||
|
|
||||||
|
### Implementation Overview
|
||||||
|
- API keys are **not stored in the source code**
|
||||||
|
- The backend loads the key from an **environment variable**
|
||||||
|
- A single configuration works for all users without manual setup
|
||||||
|
- Secrets are protected from being exposed in the repository or frontend
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
The backend expects the following environment variable:
|
||||||
|
|
||||||
|
|
||||||
|
This variable is injected at runtime by the deployment or CI/CD environment and referenced in `application.yml`.
|
||||||
|
|
||||||
|
### Security Benefits
|
||||||
|
- Prevents accidental exposure of API keys
|
||||||
|
- Ensures secure collaboration in GitLab
|
||||||
|
- Follows best practices for secret management
|
||||||
|
|
||||||
|
---
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ 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");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,21 +16,15 @@ 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+43
-49
@@ -6,7 +6,7 @@ manualUploadBtn.addEventListener('click', () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error in manualBtn EventListener click");
|
console.log("Error in manualBtn EventListener click");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//function to check if one checkbox is at least klicked
|
//function to check if one checkbox is at least klicked
|
||||||
@@ -15,24 +15,18 @@ 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")){
|
||||||
const lower = pathTest.toLowerCase();
|
window.extractor.extract({inputVideoPath: pathTest, outputType:"wav"})
|
||||||
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.');
|
||||||
@@ -40,43 +34,43 @@ function checkBoxes() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
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
|
||||||
function changeLanguage(language) {
|
function changeLanguage(language) {
|
||||||
if (language === 'en') {
|
if (language === 'en') {
|
||||||
document.getElementById('title').textContent = 'Video to document';
|
document.getElementById('title').textContent = 'Video to document';
|
||||||
document.getElementById('h1').textContent = 'Video to document';
|
document.getElementById('h1').textContent = 'Video to document';
|
||||||
document.getElementById('p1').textContent = 'Drag and drop video file';
|
document.getElementById('p1').textContent = 'Drag and drop video file';
|
||||||
document.getElementById('fileName').textContent = 'No video chosen';
|
document.getElementById('fileName').textContent = 'No video chosen';
|
||||||
document.getElementById('manualUploadBtn').textContent = 'Search video';
|
document.getElementById('manualUploadBtn').textContent = 'Search video';
|
||||||
document.getElementById('checkbox_group').textContent = 'Choose prefered document style:';
|
document.getElementById('checkbox_group').textContent = 'Choose prefered document style:';
|
||||||
document.getElementById('label_format').textContent = 'Meeting report';
|
document.getElementById('label_format').textContent = 'Meeting report';
|
||||||
document.getElementById('label_summary').textContent = 'Summary with timestamps';
|
document.getElementById('label_summary').textContent = 'Summary with timestamps';
|
||||||
document.getElementById('submitButton').textContent = 'Submit';
|
document.getElementById('submitButton').textContent = 'Submit';
|
||||||
} else if (language === 'de') {
|
} else if (language === 'de') {
|
||||||
document.getElementById('title').textContent = 'Video zu Dokument';
|
document.getElementById('title').textContent = 'Video zu Dokument';
|
||||||
document.getElementById('h1').textContent = 'Video zu Dokument';
|
document.getElementById('h1').textContent = 'Video zu Dokument';
|
||||||
document.getElementById('p1').textContent = 'Video per Drag & Drop ablegen';
|
document.getElementById('p1').textContent = 'Video per Drag & Drop ablegen';
|
||||||
document.getElementById('fileName').textContent = 'Kein Video ausgewaehlt';
|
document.getElementById('fileName').textContent = 'Kein Video ausgewaehlt';
|
||||||
document.getElementById('manualUploadBtn').textContent = 'Video suchen';
|
document.getElementById('manualUploadBtn').textContent = 'Video suchen';
|
||||||
document.getElementById('checkbox_group').textContent = 'Bevorzugte Dokumentvarianten:';
|
document.getElementById('checkbox_group').textContent = 'Bevorzugte Dokumentvarianten:';
|
||||||
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 = 'वीडियो फ़ाइल खींचें और छोड़ें';
|
||||||
document.getElementById('fileName').textContent = 'कोई वीडियो नहीं चुना गया';
|
document.getElementById('fileName').textContent = 'कोई वीडियो नहीं चुना गया';
|
||||||
document.getElementById('manualUploadBtn').textContent = 'वीडियो खोजें';
|
document.getElementById('manualUploadBtn').textContent = 'वीडियो खोजें';
|
||||||
document.getElementById('checkbox_group').textContent = 'पसंदीदा दस्तावेज़ शैली चुनें:';
|
document.getElementById('checkbox_group').textContent = 'पसंदीदा दस्तावेज़ शैली चुनें:';
|
||||||
document.getElementById('label_format').textContent = 'बैठक रिपोर्ट';
|
document.getElementById('label_format').textContent = 'बैठक रिपोर्ट';
|
||||||
document.getElementById('label_summary').textContent = 'टाइमस्टैम्प के साथ सारांश';
|
document.getElementById('label_summary').textContent = 'टाइमस्टैम्प के साथ सारांश';
|
||||||
document.getElementById('submitButton').textContent = 'जमा करना';
|
document.getElementById('submitButton').textContent = 'जमा करना';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +81,7 @@ videoUpload.addEventListener('change', () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error in manualBtn EventListener change");
|
console.log("Error in manualBtn EventListener change");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -105,11 +99,11 @@ function handleFiles(files) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error in script.js handleFiles function");
|
console.log("Error in script.js handleFiles function");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//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}%`;
|
||||||
@@ -117,5 +111,5 @@ function updateProgressBar(bar, value) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error in scripts.js updateProgressBar function");
|
console.log("Error in scripts.js updateProgressBar function");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -76,9 +76,4 @@ 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);
|
|
||||||
});
|
|
||||||
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
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,123 +1,8 @@
|
|||||||
require('dotenv').config();
|
|
||||||
|
|
||||||
const API_KEY = process.env.API_KEY;
|
|
||||||
const BASE_URL = 'https://api.assemblyai.com/v2';
|
|
||||||
|
|
||||||
//---------------------------------------------------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 = {
|
module.exports = {
|
||||||
name: 'assembly',
|
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',
|
type:"transcription", // value used to differentiate each module to order them in the UI
|
||||||
displayname: 'AssemblyAI',
|
displayname:"Assembly", // The displayname used within the UI
|
||||||
|
async function(parameter){
|
||||||
async function(audioFileName) {
|
// TODO add code to actually process the audio file
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
@@ -6,13 +6,6 @@ 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"})
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: v2d-document
|
||||||
|
|
||||||
|
app:
|
||||||
|
external:
|
||||||
|
apiKey: ${LLM_API_KEY:}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.v2d.document.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "app.external")
|
||||||
|
public class AppProperties {
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
public String getApiKey() { return apiKey; }
|
||||||
|
public void setApiKey(String apiKey) { this.apiKey = apiKey; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.v2d.document.controller;
|
||||||
|
|
||||||
|
import com.v2d.document.service.ExternalApiService;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/generate")
|
||||||
|
public class GenerateController {
|
||||||
|
|
||||||
|
private final ExternalApiService externalApiService;
|
||||||
|
|
||||||
|
public GenerateController(ExternalApiService externalApiService) {
|
||||||
|
this.externalApiService = externalApiService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<String> generate(@RequestBody Map<String,Object> body) {
|
||||||
|
// Build provider payload from the user's body (transform safely)
|
||||||
|
String payload = "{\"text\": \"use this text\"}"; // adapt for real usage
|
||||||
|
String providerResponse = externalApiService.callProvider(payload);
|
||||||
|
return ResponseEntity.ok(providerResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package com.v2d.document.service;
|
||||||
|
|
||||||
|
import com.v2d.document.config.AppProperties;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ExternalApiService {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(ExternalApiService.class);
|
||||||
|
private final AppProperties props;
|
||||||
|
private final HttpClient http = HttpClient.newHttpClient();
|
||||||
|
|
||||||
|
public ExternalApiService(AppProperties props) {
|
||||||
|
this.props = props;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String callProvider(String jsonPayload) {
|
||||||
|
String key = props.getApiKey();
|
||||||
|
if (key == null || key.isBlank()) {
|
||||||
|
log.warn("External API key is not configured.");
|
||||||
|
throw new IllegalStateException("External API key missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpRequest req = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create("https://api.example.com/endpoint")) // replace with real endpoint
|
||||||
|
.header("Authorization", "Bearer " + key)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse<String> resp = http.send(req, HttpResponse.BodyHandlers.ofString());
|
||||||
|
return resp.body();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("External API call failed: {}", e.getMessage());
|
||||||
|
throw new RuntimeException("External API call failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
package com.v2d.document.service;
|
||||||
|
|
||||||
|
import com.v2d.document.config.AppProperties;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ExternalApiService {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(ExternalApiService.class);
|
||||||
|
private final AppProperties props;
|
||||||
|
private final HttpClient http = HttpClient.newHttpClient();
|
||||||
|
|
||||||
|
public ExternalApiService(AppProperties props) {
|
||||||
|
this.props = props;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String callProvider(String jsonPayload) {
|
||||||
|
String key = props.getApiKey();
|
||||||
|
if (key == null || key.isBlank()) {
|
||||||
|
log.warn("External API key is not configured.");
|
||||||
|
throw new IllegalStateException("External API key missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpRequest req = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create("https://api.example.com/endpoint")) // replace with real endpoint
|
||||||
|
.header("Authorization", "Bearer " + key)
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse<String> resp = http.send(req, HttpResponse.BodyHandlers.ofString());
|
||||||
|
return resp.body();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("External API call failed: {}", e.getMessage());
|
||||||
|
throw new RuntimeException("External API call failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.v2d.document.config;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class AppPropertiesTest {
|
||||||
|
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
|
.withUserConfiguration(AppProperties.class)
|
||||||
|
.withPropertyValues("app.external.apiKey=TEST_KEY");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void bindsApiKey() {
|
||||||
|
contextRunner.run(context -> {
|
||||||
|
AppProperties props = context.getBean(AppProperties.class);
|
||||||
|
assertThat(props.getApiKey()).isEqualTo("TEST_KEY");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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
@@ -1,12 +0,0 @@
|
|||||||
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
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user