Refactor Windows audio capture setup to streamline processing and remove redundant logging
Some checks failed
Build and Release / build (x64, ubuntu-latest, linux) (push) Has been skipped
Build and Release / build (arm64, macos-latest, darwin) (push) Has been cancelled
Build and Release / build (x64, macos-latest, darwin) (push) Has been cancelled
Build and Release / build (x64, windows-latest, win32) (push) Has been cancelled
Build and Release / release (push) Has been cancelled
Some checks failed
Build and Release / build (x64, ubuntu-latest, linux) (push) Has been skipped
Build and Release / build (arm64, macos-latest, darwin) (push) Has been cancelled
Build and Release / build (x64, macos-latest, darwin) (push) Has been cancelled
Build and Release / build (x64, windows-latest, win32) (push) Has been cancelled
Build and Release / release (push) Has been cancelled
This commit is contained in:
parent
2f013b4751
commit
76d6fc2749
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "cheating-daddy",
|
"name": "cheating-daddy",
|
||||||
"productName": "cheating-daddy",
|
"productName": "cheating-daddy",
|
||||||
"version": "0.5.8",
|
"version": "0.5.9",
|
||||||
"description": "cheating daddy",
|
"description": "cheating daddy",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@ -295,9 +295,6 @@ async function startCapture(screenshotIntervalSeconds = 5, imageQuality = 'mediu
|
|||||||
console.log('Linux capture started - system audio:', mediaStream.getAudioTracks().length > 0, 'microphone mode:', audioMode);
|
console.log('Linux capture started - system audio:', mediaStream.getAudioTracks().length > 0, 'microphone mode:', audioMode);
|
||||||
} else {
|
} else {
|
||||||
// Windows - use display media with loopback for system audio
|
// Windows - use display media with loopback for system audio
|
||||||
logToMain('info', '=== Starting Windows audio capture ===');
|
|
||||||
cheatingDaddy.setStatus('Requesting screen & audio...');
|
|
||||||
|
|
||||||
mediaStream = await navigator.mediaDevices.getDisplayMedia({
|
mediaStream = await navigator.mediaDevices.getDisplayMedia({
|
||||||
video: {
|
video: {
|
||||||
frameRate: 1,
|
frameRate: 1,
|
||||||
@ -313,6 +310,7 @@ async function startCapture(screenshotIntervalSeconds = 5, imageQuality = 'mediu
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('Windows capture started with loopback audio');
|
||||||
const audioTracks = mediaStream.getAudioTracks();
|
const audioTracks = mediaStream.getAudioTracks();
|
||||||
const videoTracks = mediaStream.getVideoTracks();
|
const videoTracks = mediaStream.getVideoTracks();
|
||||||
|
|
||||||
@ -328,14 +326,8 @@ async function startCapture(screenshotIntervalSeconds = 5, imageQuality = 'mediu
|
|||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (audioTracks.length === 0) {
|
// Setup audio processing for Windows loopback audio only
|
||||||
logToMain('warn', 'WARNING: No audio tracks! User must check "Share audio" in screen picker dialog');
|
setupWindowsLoopbackProcessing();
|
||||||
cheatingDaddy.setStatus('Warning: No audio - enable "Share audio" checkbox');
|
|
||||||
} else {
|
|
||||||
logToMain('info', 'Audio track acquired, setting up processing...');
|
|
||||||
// Setup audio processing for Windows loopback audio only
|
|
||||||
setupWindowsLoopbackProcessing();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (audioMode === 'mic_only' || audioMode === 'both') {
|
if (audioMode === 'mic_only' || audioMode === 'both') {
|
||||||
let micStream = null;
|
let micStream = null;
|
||||||
@ -451,73 +443,32 @@ function setupLinuxSystemAudioProcessing() {
|
|||||||
|
|
||||||
function setupWindowsLoopbackProcessing() {
|
function setupWindowsLoopbackProcessing() {
|
||||||
// Setup audio processing for Windows loopback audio only
|
// Setup audio processing for Windows loopback audio only
|
||||||
logToMain('info', 'Setting up Windows loopback audio processing...');
|
audioContext = new AudioContext({ sampleRate: SAMPLE_RATE });
|
||||||
|
const source = audioContext.createMediaStreamSource(mediaStream);
|
||||||
try {
|
audioProcessor = audioContext.createScriptProcessor(BUFFER_SIZE, 1, 1);
|
||||||
audioContext = new AudioContext({ sampleRate: SAMPLE_RATE });
|
|
||||||
|
let audioBuffer = [];
|
||||||
logToMain('info', 'AudioContext created:', {
|
const samplesPerChunk = SAMPLE_RATE * AUDIO_CHUNK_DURATION;
|
||||||
state: audioContext.state,
|
|
||||||
sampleRate: audioContext.sampleRate,
|
audioProcessor.onaudioprocess = async e => {
|
||||||
});
|
const inputData = e.inputBuffer.getChannelData(0);
|
||||||
|
audioBuffer.push(...inputData);
|
||||||
// Resume AudioContext if suspended (Chrome policy)
|
|
||||||
if (audioContext.state === 'suspended') {
|
// Process audio in chunks
|
||||||
logToMain('warn', 'AudioContext suspended, attempting resume...');
|
while (audioBuffer.length >= samplesPerChunk) {
|
||||||
audioContext.resume().then(() => {
|
const chunk = audioBuffer.splice(0, samplesPerChunk);
|
||||||
logToMain('info', 'AudioContext resumed successfully');
|
const pcmData16 = convertFloat32ToInt16(chunk);
|
||||||
}).catch(err => {
|
const base64Data = arrayBufferToBase64(pcmData16.buffer);
|
||||||
logToMain('error', 'Failed to resume AudioContext:', err.message);
|
|
||||||
|
await ipcRenderer.invoke('send-audio-content', {
|
||||||
|
data: base64Data,
|
||||||
|
mimeType: 'audio/pcm;rate=24000',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
const source = audioContext.createMediaStreamSource(mediaStream);
|
|
||||||
audioProcessor = audioContext.createScriptProcessor(BUFFER_SIZE, 1, 1);
|
|
||||||
|
|
||||||
let audioBuffer = [];
|
source.connect(audioProcessor);
|
||||||
const samplesPerChunk = SAMPLE_RATE * AUDIO_CHUNK_DURATION;
|
audioProcessor.connect(audioContext.destination);
|
||||||
let chunkCount = 0;
|
|
||||||
let totalSamples = 0;
|
|
||||||
|
|
||||||
audioProcessor.onaudioprocess = async e => {
|
|
||||||
const inputData = e.inputBuffer.getChannelData(0);
|
|
||||||
audioBuffer.push(...inputData);
|
|
||||||
totalSamples += inputData.length;
|
|
||||||
|
|
||||||
// Process audio in chunks
|
|
||||||
while (audioBuffer.length >= samplesPerChunk) {
|
|
||||||
const chunk = audioBuffer.splice(0, samplesPerChunk);
|
|
||||||
const pcmData16 = convertFloat32ToInt16(chunk);
|
|
||||||
const base64Data = arrayBufferToBase64(pcmData16.buffer);
|
|
||||||
|
|
||||||
await ipcRenderer.invoke('send-audio-content', {
|
|
||||||
data: base64Data,
|
|
||||||
mimeType: 'audio/pcm;rate=24000',
|
|
||||||
});
|
|
||||||
|
|
||||||
chunkCount++;
|
|
||||||
|
|
||||||
// Log progress every 100 chunks (~10 seconds)
|
|
||||||
if (chunkCount === 1) {
|
|
||||||
logToMain('info', 'First audio chunk sent to AI');
|
|
||||||
cheatingDaddy.setStatus('Listening...');
|
|
||||||
} else if (chunkCount % 100 === 0) {
|
|
||||||
// Calculate max amplitude to check if we're getting real audio
|
|
||||||
const maxAmp = Math.max(...chunk.map(Math.abs));
|
|
||||||
logToMain('info', `Audio progress: ${chunkCount} chunks, maxAmplitude: ${maxAmp.toFixed(4)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
source.connect(audioProcessor);
|
|
||||||
audioProcessor.connect(audioContext.destination);
|
|
||||||
|
|
||||||
logToMain('info', 'Windows audio processing pipeline connected');
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
logToMain('error', 'Error setting up Windows audio:', err.message, err.stack);
|
|
||||||
cheatingDaddy.setStatus('Audio error: ' + err.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function captureScreenshot(imageQuality = 'medium', isManual = false) {
|
async function captureScreenshot(imageQuality = 'medium', isManual = false) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user