-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
166 lines (136 loc) · 5.92 KB
/
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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//express for api
import express from 'express';
import cors from 'cors';
const app = express();
//use cors for cross origin problems, serve json and serve static files from the audio folder
app.use(cors(), express.json(),express.static('audio', {etag: false, maxAge: 1000}));
//env variables
import dotenv from 'dotenv'
dotenv.config(); //add post middleware
//schedule job
import schedule from 'node-schedule'
//make api calls with axios
import axios from 'axios'
//TelegramBot
import TeleBot from 'telebot'
import audiogeneration from './utils/audiogeneration.js';
import { synthesizeSpeech, synthesizeSpeechXML } from './Azure_API.js';
app.get('/sendvoice', async function (req, res) {
const bot = new TeleBot(process.env?.TelegramBotToken || "");
//to get the channelID https://gist.github.com/mraaroncruz/e76d19f7d61d59419002db54030ebe35
bot.sendVoice(process.env?.TelegramChannelID || "", "./audio/VettelAICongrats.mp3", {caption: "Sebastian Vettel congratulates Max Verstappen on his Monaco Grand Prix Victory."});
res.send(`Voice is send in the Telegram channel`);
});
app.get('/mixaudio', async function (req, res) {
await audiogeneration.generateCoolBoardRadioEffectWithDistortion('./audio/stock/apivoiceXML.mp3');
res.send(`Audio mixed with ffmpeg`);
});
app.get('/createandsendradiomessage/:filename', async function (req, res) {
const filename = req.params.filename;
const bot = new TeleBot(process.env?.TelegramBotToken || "");
await audiogeneration.generateCoolBoardRadioEffect(`./audio/stock/${filename}`).then(() => {
bot.sendVoice(process.env?.TelegramChannelID || "", "./audio/speechWithCoolBoardRadioEffect.mp3", {caption: "This file is fully generated by code and didn't have any human interaction."});
console.log("finished sending message");
}).catch((err) => {console.log(err)});
res.send(`radio message created and send via telegram.`);
});
app.get('/voicefile', async function (req, res) {
// get text from query
const textFromQuery = req.query.tts?.toString();
console.log(textFromQuery);
// const text=`Hey Valterri, it is James.Fuck you`;
await synthesizeSpeechXML(textFromQuery);
//await synthesizeSpeech("This is for all the kids out there that dream of the impossible!");
res.send(`Voice is made and stored in a file`);
});
// Used for final prototype
app.get('/createvoicefile', async function (req, res) {
// get text from query
const textFromQuery = req.query.tts?.toString();
const voiceName = req.query.voice?.toString();
const notiSound = req.query.notisound.toLocaleLowerCase() == 'true' ? true : false;
const distortEffect = req.query.distortion.toLocaleLowerCase() == 'true' ? true : false;;
const backgroundVolume = req.query.backgroundvol / 100;
const backgroundTiming = req.query.backgroundtiming;
const background = req.query.background.toString();
console.log("noti: " + notiSound);
console.log("vol: " + backgroundVolume);
console.log(background);
if(voiceName == "Vettel" && textFromQuery == "Sebastian Vettel congratulates Max Verstappen on his Monaco Grand Prix Victory.")
{
res.send("VettelAICongrats.mp3")
}
else {
await synthesizeSpeechXML(textFromQuery,voiceName).then(async() => {
if(distortEffect)
{
await audiogeneration.generateCoolBoardRadioEffectWithDistortion(process.env?.PathApiVoiceXml || `./audio/apivoice.mp3`, notiSound, background, backgroundVolume).then(() => {
res.send(`preview.mp3`);
}).catch((err) => {
console.log(err);
res.status(500);
res.send("Something went wrong trying to modify the audio file.")
});
}
else {
await audiogeneration.generateCoolBoardRadioEffect(process.env?.PathApiVoiceXml || `./audio/apivoice.mp3`, notiSound, background, backgroundVolume).then(() => {
res.send(`preview.mp3`);
}).catch((err) => {
console.log(err);
res.status(500);
res.send("Something went wrong trying to modify the audio file.")
});
}
}).catch((err) => {
console.log(err);
res.status(500);
res.send("Something went wrong trying to create the audio file.")
});
}
});
app.post('/publishvoicetosocial', async function (req, res) {
//array of platform names
const fileName = req.body.filename?.toString();
const msgDesc = req.body.msgdesc?.toString();
const platforms = req.body.platforms;
if(platforms?.includes("Telegram"))
{
const bot = new TeleBot(process.env?.TelegramBotToken || "");
//to get the channelID https://gist.github.com/mraaroncruz/e76d19f7d61d59419002db54030ebe35
await bot.sendVoice(process.env?.TelegramChannelID || "", `./audio/${fileName}`, {caption: msgDesc != "" ? msgDesc : "News Flash⚡️ By RacingNews365 Tacotron🤖🌮."});
}
if(platforms?.includes("Twitter"))
{
//Do the Sharing via Social Platform API
}
if(platforms?.includes("Facebook"))
{
//Do the Sharing via Social Platform API
}
if(platforms?.includes("WhatsApp"))
{
//Do the Sharing via Social Platform API
}
if(platforms?.includes("Spotify"))
{
//Do the Sharing via Social Platform API
}
if(platforms?.includes("Snapchat"))
{
//Do the Sharing via Social Platform API
}
if(platforms?.includes("Youtube"))
{
//Do the Sharing via Social Platform API
}
if(platforms?.includes("Instagram"))
{
//Do the Sharing via Social Platform API
}
res.send("Voice file shared on socials")
});
//App listen
const port = process.env?.PORT || 4001;
app.listen(port, async() => {
console.log(`Listening on port: ${port}`);
});