Created
January 14, 2022 13:21
-
-
Save Aniket-508/2833182b264f7abe5d631dbad413cd7e to your computer and use it in GitHub Desktop.
Node js script to transcribe the song from soundcloud
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
// Please install the required packages | |
const scdl = require('soundcloud-downloader').default | |
const fs = require('fs') | |
const SOUNDCLOUD_URL = '(Eg: https://m.soundcloud.com/fahad-syed-1/tightrope-x-mashup)' | |
scdl.download(SOUNDCLOUD_URL).then(stream => stream.pipe(fs.createWriteStream('audio.mp3'))) | |
const { Deepgram } = require('@deepgram/sdk'); | |
const deepgramApiKey = 'API_key'; | |
const pathToFile = 'audio.mp3'; | |
// Initializes the Deepgram SDK | |
const deepgram = new Deepgram(deepgramApiKey); | |
// Creates a websocket connection to Deepgram | |
const deepgramSocket = deepgram.transcription.live({ punctuate: true }); | |
// Listen for the connection to open and begin sending | |
deepgramSocket.addListener('open', () => { | |
console.log('Connection Opened!'); | |
// Grab your audio file | |
const fs = require('fs'); | |
const contents = fs.readFileSync(pathToFile); | |
// Send the audio to the Deepgram API in chunks of 1000 bytes | |
const chunk_size = 1000; | |
for (i = 0; i < contents.length; i+= chunk_size) { | |
const slice = contents.slice(i, i + chunk_size); | |
deepgramSocket.send(slice); | |
} | |
// Close the websocket connection | |
deepgramSocket.finish(); | |
}); | |
// Listen for the connection to close | |
deepgramSocket.addListener('close', () => { | |
console.log('Connection closed.'); | |
}) | |
// Receive transcriptions based on sent streams and write them to the console | |
deepgramSocket.addListener('transcriptReceived', (transcription) => { | |
console.dir(transcription, { depth: null }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment