-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
121 lines (98 loc) · 4.23 KB
/
index.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
const socketToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbiI6IjZBQkFDODM1NEZFMjVCOTUxQkZCIiwicmVhZF9vbmx5Ijp0cnVlLCJwcmV2ZW50X21hc3RlciI6dHJ1ZSwidHdpdGNoX2lkIjoiNzExOTYwMjQzIn0.GYjFRUaMuG2f9rcvI7uztYlFT-0X8Q3peYhQtJ8IIvQ'; //Socket token from /socket/token end point
const FakeYouURL = 'https://api.fakeyou.com/tts/inference'
const io = require('socket.io-client');
const { randomUUID } = require("crypto");
const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
const { createWriteStream } = require("fs");
const { randomBytes } = require("crypto");
const { pipeline } = require("stream");
const { promisify } = require("util");
const { unlink } = require("fs");
var voice = 'TM:7wbtjphx8h8v';
const { requestSpeech, getVoiceList } = require("C:\\Users\\lolt0\\Desktop\\Streamlabs test project\\fakeYou.js");
const { fakeYouToken } = 'SAPI:FTK789_6096133E1D79D6FB'
const streamlabs = io(`https://sockets.streamlabs.com?token=${socketToken}`, {transports: ['websocket']});
console.log('Fetching')
streamlabs.on('connect', () => { console.log('Connection To Server Successful...');});
streamlabs.on('event', eventData => {
if(eventData.for === 'twitch_account' && eventData.type == 'follow'){
console.log('New follower:');
var followobj = eventData.message;
var followname = followobj[0].name;
console.log(followname);
console.log(followobj);
console.log('hi');
}
if(eventData.for === 'twitch_account' && eventData.type == 'subscription'){
var donobj = eventData.message;
var dononame = donobj[0].name;
var donoamo = donobj[0].amount;
var donomessage = donobj[0].message;
var message = donomessage;
console.log(message);
console.log(voice)
function requestSpeechFile(voice, message) {
return new Promise(async(resolve, reject) => {
// Launch speech request and poll until completion
const url = await requestSpeech(voice, message).catch(reject);
if (!url) return;
const response = await fetch(url).catch(error => {
reject(`HTTP error! ${error.name}`);
console.error(error);
});
if (!response.ok) return;
// Generate random temporary filename to avoid overwriting other recordings
const filePath = `./${randomBytes(48).toString("hex")}.wav`;
const streamPipeline = promisify(pipeline);
await streamPipeline(response.body, createWriteStream(filePath)).then(() => {
resolve(filePath);
}).catch(error => {
if (!error) return;
reject("Failed to write file!");
console.error(error);
});
});
}
requestSpeechFile(voice, message).then(async(filePath) => {
console.log('its working')
// Send temporary file in new message to avoid 15 minute interaction expiry time
}).catch(console.error);
}
if(eventData.for === 'streamlabs' && eventData.type == 'donation'){
var donobj = eventData.message;
var dononame = donobj[0].name;
var donoamo = donobj[0].amount;
var donomessage = donobj[0].message;
var message = donomessage;
console.log(message);
console.log(voice)
function requestSpeechFile(voice, message) {
return new Promise(async(resolve, reject) => {
// Launch speech request and poll until completion
const url = await requestSpeech(voice, message).catch(reject);
if (!url) return;
const response = await fetch(url).catch(error => {
reject(`HTTP error! ${error.name}`);
console.error(error);
});
if (!response.ok) return;
// Generate random temporary filename to avoid overwriting other recordings
const filePath = `./${randomBytes(48).toString("hex")}.wav`;
console.log('tesdting')
const streamPipeline = promisify(pipeline);
await streamPipeline(response.body, createWriteStream(filePath)).then(() => {
resolve(filePath);
}).catch(error => {
if (!error) return;
reject("Failed to write file!");
console.error(error);
});
});
}
requestSpeechFile(voice, message).then(async(filePath) => {
console.log('its working?')
// Send temporary file in new message to avoid 15 minute interaction expiry time
console.log('hi')
}).catch(console.error);
};
});