forked from Furtsy/telegram-bot-ai
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tts.js
29 lines (29 loc) · 888 Bytes
/
tts.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
var url = require('url');
var host = 'https://translate.google.com'
module.exports = function (text, lang, speed) {
if (typeof text !== 'string' || text.length === 0) {
throw new TypeError('text should be a string');
}
if (text.length > 200) {
throw new RangeError('text length (' + text.length + ') should be less than 200 characters');
}
if (typeof lang !== 'undefined' && (typeof lang !== 'string' || lang.length === 0)) {
throw new TypeError('lang should be a string');
}
if (typeof speed !== 'undefined' && typeof speed !== 'number') {
throw new TypeError('speed should be a number');
}
return host + '/translate_tts' + url.format({
query: {
ie: 'UTF-8',
q: text,
tl: lang || 'tr',
total: 1,
idx: 0,
textlen: text.length,
client: 'tw-ob',
prev: 'input',
ttsspeed: speed || 1
}
});
};