Raw Mic Input

Disables WebRTC audio processing to allow raw mic input.

当前为 2025-11-25 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
    }
})();