chat-gpt-voice-recognition-userscript

A userscript to add voice recognition to Chat GPT

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        chat-gpt-voice-recognition-userscript
// @match       https://chat.openai.com/chat
// @version     2022.12.7
// @author      Jared Jacobsen (https://github.com/JaredJacobsen)
// @license     MIT
// @description A userscript to add voice recognition to Chat GPT
// @namespace https://greasyfork.org/users/994126
// ==/UserScript==

let textArea;
let transcript = '';
var recognition = new webkitSpeechRecognition();
recognition.continuous = false;
recognition.interimResults = true;

let recognizing = false;
recognition.onstart = function () {
	textArea.parentElement.style.borderColor = 'red';
	textArea.value = '';
	recognizing = true;
	transcript = '';
};
recognition.onresult = function (event) {
	transcript = '';
	for (var i = event.resultIndex; i < event.results.length; ++i) {
		transcript += event.results[i][0].transcript;
	}
	textArea.focus();
	textArea.value = transcript;
	let ev = new Event('input', { bubbles: true });
	textArea.dispatchEvent(ev);
};
recognition.onend = function () {
	textArea.parentElement.style.borderColor = 'lightgray';
	recognizing = false;
	transcript = '';
	textArea.parentElement.querySelector('button').click();
};
recognition.onerror = function (event) {
	console.log('error', event);
	textArea.parentElement.style.borderColor = 'lightgray';
};

document.addEventListener(
	'keydown',
	(e) => {
		if (e.code === 'Tab') {
			e.preventDefault();
			e.stopImmediatePropagation();
			textArea = document.querySelector('textarea');
			if (recognizing) {
				recognizing = false;
				recognition.stop();
			} else recognition.start();
		}
	},
	true
);