-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
67 lines (58 loc) · 1.88 KB
/
index.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
const sanscript = require("sanscriptjs");
const googleTTS = require("google-tts-api");
const fs = require("fs");
let tts = {};
let getQuery = (text, script) => {
if (script) {
return (script != "kannada" ? sanscript.t(text, script, "kannada") : text)
} else {
throw console.error("ERROR: Must specify the script of the query.");
}
}
tts.saveFile = (text, options) => {
googleTTS.getAudioBase64(getQuery(text, options.script), {
lang: 'kn',
slow: options.slow ?? false,
host: 'https://translate.google.com',
timeout: 10000,
}).then(response => {
fs.writeFileSync(options.fileName ?? "audio.mp3", Buffer.from(response, 'base64'))
}).catch(console.error);
}
tts.getBase64 = (text, options) => {
googleTTS.getAudioBase64(getQuery(text, options.script), {
lang: 'kn',
slow: options.slow ?? false,
host: 'https://translate.google.com',
timeout: 10000,
}).then(response => {
return response;
}).catch(console.error);
}
tts.getURL = (text, options) => {
return googleTTS.getAudioUrl(getQuery(text, options.script), {
lang: 'kn',
slow: options.slow ?? false,
host: 'https://translate.google.com',
})
}
tts.getAllBase64 = (text, options) => {
googleTTS.getAllAudioBase64(getQuery(text, options.script), {
lang: 'kn',
slow: options.slow ?? false,
host: 'https://translate.google.com',
timeout: 10000,
splitPunct: options.splitPunct ?? "॥.?"
}).then(response => {
return response;
}).catch(console.error);
}
tts.getAllURLs = (text, options) => {
return googleTTS.getAllAudioUrls(getQuery(text, options.script), {
lang: 'kn',
slow: options.slow ?? false,
host: 'https://translate.google.com',
splitPunct: options.splitPunct ?? "॥.?"
})
}
module.exports = tts;