580 lines
24 KiB
JavaScript
580 lines
24 KiB
JavaScript
require('../connections/mysql-server');
|
|
require('../helpers/CheckToken');
|
|
const express = require('express');
|
|
const router = express.Router();
|
|
const bodyParser = require('body-parser');
|
|
const { debug } = require('console');
|
|
|
|
const apikeyWatson = process.env.IBMTTS_APIKEY;
|
|
const apiurlServiceWatson = process.env.IBMTTS_SERVICEURL;
|
|
|
|
router.use(bodyParser.urlencoded({ extended: true }));
|
|
router.use(bodyParser.json());
|
|
|
|
var routes = function () {
|
|
|
|
//#region CHARACTERSCONVERSATION
|
|
router.get('/getAllCharConv', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersConversation;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getCharacterconversation/:idcharactersConversation', verifyJWT, (req, res) => {
|
|
const idcharactersConversation = parseInt(req.params.idcharactersConversation);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersConversation
|
|
where idcharactersConversation = ${idcharactersConversation};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertCharConv', verifyJWT, (req, res) => {
|
|
const idcharactersConversation = parseInt(req.body.idcharactersConversation);
|
|
const description = req.body.description;
|
|
const idcharacters_1 = parseInt(req.body.idcharacters_1);
|
|
const idcharacters_2 = parseInt(req.body.idcharacters_2);
|
|
const idcharactersBackground = parseInt(req.body.idcharactersBackground);
|
|
const idcharactersFonts = parseInt(req.body.idcharactersFonts);
|
|
execSQLQuery(`INSERT INTO charactersConversation (description, idcharacters_1, idcharacters_2, idcharactersBackground, idcharactersFonts)
|
|
VALUES (?, ?, ?, ?, ?);`, res, req.originalUrl, [description, idcharacters_1, idcharacters_2, idcharactersBackground, idcharactersFonts]);
|
|
});
|
|
|
|
router.patch('/updateCharConv', verifyJWT, (req, res) => {
|
|
const idcharactersConversation = parseInt(req.body.idcharactersConversation);
|
|
const description = req.body.description;
|
|
const idcharacters_1 = parseInt(req.body.idcharacters_1);
|
|
const idcharacters_2 = parseInt(req.body.idcharacters_2);
|
|
const idcharactersBackground = parseInt(req.body.idcharactersBackground);
|
|
const idcharactersFonts = parseInt(req.body.idcharactersFonts);
|
|
execSQLQuery(`UPDATE charactersConversation SET
|
|
description = ?,
|
|
idcharacters_1 = ?,
|
|
idcharacters_2 = ?,
|
|
idcharactersBackground = ?,
|
|
idcharactersFonts = ?
|
|
WHERE idcharactersConversation = ?;`, res, req.originalUrl, [description, idcharacters_1, idcharacters_2, idcharactersBackground, idcharactersFonts, idcharactersConversation]);
|
|
});
|
|
|
|
router.get('/getCharConvDetails/:idcharactersConversation', verifyJWT, (req, res) => {
|
|
const idcharactersConversation = parseInt(req.params.idcharactersConversation);
|
|
execSQLQuery(`select
|
|
cc.idcharactersConversation,
|
|
cc.description,
|
|
cp.seconds,
|
|
cp.speed,
|
|
cc.idcharacters_1,
|
|
(select ch1.description from characters ch1 where ch1.idcharacters = cc.idcharacters_1) as 'character_1',
|
|
cc.idcharacters_2,
|
|
(select ch2.description from characters ch2 where ch2.idcharacters = cc.idcharacters_2) as 'character_2',
|
|
cc.idcharactersBackground,
|
|
cb.description as 'background',
|
|
cb.ext as 'backgroundExt',
|
|
cc.idcharactersFonts,
|
|
cf.description as 'font',
|
|
cp.fontSize,
|
|
cp.fontColor,
|
|
cp.idcharactersPhrases,
|
|
cp.charactertalking,
|
|
cp.idcharactersBaloons,
|
|
ba.description as 'baloon',
|
|
ba.ext as 'baloonExt',
|
|
cp.baloonColor,
|
|
cp.phrase,
|
|
cp.idcharactersFeelings_1,
|
|
(select cf1.description from charactersFeelings cf1 where cf1.idcharactersFeelings = cp.idcharactersFeelings_1) as 'characterFeeling_1',
|
|
cp.idcharactersFeelings_2,
|
|
(select cf2.description from charactersFeelings cf2 where cf2.idcharactersFeelings = cp.idcharactersFeelings_2) as 'characterFeeling_2',
|
|
cp.sintetizevoice,
|
|
cp.idcharactersVoices,
|
|
(select cv.description from charactersVoices cv where cv.idcharactersVoices = cp.idcharactersVoices) as 'voicename',
|
|
(select cv.voice from charactersVoices cv where cv.idcharactersVoices = cp.idcharactersVoices) as 'voice',
|
|
cp.idcharactersTransitions,
|
|
ct.description as 'transition',
|
|
ct.ext as 'transitionExt',
|
|
cp.ordem
|
|
from charactersConversation cc
|
|
left join charactersBackground cb on cb.idcharactersBackground = cc.idcharactersBackground
|
|
left join charactersFonts cf on cf.idcharactersFonts = cc.idcharactersFonts
|
|
left join charactersPhrases cp on cp.idcharactersConversation = cc.idcharactersConversation
|
|
left join charactersBaloons ba on ba.idcharactersBaloons = cp.idcharactersBaloons
|
|
left join charactersTransitions ct on ct.idcharactersTransitions = cp.idcharactersTransitions
|
|
where cc.idcharactersConversation = ${idcharactersConversation}
|
|
order by cp.ordem asc;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.delete('/deleteCharacterconversation/:idcharactersConversation', verifyJWT, (req, res) => {
|
|
const idcharactersConversation = parseInt(req.params.idcharactersConversation);
|
|
execSQLQuery(`delete from charactersConversation
|
|
where idcharactersConversation = ${idcharactersConversation};`, res, req.originalUrl);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region CHARACTERS
|
|
router.get('/getAllCharacters', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from characters;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getCharacter/:idcharacters', verifyJWT, (req, res) => {
|
|
const idcharacters = parseInt(req.params.idcharacters);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from characters
|
|
where idcharacters = ${idcharacters};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertCharacter', verifyJWT, (req, res) => {
|
|
const idcharacters = parseInt(req.body.idcharacters);
|
|
const description = req.body.description;
|
|
execSQLQuery(`INSERT INTO characters (description)
|
|
VALUES (?);`, res, req.originalUrl, [description]);
|
|
});
|
|
|
|
router.patch('/updateCharacter', verifyJWT, (req, res) => {
|
|
const idcharacters = parseInt(req.body.idcharacters);
|
|
const description = req.body.description;
|
|
execSQLQuery(`UPDATE characters SET
|
|
description = ?
|
|
WHERE idcharacters = ?;`, res, req.originalUrl, [description, idcharacters]);
|
|
});
|
|
|
|
router.delete('/deleteCharacter/:idcharacters', verifyJWT, (req, res) => {
|
|
const idcharacters = parseInt(req.params.idcharacters);
|
|
execSQLQuery(`delete from characters
|
|
where idcharacters = ${idcharacters};`, res, req.originalUrl);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region BACKGROUNDS
|
|
router.get('/getAllBackgrounds', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersBackground;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getBackground/:idcharactersBackground', verifyJWT, (req, res) => {
|
|
const idcharactersBackground = parseInt(req.params.idcharactersBackground);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersBackground
|
|
where idcharactersBackground = ${idcharactersBackground};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertBackground', verifyJWT, (req, res) => {
|
|
const idcharactersBackground = parseInt(req.body.idcharactersBackground);
|
|
const description = req.body.description;
|
|
const ext = req.body.ext;
|
|
execSQLQuery(`INSERT INTO charactersBackground (description, ext)
|
|
VALUES (?, ?);`, res, req.originalUrl, [description, ext]);
|
|
});
|
|
|
|
router.patch('/updateBackground', verifyJWT, (req, res) => {
|
|
const idcharactersBackground = parseInt(req.body.idcharactersBackground);
|
|
const description = req.body.description;
|
|
const ext = req.body.ext;
|
|
execSQLQuery(`UPDATE charactersBackground SET
|
|
description = ?,
|
|
ext = ?
|
|
WHERE idcharactersBackground = ?;`, res, req.originalUrl, [description, ext, idcharactersBackground]);
|
|
});
|
|
|
|
router.delete('/deleteBackground/:idcharactersBackground', verifyJWT, (req, res) => {
|
|
const idcharactersBackground = parseInt(req.params.idcharactersBackground);
|
|
execSQLQuery(`delete from charactersBackground
|
|
where idcharactersBackground = ${idcharactersBackground};`, res, req.originalUrl);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region FEELINGS
|
|
router.get('/getAllFeelings', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersFeelings;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getFeeling/:idcharactersFeelings', verifyJWT, (req, res) => {
|
|
const idcharactersFeelings = parseInt(req.params.idcharactersFeelings);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersFeelings
|
|
where idcharactersFeelings = ${idcharactersFeelings};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertFeeling', verifyJWT, (req, res) => {
|
|
const idcharactersFeelings = parseInt(req.body.idcharactersFeelings);
|
|
const description = req.body.description;
|
|
execSQLQuery(`INSERT INTO charactersFeelings (description)
|
|
VALUES (?);`, res, req.originalUrl, [description]);
|
|
});
|
|
|
|
router.patch('/updateFeeling', verifyJWT, (req, res) => {
|
|
const idcharactersFeelings = parseInt(req.body.idcharactersFeelings);
|
|
const description = req.body.description;
|
|
execSQLQuery(`UPDATE charactersFeelings SET
|
|
description = ?
|
|
WHERE idcharactersFeelings = ?;`, res, req.originalUrl, [description, idcharactersFeelings]);
|
|
});
|
|
|
|
router.delete('/deleteFeeling/:idcharactersFeelings', verifyJWT, (req, res) => {
|
|
const idcharactersFeelings = parseInt(req.params.idcharactersFeelings);
|
|
execSQLQuery(`delete from charactersFeelings
|
|
where idcharactersFeelings = ${idcharactersFeelings};`, res, req.originalUrl);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region FONTS
|
|
router.get('/getAllFonts', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersFonts;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getFont/:idcharactersFonts', verifyJWT, (req, res) => {
|
|
const idcharactersFonts = parseInt(req.params.idcharactersFonts);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersFonts
|
|
where idcharactersFonts = ${idcharactersFonts};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertFont', verifyJWT, (req, res) => {
|
|
const idcharactersFonts = parseInt(req.body.idcharactersFonts);
|
|
const description = req.body.description;
|
|
execSQLQuery(`INSERT INTO charactersFonts (description)
|
|
VALUES (?);`, res, req.originalUrl, [description]);
|
|
});
|
|
|
|
router.patch('/updateFont', verifyJWT, (req, res) => {
|
|
const idcharactersFonts = parseInt(req.body.idcharactersFonts);
|
|
const description = req.body.description;
|
|
execSQLQuery(`UPDATE charactersFonts SET
|
|
description = ?
|
|
WHERE idcharactersFonts = ?;`, res, req.originalUrl, [description, idcharactersFonts]);
|
|
});
|
|
|
|
router.delete('/deleteFont/:idcharactersFonts', verifyJWT, (req, res) => {
|
|
const idcharactersFonts = parseInt(req.params.idcharactersFonts);
|
|
execSQLQuery(`delete from charactersFonts
|
|
where idcharactersFonts = ${idcharactersFonts};`, res, req.originalUrl);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region VOICES
|
|
router.get('/getAllVoices', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersVoices;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getVoice/:idcharactersVoices', verifyJWT, (req, res) => {
|
|
const idcharactersVoices = parseInt(req.params.idcharactersVoices);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersVoices
|
|
where idcharactersVoices = ${idcharactersVoices};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertVoice', verifyJWT, (req, res) => {
|
|
const idcharactersVoices = parseInt(req.body.idcharactersVoices);
|
|
const description = req.body.description;
|
|
execSQLQuery(`INSERT INTO charactersVoices (description)
|
|
VALUES (?);`, res, req.originalUrl, [description]);
|
|
});
|
|
|
|
router.patch('/updateVoice', verifyJWT, (req, res) => {
|
|
const idcharactersVoices = parseInt(req.body.idcharactersVoices);
|
|
const description = req.body.description;
|
|
execSQLQuery(`UPDATE charactersVoices SET
|
|
description = ?
|
|
WHERE idcharactersVoices = ?;`, res, req.originalUrl, [description, idcharactersVoices]);
|
|
});
|
|
|
|
router.delete('/deleteVoice/:idcharactersVoices', verifyJWT, (req, res) => {
|
|
const idcharactersVoices = parseInt(req.params.idcharactersVoices);
|
|
execSQLQuery(`delete from charactersVoices
|
|
where idcharactersVoices = ${idcharactersVoices};`, res, req.originalUrl);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region BALOONS
|
|
router.get('/getAllBaloons', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersBaloons;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getBaloon/:idcharactersBaloons', verifyJWT, (req, res) => {
|
|
const idcharactersBaloons = parseInt(req.params.idcharactersBaloons);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersBaloons
|
|
where idcharactersBaloons = ${idcharactersBaloons};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertBaloon', verifyJWT, (req, res) => {
|
|
const idcharactersBaloons = parseInt(req.body.idcharactersBaloons);
|
|
const description = req.body.description;
|
|
const ext = req.body.ext;
|
|
execSQLQuery(`INSERT INTO charactersBaloons (description, ext)
|
|
VALUES (?, ?);`, res, req.originalUrl, [description, ext]);
|
|
});
|
|
|
|
router.patch('/updateBaloon', verifyJWT, (req, res) => {
|
|
const idcharactersBaloons = parseInt(req.body.idcharactersBaloons);
|
|
const description = req.body.description;
|
|
const ext = req.body.ext;
|
|
execSQLQuery(`UPDATE charactersBaloons SET
|
|
description = ?,
|
|
ext = ?
|
|
WHERE idcharactersBaloons = ?;`, res, req.originalUrl, [description, ext, idcharactersBaloons]);
|
|
});
|
|
|
|
router.delete('/deleteBaloon/:idcharactersBaloons', verifyJWT, (req, res) => {
|
|
const idcharactersBaloons = parseInt(req.params.idcharactersBaloons);
|
|
execSQLQuery(`delete from charactersBaloons
|
|
where idcharactersBaloons = ${idcharactersBaloons};`, res, req.originalUrl);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region PHRASES
|
|
router.get('/getAllPhrases', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersPhrases;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getPhrase/:idcharactersPhrases', verifyJWT, (req, res) => {
|
|
const idcharactersPhrases = parseInt(req.params.idcharactersPhrases);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersPhrases
|
|
where idcharactersPhrases = ${idcharactersPhrases};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getPhrasesInConversation/:idcharactersConversation', verifyJWT, (req, res) => {
|
|
const idcharactersConversation = parseInt(req.params.idcharactersConversation);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersPhrases
|
|
where idcharactersConversation = ${idcharactersConversation}
|
|
order by ordem asc;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertPhrase', verifyJWT, (req, res) => {
|
|
const idcharactersPhrases = parseInt(req.body.idcharactersPhrases);
|
|
const idcharactersConversation = parseInt(req.body.idcharactersConversation);
|
|
const seconds = parseFloat(req.body.seconds);
|
|
const speed = req.body.speed;
|
|
const charactertalking = req.body.charactertalking;
|
|
const idcharactersBaloons = req.body.idcharactersBaloons;
|
|
const baloonColor = req.body.baloonColor;
|
|
const phrase = req.body.phrase;
|
|
const fontSize = req.body.fontSize;
|
|
const fontColor = req.body.fontColor;
|
|
const idcharactersFeelings_1 = req.body.idcharactersFeelings_1;
|
|
const idcharactersFeelings_2 = req.body.idcharactersFeelings_2;
|
|
const sintetizevoice = req.body.sintetizevoice ? 1 : 0;
|
|
const idcharactersVoices = req.body.idcharactersVoices;
|
|
const idcharactersTransitions = req.body.idcharactersTransitions;
|
|
const ordem = parseInt(req.body.ordem);
|
|
execSQLQuery(`INSERT INTO charactersPhrases (idcharactersConversation, seconds, speed, charactertalking, idcharactersBaloons, baloonColor, fontSize, fontColor, phrase, idcharactersFeelings_1, idcharactersFeelings_2, sintetizevoice, idcharactersVoices, idcharactersTransitions, ordem)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, res, req.originalUrl, [idcharactersConversation, seconds, speed, charactertalking, idcharactersBaloons, baloonColor, fontSize, fontColor, phrase, idcharactersFeelings_1, idcharactersFeelings_2, sintetizevoice, idcharactersVoices, idcharactersTransitions, ordem]);
|
|
});
|
|
|
|
router.patch('/updatePhrase', verifyJWT, (req, res) => {
|
|
const idcharactersPhrases = parseInt(req.body.idcharactersPhrases);
|
|
const idcharactersConversation = parseInt(req.body.idcharactersConversation);
|
|
const seconds = parseFloat(req.body.seconds);
|
|
const speed = parseFloat(req.body.speed);
|
|
const charactertalking = parseInt(req.body.charactertalking);
|
|
const idcharactersBaloons = parseInt(req.body.idcharactersBaloons);
|
|
const baloonColor = req.body.baloonColor;
|
|
const phrase = req.body.phrase;
|
|
const idcharactersFeelings_1 = parseInt(req.body.idcharactersFeelings_1);
|
|
const idcharactersFeelings_2 = parseInt(req.body.idcharactersFeelings_2);
|
|
const sintetizevoice = req.body.sintetizevoice ? 1 : 0;
|
|
const idcharactersVoices = parseInt(req.body.idcharactersVoices);
|
|
const idcharactersTransitions = parseInt(req.body.idcharactersTransitions);
|
|
const ordem = parseInt(req.body.ordem);
|
|
execSQLQuery(`UPDATE charactersPhrases SET
|
|
idcharactersConversation = ?,
|
|
seconds = ?,
|
|
speed = ?,
|
|
charactertalking = ?,
|
|
idcharactersBaloons = ?,
|
|
baloonColor = ?,
|
|
phrase = ?,
|
|
idcharactersFeelings_1 = ?,
|
|
idcharactersFeelings_2 = ?,
|
|
sintetizevoice = ?,
|
|
idcharactersVoices = ?,
|
|
idcharactersTransitions = ?,
|
|
ordem = ?
|
|
WHERE idcharactersPhrases = ?;`, res, req.originalUrl, [idcharactersConversation, seconds, speed, charactertalking, idcharactersBaloons, baloonColor, phrase, idcharactersFeelings_1, idcharactersFeelings_2, sintetizevoice, idcharactersVoices, idcharactersTransitions, ordem, idcharactersPhrases]);
|
|
});
|
|
|
|
router.delete('/deletePhrase/:idcharactersPhrases', verifyJWT, (req, res) => {
|
|
const idcharactersPhrases = parseInt(req.params.idcharactersPhrases);
|
|
execSQLQuery(`delete from charactersPhrases
|
|
where idcharactersPhrases = ${idcharactersPhrases};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.delete('/deletePhrasesInConversation/:idcharactersConversation', verifyJWT, (req, res) => {
|
|
const idcharactersConversation = parseInt(req.params.idcharactersConversation);
|
|
execSQLQuery(`delete from charactersPhrases
|
|
where idcharactersConversation = ${idcharactersConversation};`, res, req.originalUrl);
|
|
});
|
|
|
|
//#endregion
|
|
|
|
//#region TRANSITIONS
|
|
router.get('/getAllTransitions', verifyJWT, (req, res) => {
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersTransitions;`, res, req.originalUrl);
|
|
});
|
|
|
|
router.get('/getTransition/:idcharactersTransitions', verifyJWT, (req, res) => {
|
|
const idcharactersTransitions = parseInt(req.params.idcharactersTransitions);
|
|
execSQLQuery(`SELECT
|
|
*
|
|
from charactersTransitions
|
|
where idcharactersTransitions = ${idcharactersTransitions};`, res, req.originalUrl);
|
|
});
|
|
|
|
router.post('/insertTransition', verifyJWT, (req, res) => {
|
|
const idcharactersTransitions = parseInt(req.body.idcharactersTransitions);
|
|
const description = req.body.description;
|
|
const ext = req.body.ext;
|
|
execSQLQuery(`INSERT INTO charactersTransitions (description, ext)
|
|
VALUES (?, ?);`, res, req.originalUrl, [description, ext]);
|
|
});
|
|
|
|
router.patch('/updateTransition', verifyJWT, (req, res) => {
|
|
const idcharactersTransitions = parseInt(req.body.idcharactersTransitions);
|
|
const description = req.body.description;
|
|
const ext = req.body.ext;
|
|
execSQLQuery(`UPDATE charactersTransitions SET
|
|
description = ?,
|
|
ext = ?
|
|
WHERE idcharactersTransitions = ?;`, res, req.originalUrl, [description, ext, idcharactersTransitions]);
|
|
});
|
|
|
|
router.delete('/deleteTransition/:idcharactersTransitions', verifyJWT, (req, res) => {
|
|
const idcharactersTransitions = parseInt(req.params.idcharactersTransitions);
|
|
execSQLQuery(`delete from charactersTransitions
|
|
where idcharactersTransitions = ${idcharactersTransitions};`, res, req.originalUrl);
|
|
});
|
|
//#endregion
|
|
|
|
|
|
router.post('/tts', verifyJWT, (req, res) => {
|
|
const Texto = req.body.texto;
|
|
const Velocidade = req.body.speed;
|
|
const idzoevoices = req.body.idzoevoices;
|
|
const PollyVoice = req.body.PollyVoice;
|
|
const NomeArquivo = "sintetize.mp3";
|
|
const shell = require('shelljs');
|
|
mysqlConnection.query(`SELECT cf.TTSmode, (SELECT voice FROM zoevoices WHERE idzoevoices = 1) as voice FROM config cf;`, function (error, Config, fields) {
|
|
const TTSMode = Config[0]['TTSmode'];
|
|
let Voz = Config[0]['voice'];
|
|
if (PollyVoice != "")
|
|
Voz = PollyVoice;
|
|
|
|
if (TTSMode == 3) { // WIDEO
|
|
const request = require('request');
|
|
var options = {
|
|
uri: 'https://texttospeechapi.wideo.co/api/wideo-text-to-speech',
|
|
method: 'POST',
|
|
json: { "data":{"text":Texto,"speed":Velocidade,"voice":Voz} }
|
|
};
|
|
request(options, function (error, response, body) {
|
|
if (!error && response.statusCode == 200) {
|
|
shell.exec(`wget "${response['body']['result']['url']}" -O ${Variables("src_media")}/audiosZoe/${NomeArquivo} -q;`, function(Sucesso) {
|
|
EnviarAudio(NomeArquivo, true, error, res, req);
|
|
});
|
|
}
|
|
else {
|
|
console.log(error);
|
|
EnviarAudio(NomeArquivo, false, error, res, req);
|
|
}
|
|
});
|
|
}
|
|
else if (TTSMode == 4) { // AMAZON POLLY
|
|
shell.exec(`python ${Variables('src_media')}assets/polly_service.py "${Texto}" "${Variables('src_media')}/audiosZoe/${NomeArquivo}" "${Voz}"`, function(Sucesso) {
|
|
EnviarAudio(NomeArquivo, true, null, res, req);
|
|
});
|
|
}
|
|
else if (TTSMode == 6) { // WATSON IBM
|
|
const fs = require('fs');
|
|
const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
|
|
const { IamAuthenticator } = require('ibm-watson/auth');
|
|
|
|
const textToSpeech = new TextToSpeechV1({
|
|
authenticator: new IamAuthenticator({ apikey: apikeyWatson }),
|
|
serviceUrl: apiurlServiceWatson
|
|
});
|
|
|
|
const params = {
|
|
text: Texto,
|
|
voice: Voz,
|
|
accept: 'audio/wav'
|
|
};
|
|
console.log("A" + " " + NomeArquivo);
|
|
textToSpeech.synthesize(params).then(response => {
|
|
const audio = response.result;
|
|
return textToSpeech.repairWavHeaderStream(audio);
|
|
}).then(repairedFile => {
|
|
fs.writeFileSync(`${Variables("src_media")}audiosZoe/${NomeArquivo}`, repairedFile);
|
|
console.log('audio.wav written with a corrected wav header');
|
|
//EnviarAudio(NomeArquivo.replace(".mp3", ".wav"), true, null, res, req);
|
|
shell.exec(`ffmpeg -loglevel panic -i ${Variables("src_media")}audiosZoe/${NomeArquivo} ${Variables("src_media")}audiosZoe/${NomeArquivo} -o`, function(Sucesso) {
|
|
EnviarAudio(NomeArquivo, true, null, res, req);
|
|
});
|
|
}).catch(err => {
|
|
console.log(err);
|
|
});
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
function EnviarAudio(NomeArquivo, Sucesso, error, res, req) {
|
|
if (Sucesso) {
|
|
console.log(new Date().toUTCString() + " - " + req.originalUrl + " success 200");
|
|
res.send(JSON.stringify({
|
|
"status": 200,
|
|
"error": error,
|
|
"url_audio": "audiosZoe/" + NomeArquivo,
|
|
}));
|
|
}
|
|
else {
|
|
console.log(new Date().toUTCString() + " - " + req.originalUrl + " error 500");
|
|
res.send(JSON.stringify({
|
|
"status": 500,
|
|
"error": error,
|
|
"url_audio": null,
|
|
}));
|
|
}
|
|
}
|
|
|
|
router.get('/SalvarAudioSintetizado/:nome', verifyJWT, (req, res) => {
|
|
const NomeArquivo = req.params.nome;
|
|
const shell = require('shelljs');
|
|
shell.exec(`cp ${Variables("src_media")}/audiosZoe/sintetize.mp3 ${Variables("src_media")}/zoeGamesResources/audios/${NomeArquivo}.mp3`, function(Sucesso) {
|
|
res.send(true);
|
|
});
|
|
});
|
|
|
|
return router;
|
|
};
|
|
|
|
module.exports = routes; |