Created
April 11, 2022 23:52
-
-
Save musha635842/d081588cf2d03f0225c67d2fd57c93d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const formidable = require('formidable'); | |
const fs = require('fs'); | |
const { Deepgram } = require('@deepgram/sdk'); | |
const app = express(); | |
// Your Deepgram API Key | |
const deepgramApiKey = 'YOUR_DEEPGRAM_API_KEY'; | |
// Initialize the Deepgram SDK | |
const deepgram = new Deepgram(deepgramApiKey); | |
app.get('/', (req, res) => { | |
res.send(` | |
<h2>Sound transcript</h2> | |
<form action="/upload" enctype="multipart/form-data" method="post"> | |
<div>Recording: <input type="file" name="recording" multiple="multiple" /></div> | |
<p></p> | |
<input type="submit" value="Process" /> | |
</form> | |
`); | |
}); | |
app.post('/upload', (req, res, next) => { | |
const form = formidable({ multiples: true }); | |
form.parse(req, (err, fields, files) => { | |
if (err) { | |
next(err); | |
return; | |
} | |
source = { | |
buffer: fs.readFileSync(files.recording.filepath), | |
mimetype: files.recording.mimetype | |
} | |
deepgram.transcription.preRecorded( | |
source, | |
{ | |
punctuate: true | |
} | |
) | |
.then((response) => { | |
console.dir(response, {depth: null}); | |
res.send(response.results.channels[0].alternatives[0].transcript, { depth: null }); | |
}) | |
.catch((err) => { | |
console.log(err); | |
}) | |
}); | |
}); | |
app.listen(3000, () => { | |
console.log('Server listening on http://localhost:3000 ...'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment