generated from pot-app/pot-app-tts-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
23 lines (22 loc) · 765 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
async function tts(text, lang, options = {}) {
const { config, utils } = options;
const { tauriFetch } = utils;
let { requestPath } = config;
if (requestPath === undefined || requestPath.length === 0) {
requestPath = "lingva.pot-app.com"
}
if (!requestPath.startsWith('http')) {
requestPath = 'https://' + requestPath;
}
const res = await tauriFetch(`${requestPath}/api/v1/audio/${lang}/${encodeURIComponent(text)}`);
if (res.ok) {
let result = res.data;
if (result['audio']) {
return result['audio'];
} else {
throw JSON.stringify(result);
}
} else {
throw `Http Request Error\nHttp Status: ${res.status}\n${JSON.stringify(res.data)}`;
}
}