-
Notifications
You must be signed in to change notification settings - Fork 0
/
wavenet-server.js
31 lines (27 loc) · 965 Bytes
/
wavenet-server.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
class WAVENET_CLIENT {
constructor(apikey, host = 'https://wns.hugocastaneda.fr') {
this.apikey = apikey
this.host = host
}
async __make_call(endpoint, data) {
let options = { method: 'GET', headers: { 'wns-apikey': this.apikey } }
if (data) {
options.method = 'POST'
options.headers['content-type'] = 'application/json'
options.body = JSON.stringify(data)
}
const url = `${this.host}/api/${endpoint}`
console.log(url, options)
return await (await fetch(url, options)).json()
}
get_voices() {
return this.__make_call('voices')
}
get_quotas() {
return this.__make_call('quotas')
}
async tts(text, voice_name, lang = 'fr-FR', force_translate = false) {
const file_name = await this.__make_call('tts', { text, voice_name, lang, force_translate })
return `${this.host}/sounds/${file_name}`
}
}