latest_fix_read_live_files_from_/dev/shm/1.txt_file__to_lip_sink_with_external_tts
This commit is contained in:
23
package-lock.json
generated
23
package-lock.json
generated
@@ -9,7 +9,8 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^5.2.1"
|
"express": "^5.2.1",
|
||||||
|
"ws": "^8.20.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/accepts": {
|
"node_modules/accepts": {
|
||||||
@@ -773,6 +774,26 @@
|
|||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
|
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
|
||||||
|
},
|
||||||
|
"node_modules/ws": {
|
||||||
|
"version": "8.20.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.20.1.tgz",
|
||||||
|
"integrity": "sha512-It4dO0K5v//JtTXuPkfEOaI3uUN87iYPnqo/ZzqCoG3g8uhA66QUMs/SrM0YK7/NAu+r4LMh/9dq2A7k+rHs+w==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"bufferutil": "^4.0.1",
|
||||||
|
"utf-8-validate": ">=5.0.2"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"bufferutil": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"utf-8-validate": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^5.2.1"
|
"express": "^5.2.1",
|
||||||
|
"ws": "^8.20.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,82 @@ let interval = setInterval(() => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function real_lipsing(value){
|
||||||
|
readShm('/handler1').then(value => console.log(value));
|
||||||
|
|
||||||
|
// let value = 0;
|
||||||
|
let slider = document.getElementById("paramMouthOpenYRange");
|
||||||
|
// Set the slider value
|
||||||
|
slider.value = value.toFixed(2);
|
||||||
|
|
||||||
|
// Trigger input event (if something listens to slider)
|
||||||
|
slider.dispatchEvent(new Event('input'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function readShm(endpoint) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const ws = new WebSocket(`ws://localhost:3000${endpoint}`);
|
||||||
|
ws.onmessage = (event) => {
|
||||||
|
resolve(event.data);
|
||||||
|
ws.close();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Usage:
|
||||||
|
// const value = await readShm('/handler1');
|
||||||
|
// console.log(value);
|
||||||
|
|
||||||
|
|
||||||
|
async function real_lipsing_from_backend_web_socket(){
|
||||||
|
let value = await readShm('/handler1');
|
||||||
|
console.log(value);
|
||||||
|
value = parseInt(value);
|
||||||
|
if (isNaN(value)) { value = 0; alert('WebSocket returned non-integer, defaulting to 0'); }
|
||||||
|
|
||||||
|
// let value = 0;
|
||||||
|
let slider = document.getElementById("paramMouthOpenYRange");
|
||||||
|
// Set the slider value
|
||||||
|
slider.value = value.toFixed(2);
|
||||||
|
|
||||||
|
// Trigger input event (if something listens to slider)
|
||||||
|
slider.dispatchEvent(new Event('input'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function start_lipsync_websocket() {
|
||||||
|
const ws = new WebSocket(`ws://localhost:3000/handler1`);
|
||||||
|
|
||||||
|
ws.onmessage = (event) => {
|
||||||
|
let value = parseFloat(event.data);
|
||||||
|
if (isNaN(value)) { value = 0.0; }
|
||||||
|
|
||||||
|
let slider = document.getElementById("paramMouthOpenYRange");
|
||||||
|
slider.value = value.toFixed(2);
|
||||||
|
slider.dispatchEvent(new Event('input'));
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onclose = () => {
|
||||||
|
console.log('WebSocket closed, reconnecting...');
|
||||||
|
setTimeout(start_lipsync_websocket, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onerror = (err) => {
|
||||||
|
console.log('WebSocket error', err);
|
||||||
|
ws.close();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
start_lipsync_websocket();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function drag_body_on_y_axis(delay){
|
async function drag_body_on_y_axis(delay){
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
server copy.js
Normal file
11
server copy.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const PORT = 3000;
|
||||||
|
|
||||||
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`Server running at http://localhost:${PORT}`);
|
||||||
|
});
|
||||||
39
server.js
39
server.js
@@ -1,11 +1,48 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const http = require('http');
|
||||||
|
const WebSocket = require('ws');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3000;
|
const PORT = 3000;
|
||||||
|
|
||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
const server = http.createServer(app);
|
||||||
|
const wss = new WebSocket.Server({ server });
|
||||||
|
|
||||||
|
wss.on('connection', (ws, req) => {
|
||||||
|
const endpoint = req.url;
|
||||||
|
|
||||||
|
if (endpoint === '/handler1') {
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
try {
|
||||||
|
const data = fs.readFileSync('/dev/shm/1.txt', 'utf8').trim();
|
||||||
|
ws.send(data);
|
||||||
|
} catch (e) {
|
||||||
|
ws.send('0');
|
||||||
|
}
|
||||||
|
}, 50); // sends every 50ms = 20 times per second
|
||||||
|
|
||||||
|
ws.on('close', () => {
|
||||||
|
clearInterval(interval); // cleanup when client disconnects
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (endpoint === '/handler2') {
|
||||||
|
// const interval = setInterval(() => {
|
||||||
|
// try {
|
||||||
|
// const data = fs.readFileSync('/dev/shm/2.txt', 'utf8').trim();
|
||||||
|
// ws.send(data);
|
||||||
|
// } catch (e) {
|
||||||
|
// ws.send('0');
|
||||||
|
// }
|
||||||
|
// }, 50);
|
||||||
|
// ws.on('close', () => clearInterval(interval));
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(PORT, () => {
|
||||||
console.log(`Server running at http://localhost:${PORT}`);
|
console.log(`Server running at http://localhost:${PORT}`);
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user