-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathytToText.js
90 lines (68 loc) · 2.57 KB
/
ytToText.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const fs = require('fs')
const YoutubeMp3Downloader = require('youtube-mp3-downloader')
const { Deepgram } = require('@deepgram/sdk')
const ffmpeg = require('ffmpeg-static')
const deepgramApiKey = 'a3e2620e24915546bd4256b9decbe0c7ba1cc132';
const deepgram = new Deepgram(deepgramApiKey)
/*
const YD = new YoutubeMp3Downloader({
ffmpegPath: ffmpeg,
outputPath: './',
youtubeVideoQuality: 'highestaudio',
queueParallelism: 1
})
*/
async function toText(id) {
let promise = new Promise((resolve, reject) => {
try {
const ytID = id;
//const ytID = 'uBp6qjJtKC0'
const YD = new YoutubeMp3Downloader({
ffmpegPath: ffmpeg,
outputPath: './',
youtubeVideoQuality: 'highestaudio',
queueParallelism: 1
})
YD.download(ytID)
YD.on('error', err => {
console.log("something goofed");
console.log(err)
reject("Download error");
})
YD.on('progress', data => {
console.log(data.progress.percentage + '% downloaded')
})
YD.on('finished', async (err, video) => {
try {
const videoFileName = video.file
console.log(`Downloaded ${videoFileName}`)
const file = {
buffer: fs.readFileSync(videoFileName),
mimetype: 'audio/mp3'
}
const options = {
punctuate: true,
utterances: true
}
const result = await deepgram.transcription.preRecorded(file, options).catch(e => console.log(e))
const transcript = result.results.channels[0].alternatives[0].transcript
//console.log(JSON.stringify(result, undefined, 4));
const utterances = result.results.utterances;
console.log(":)")
resolve(JSON.stringify(utterances));
} catch (error) {
console.log("other");
console.log(error)
reject("other")
}
})
} catch (err) {
console.log("other2");
console.log(err)
reject("other2")
}
})
return promise;
}
module.exports = toText
//Test if the id doesnt break everything