-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (54 loc) · 2.31 KB
/
index.js
File metadata and controls
69 lines (54 loc) · 2.31 KB
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
// hello
const fs = require('fs');
const path = require('path');
const chalk = require('chalk')
const Leopard = require('@picovoice/leopard-node');
// env vars
require('dotenv').config();
const ACCESS_KEY = process.env.ACCESS_KEY;
const SEARCH = process.env.SEARCH ? process.env.SEARCH : path.join(__dirname, "input");
const TRANSCRIPTS = process.env.TRANSCRIPTS ? process.env.TRANSCRIPTS : path.join(__dirname, "transcripts");
const excludePaths = process.env.EXCLUDE ? process.env.EXCLUDE.split(',') : [];
// make sure folders & files exist
fs.mkdirSync(path.join(__dirname, "input"), {recursive: true});
fs.mkdirSync(TRANSCRIPTS, {recursive: true});
// helper functions
function isExcludedPath(filePath, excludePaths) {
return excludePaths.some(excludePath => {
const resolvedExcludePath = path.resolve(excludePath);
const resolvedFilePath = path.resolve(filePath);
return resolvedFilePath.startsWith(resolvedExcludePath);
});
}
function iterateDirectoryRecursively(directoryPath, excludePaths, f) {
const files = fs.readdirSync(directoryPath);
files.forEach(file => {
const filePath = path.join(directoryPath, file);
if (fs.statSync(filePath).isDirectory()) {
if (!isExcludedPath(filePath, excludePaths)) {
iterateDirectoryRecursively(filePath, excludePaths);
}
} else {
f(filePath);
console.log(filePath);
}
});
}
const rootDirectoryPath = path.dirname(require.main.filename);
console.log('Root Directory Path:', rootDirectoryPath);
console.log(chalk.blue.italic("starbucks2 stt test"));
//const accessKey = "${ACCESS_KEY}" // Obtained from the Picovoice Console (https://console.picovoice.ai/)
let handle = new Leopard(ACCESS_KEY, {enableAutomaticPunctuation: true});
iterateDirectoryRecursively(SEARCH, EXCLUDE, (fp) => {
console.log(`PROCESSING ${fp}`);
const result = handle.processFile(fp);
const o_filename = path.parse(fp).base.split(".")[0] + '.txt';
console.log(` [DEBUG] o_filename: ${o_filename}`);
const output = path.join(TRANSCRIPTS, o_filename);
const text = result.transcript;
console.log(`${text}\n ➖ \n`);
fs.writeFileSync(output, text, {encoding: 'utf8', flag:'w'});
console.log(`WROTE TO OUTPUT FILE ✅\n\n`);
});
// const result = engineInstance.processFile('${AUDIO_PATH}');
// console.log(result.transcript);