Compare commits
9 Commits
2a5f65d393
...
f14b61d7d9
| Author | SHA1 | Date |
|---|---|---|
|
|
f14b61d7d9 | |
|
|
3733b4b94f | |
|
|
528a698cf0 | |
|
|
42f3e59a42 | |
|
|
79fc30945a | |
|
|
eaef5b2205 | |
|
|
a5f9ac841f | |
|
|
d948b1743d | |
|
|
94e6f535d0 |
|
|
@ -5,6 +5,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||||
<title>GrechkaCraft: Multiplayer</title>
|
<title>GrechkaCraft: Multiplayer</title>
|
||||||
<!-- Socket.io Client -->
|
<!-- Socket.io Client -->
|
||||||
|
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
||||||
<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
|
<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
|
||||||
<link rel="stylesheet" href="style.css?v=6">
|
<link rel="stylesheet" href="style.css?v=6">
|
||||||
</head>
|
</head>
|
||||||
|
|
@ -17,6 +18,7 @@
|
||||||
<div id="stats">
|
<div id="stats">
|
||||||
<div class="row">❤️ <span id="hp">100</span> 🍗 <span id="food">100</span></div>
|
<div class="row">❤️ <span id="hp">100</span> 🍗 <span id="food">100</span></div>
|
||||||
<div class="row">🫁 <span id="o2">100</span></div>
|
<div class="row">🫁 <span id="o2">100</span></div>
|
||||||
|
<div class="row">🌡️ <span id="temp">15°C</span></div>
|
||||||
<div class="row">📍 X:<span id="sx">0</span> Y:<span id="sy">0</span></div>
|
<div class="row">📍 X:<span id="sx">0</span> Y:<span id="sy">0</span></div>
|
||||||
<div class="row">🕒 <span id="tod">День</span></div>
|
<div class="row">🕒 <span id="tod">День</span></div>
|
||||||
<div class="row">🌐 <span id="worldId" style="cursor:pointer; text-decoration:underline;" title="Нажмите, чтобы скопировать ссылку">default</span></div>
|
<div class="row">🌐 <span id="worldId" style="cursor:pointer; text-decoration:underline;" title="Нажмите, чтобы скопировать ссылку">default</span></div>
|
||||||
|
|
@ -93,6 +95,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="game.js?v=24"></script>
|
<script src="game.js?v=50"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ server {
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
# CORS for ES modules
|
|
||||||
add_header Access-Control-Allow-Origin *;
|
add_header Access-Control-Allow-Origin *;
|
||||||
|
|
||||||
location ~* \.(js|mjs|css)$ {
|
location ~* \.(js|mjs|css)$ {
|
||||||
|
|
|
||||||
128
voice-test.html
128
voice-test.html
|
|
@ -1,70 +1,94 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html><head><title>Voice Test</title></head><body>
|
<html>
|
||||||
<h1>Voice Capture Test</h1>
|
<head><title>Voice Test</title></head>
|
||||||
<button id="btn" style="padding:20px;font-size:24px;background:#2ecc71;color:#fff;border:none;border-radius:12px;cursor:pointer;">Start Mic</button>
|
<body style="background:#1a1a2e;color:#eee;font-family:monospace;padding:20px">
|
||||||
<div id="log" style="font-family:monospace;white-space:pre;margin-top:20px;"></div>
|
<h2>Voice Chat Debug</h2>
|
||||||
|
<div id="log" style="white-space:pre;overflow:auto;max-height:80vh;border:1px solid #444;padding:10px;font-size:12px"></div>
|
||||||
<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
|
<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const log = document.getElementById('log');
|
const VOICE_SERVER = 'https://voicegrech.mkn8n.ru';
|
||||||
function addLog(msg) { log.textContent += msg + '\n'; console.log(msg); }
|
const logEl = document.getElementById('log');
|
||||||
|
function log(msg) { logEl.textContent += new Date().toISOString().substr(11,8) + ' ' + msg + '\n'; logEl.scrollTop = logEl.scrollHeight; }
|
||||||
|
|
||||||
let voiceStream, audioCtx, voiceProcessor, voiceSocket;
|
log('Starting voice test...');
|
||||||
let debugCount = 0;
|
|
||||||
|
|
||||||
document.getElementById('btn').onclick = async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
addLog('1. Requesting mic...');
|
log('Requesting microphone...');
|
||||||
voiceStream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true } });
|
const stream = await navigator.mediaDevices.getUserMedia({audio: {echoCancellation:true,noiseSuppression:true,autoGainControl:true}});
|
||||||
addLog('2. Got stream: ' + voiceStream.getTracks().map(t => t.label + ' ' + t.readyState).join(', '));
|
log('Got mic stream: ' + stream.getTracks().map(t => t.label + ' ' + t.readyState).join(', '));
|
||||||
|
|
||||||
audioCtx = new AudioContext({ sampleRate: 24000 });
|
const audioCtx = new AudioContext({sampleRate: 16000});
|
||||||
if (audioCtx.state === 'suspended') await audioCtx.resume();
|
log('AudioContext: state=' + audioCtx.state + ' sampleRate=' + audioCtx.sampleRate);
|
||||||
addLog('3. AudioContext: state=' + audioCtx.state + ' sampleRate=' + audioCtx.sampleRate);
|
if (audioCtx.state === 'suspended') { await audioCtx.resume(); log('AudioContext resumed: ' + audioCtx.state); }
|
||||||
|
|
||||||
const source = audioCtx.createMediaStreamSource(voiceStream);
|
const source = audioCtx.createMediaStreamSource(stream);
|
||||||
voiceProcessor = audioCtx.createScriptProcessor(2048, 1, 1);
|
const analyser = audioCtx.createAnalyser();
|
||||||
addLog('4. ScriptProcessor created');
|
analyser.fftSize = 2048;
|
||||||
|
source.connect(analyser);
|
||||||
|
|
||||||
voiceProcessor.onaudioprocess = (e) => {
|
// Check mic levels
|
||||||
debugCount++;
|
const dataArr = new Float32Array(analyser.fftSize);
|
||||||
const pcm = e.inputBuffer.getChannelData(0);
|
let checkCount = 0;
|
||||||
const maxVal = Math.max(...Array.from(pcm).map(Math.abs));
|
const checkInterval = setInterval(() => {
|
||||||
if (debugCount <= 10) addLog('5. onaudioprocess #' + debugCount + ' samples=' + pcm.length + ' max=' + maxVal.toFixed(4));
|
analyser.getFloatTimeDomainData(dataArr);
|
||||||
|
let sum = 0;
|
||||||
|
for (let i = 0; i < dataArr.length; i++) sum += dataArr[i] * dataArr[i];
|
||||||
|
const rms = Math.sqrt(sum / dataArr.length);
|
||||||
|
checkCount++;
|
||||||
|
if (checkCount <= 20 || checkCount % 50 === 0) log('Mic RMS: ' + rms.toFixed(6) + (rms > 0.008 ? ' SPEAKING' : ''));
|
||||||
|
}, 200);
|
||||||
|
|
||||||
if (!voiceSocket || !voiceSocket.connected) return;
|
log('Connecting to voice server...');
|
||||||
const int16 = new Int16Array(pcm.length);
|
const socket = io(VOICE_SERVER, {transports: ['websocket']});
|
||||||
for (let i = 0; i < pcm.length; i++) {
|
|
||||||
const s = Math.max(-1, Math.min(1, pcm[i]));
|
socket.on('connect', () => {
|
||||||
|
log('SOCKET CONNECTED: ' + socket.id);
|
||||||
|
socket.emit('voice_join', {world_id: 'test', x: 0, y: 0, name: 'Tester', mode: 'world', codec: 'pcm'});
|
||||||
|
log('voice_join sent');
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('connect_error', (e) => {
|
||||||
|
log('SOCKET ERROR: ' + e.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('voice_in', (payload) => {
|
||||||
|
log('RX voice_in from ' + (payload.meta?.from||'?').substring(0,8) + ' codec:' + payload.codec + ' size:' + (payload.data?.byteLength || payload.data?.length || '?'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Capture and send
|
||||||
|
const processor = audioCtx.createScriptProcessor(320, 1, 1);
|
||||||
|
source.connect(processor);
|
||||||
|
processor.connect(audioCtx.destination);
|
||||||
|
|
||||||
|
let seq = 0;
|
||||||
|
let sendCount = 0;
|
||||||
|
processor.onaudioprocess = (e) => {
|
||||||
|
if (!socket.connected) return;
|
||||||
|
const float32 = e.inputBuffer.getChannelData(0);
|
||||||
|
let rms = 0;
|
||||||
|
for (let i = 0; i < float32.length; i++) rms += float32[i] * float32[i];
|
||||||
|
rms = Math.sqrt(rms / float32.length);
|
||||||
|
|
||||||
|
if (rms < 0.005) return; // Skip silence
|
||||||
|
|
||||||
|
const int16 = new Int16Array(float32.length);
|
||||||
|
for (let i = 0; i < float32.length; i++) {
|
||||||
|
const s = Math.max(-1, Math.min(1, float32[i]));
|
||||||
int16[i] = s < 0 ? s * 0x8000 : s * 0x7FFF;
|
int16[i] = s < 0 ? s * 0x8000 : s * 0x7FFF;
|
||||||
}
|
}
|
||||||
voiceSocket.emit('voice_data', int16.buffer);
|
|
||||||
|
socket.emit('voice_data', {codec: 'pcm', data: int16.buffer, seq: seq++, speaking: true});
|
||||||
|
sendCount++;
|
||||||
|
if (sendCount <= 5 || sendCount % 50 === 0) log('TX frame #' + sendCount + ' rms:' + rms.toFixed(4) + ' size:' + int16.buffer.byteLength);
|
||||||
};
|
};
|
||||||
|
|
||||||
const silentGain = audioCtx.createGain();
|
log('Voice capture active. Speak into mic!');
|
||||||
silentGain.gain.value = 0;
|
|
||||||
source.connect(voiceProcessor);
|
|
||||||
voiceProcessor.connect(silentGain);
|
|
||||||
silentGain.connect(audioCtx.destination);
|
|
||||||
addLog('6. Audio chain connected: source→processor→gain(0)→destination');
|
|
||||||
|
|
||||||
addLog('7. Connecting to voice server...');
|
|
||||||
voiceSocket = io('https://voicegrech.mkn8n.ru', { transports: ['websocket'] });
|
|
||||||
voiceSocket.on('connect', () => {
|
|
||||||
addLog('8. Socket connected: ' + voiceSocket.id);
|
|
||||||
voiceSocket.emit('voice_join', { world_id: 'test', x: 0, y: 0, name: 'Tester' });
|
|
||||||
addLog('9. Sent voice_join. Speak into mic — watch onaudioprocess logs above!');
|
|
||||||
});
|
|
||||||
voiceSocket.on('connect_error', (err) => addLog('ERROR: ' + err.message));
|
|
||||||
|
|
||||||
voiceSocket.on('voice_in', (payload) => {
|
|
||||||
addLog('VOICE_IN from ' + payload.meta.name + ' vol=' + payload.volume + ' bytes=' + payload.data.byteLength);
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('btn').textContent = 'Listening...';
|
|
||||||
document.getElementById('btn').style.background = '#e74c3c';
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
addLog('ERROR: ' + e.message + '\n' + e.stack);
|
log('ERROR: ' + e.message);
|
||||||
}
|
}
|
||||||
};
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body></html>
|
</body>
|
||||||
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue