chat-gpt-voice-recognition-userscript

A userscript to add voice recognition to Chat GPT

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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
);