39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
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}`);
|
|
});
|