Raw Mic Input

Disables WebRTC audio processing to allow raw mic input.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Raw Mic Input
// @namespace    https://6942020.xyz/
// @version      1.4
// @description  Disables WebRTC audio processing to allow raw mic input.
// @author       Joey Watts
// @author       WadeGrimridge
// @match        *://*/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let globalRawAudioTrack = null;

    const rawConfig = {
        echoCancellation: false,
        noiseSuppression: false,
        autoGainControl: false,
        voiceIsolation: false,
        googEchoCancellation: false,
        googAutoGainControl: false,
        googAutoGainControl2: false,
        googNoiseSuppression: false,
        googHighpassFilter: false,
        googTypingNoiseDetection: false
    };

    function disableAutogain(constraints) {
        if (!constraints) return;
        if (constraints.audio === true) constraints.audio = {};
        if (constraints.audio && typeof constraints.audio === 'object') {
            Object.assign(constraints.audio, rawConfig);
            if (constraints.audio.mandatory) {
                Object.assign(constraints.audio.mandatory, rawConfig);
            }
        }
    }

    if (navigator.mediaDevices) {
        const origGetUserMedia = navigator.mediaDevices.getUserMedia;
        navigator.mediaDevices.getUserMedia = function(constraints) {
            disableAutogain(constraints);
            return origGetUserMedia.call(this, constraints).then(stream => {
                const track = stream.getAudioTracks()[0];
                if (track) {
                    globalRawAudioTrack = track;
                }
                return stream;
            });
        };
    }

    if (window.RTCPeerConnection) {
        const origAddTransceiver = RTCPeerConnection.prototype.addTransceiver;
        RTCPeerConnection.prototype.addTransceiver = function(trackOrKind, init) {
            if (globalRawAudioTrack && typeof trackOrKind === 'object' && trackOrKind.kind === 'audio') {
                return origAddTransceiver.call(this, globalRawAudioTrack, init);
            }
            return origAddTransceiver.call(this, trackOrKind, init);
        };
    }

    if (window.RTCRtpSender) {
        const origReplaceTrack = RTCRtpSender.prototype.replaceTrack;
        RTCRtpSender.prototype.replaceTrack = function(track) {
            if (track && globalRawAudioTrack && track.kind === 'audio') {
                return origReplaceTrack.call(this, globalRawAudioTrack);
            }
            return origReplaceTrack.call(this, track);
        };
    }

    if (navigator.getUserMedia) {
        const patchLegacy = (orig) => function(constraints, success, error) {
            disableAutogain(constraints);
            return orig.call(this, constraints, (stream) => {
                const track = stream.getAudioTracks()[0];
                if (track) globalRawAudioTrack = track;
                if (success) success(stream);
            }, error);
        };
        navigator.getUserMedia = patchLegacy(navigator.getUserMedia);
        if (navigator.webkitGetUserMedia) navigator.webkitGetUserMedia = patchLegacy(navigator.webkitGetUserMedia);
        if (navigator.mozGetUserMedia) navigator.mozGetUserMedia = patchLegacy(navigator.mozGetUserMedia);
    }
})();