microphone tweaks for release

This commit is contained in:
thelamer 2024-06-25 12:36:57 -04:00
parent f3d2e12a41
commit 4791249876
2 changed files with 5 additions and 15 deletions

View File

@ -31,16 +31,6 @@ pulse.on('error', function(error) {
audioEnabled = false;
console.log('Kclient was unable to init audio, it is possible your host lacks support!!!!');
});
if (audioEnabled) {
var stream = pulse.createPlaybackStream({
stream: "LSIOMic",
device: "LSIOMic",
format: "S16LE",
rate: 44100,
channels: 1,
latency: 100,
});
}
//// Server Paths Main ////
@ -190,9 +180,7 @@ aio.on('connection', function (socket) {
// Dump blobs to pulseaudio sink
async function micData(buffer) {
if (audioEnabled) {
stream.write(buffer);
}
await fsw.writeFile('/defaults/mic.sock', buffer);
}
// Incoming socket requests

View File

@ -103,18 +103,20 @@ function mic() {
function onMediaSuccess(stream) {
audio_context = new window.AudioContext;
let source = audio_context.createMediaStreamSource(stream);
let processor = audio_context.createScriptProcessor(2048, 1, 1);
let processor = audio_context.createScriptProcessor(512, 1, 1);
source.connect(processor);
processor.connect(audio_context.destination);
processor.onaudioprocess = function (audioEvent) {
let int16Array = Int16Array.from(audioEvent.inputBuffer.getChannelData(0), x => x * 32767);
let arraySize = new Blob([JSON.stringify(int16Array)]).size;
if (arraySize > 20000) {
if (arraySize > 4100) {
socket.emit('micdata', int16Array.buffer);
}
};
}
function onMediaError(e) {
console.error('media error', e);
$('#micButton').removeClass("icons-selected");
micEnabled = false;
}
}