Upload files to "test_examples/VoiceToSpeech"
parent
6e5257fe50
commit
6181a5da83
|
@ -0,0 +1,11 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Audio zu Text</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<input type="file" accept="audio/*" id="audioFileInput">
|
||||||
|
<div id="transcriptionResult"></div>
|
||||||
|
<script src="jav.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,29 @@
|
||||||
|
const audioFileInput = document.getElementById('audioFileInput');
|
||||||
|
const transcriptionResult = document.getElementById('transcriptionResult');
|
||||||
|
|
||||||
|
audioFileInput.addEventListener('change', () => {
|
||||||
|
const audioFile = audioFileInput.files[0];
|
||||||
|
|
||||||
|
if (!audioFile) {
|
||||||
|
transcriptionResult.textContent = "Bitte wählen Sie eine Audiodatei aus.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FormData erstellen, um die Datei an den Server zu senden
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('audioFile', audioFile);
|
||||||
|
|
||||||
|
// HTTP POST-Anfrage an den Server senden
|
||||||
|
fetch('http://localhost:3000/upload', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
})
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(result => {
|
||||||
|
transcriptionResult.textContent = result;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
transcriptionResult.textContent = "Fehler beim Transkribieren der Audiodatei.";
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"@google-cloud/speech": "^6.0.2",
|
||||||
|
"child_process": "^1.0.2",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"fs": "^0.0.1-security",
|
||||||
|
"multer": "^1.4.5-lts.1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
const express = require('express');
|
||||||
|
const multer = require('multer');
|
||||||
|
const cors = require('cors');
|
||||||
|
const app = express();
|
||||||
|
const port = 3000;
|
||||||
|
const { exec } = require('child_process');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
app.use(cors());
|
||||||
|
|
||||||
|
app.use(express.static('public'));
|
||||||
|
|
||||||
|
const storage = multer.memoryStorage();
|
||||||
|
const upload = multer({ storage: storage });
|
||||||
|
|
||||||
|
app.post('/upload', upload.single('audioFile'), (req, res) => {
|
||||||
|
if (!req.file) {
|
||||||
|
return res.status(400).send("Keine Audiodatei hochgeladen.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Speichern Sie die Audiodatei vorübergehend
|
||||||
|
const audioFilePath = 'temp.wav';
|
||||||
|
fs.writeFileSync(audioFilePath, req.file.buffer);
|
||||||
|
|
||||||
|
// Verwenden Sie pocketsphinx für die Transkription
|
||||||
|
exec(`pocketsphinx_continuous -infile ${audioFilePath}`, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.error('Fehler bei der Transkription:', error);
|
||||||
|
res.status(500).send('Fehler bei der Transkription');
|
||||||
|
} else {
|
||||||
|
res.send(stdout);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`Server läuft auf Port ${port}`);
|
||||||
|
});
|
Binary file not shown.
Loading…
Reference in New Issue