mirror of
https://github.com/linuxserver/kclient.git
synced 2026-03-23 00:00:56 +08:00
microphone tweaks for release
This commit is contained in:
parent
f3d2e12a41
commit
4791249876
14
index.js
14
index.js
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user