OpenAI Voice-to-Text

Enables voice-to-text functionality on chat.openai by holding down the 'v' key and speaking into your microphone, using the Web Speech API, and automatically inserting the transcribed text into the chat input field. All you need to do is allow https://chat.openai.com to have access to your microphone and press and hold V to input your voice into text if the microphone permission does not show just press V for it to show up

当前为 2023-04-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         OpenAI Voice-to-Text
// @namespace    openai_voice_to_text
// @version      2
// @description  Enables voice-to-text functionality on chat.openai by holding down the 'v' key and speaking into your microphone, using the Web Speech API, and automatically inserting the transcribed text into the chat input field. All you need to do is allow https://chat.openai.com to have access to your microphone and press and hold V to input your voice into text if the microphone permission does not show just press V for it to show up
// @author       letsplayto
// @match        https://chat.openai.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const recognition = new webkitSpeechRecognition();
    recognition.lang = 'en-US';
    recognition.continuous = true;
    recognition.interimResults = false;

    let isListening = false;
    let finalTranscript = '';

    const micIcon = document.createElement('div');
    micIcon.style.position = 'fixed';
    micIcon.style.bottom = '10px';
    micIcon.style.right = '10px';
    micIcon.style.zIndex = '99999';
    micIcon.style.fontSize = '18px';
    micIcon.style.color = 'white';
    micIcon.style.padding = '10px';
    micIcon.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
    micIcon.style.borderRadius = '5px';
    micIcon.style.fontWeight = 'bold';
    micIcon.textContent = 'Press and hold V to talk';
    document.body.appendChild(micIcon);

    document.addEventListener('keydown', event => {
        if (event.key === 'v' && !isListening) {
            micIcon.textContent = 'Recording... (Release V to Stop)';
            startRecognition();
        }
    });

    document.addEventListener('keyup', event => {
        if (event.key === 'v' && isListening) {
            micIcon.textContent = 'Press and hold V to talk';
            stopRecognition();
        }
    });

    recognition.addEventListener('result', event => {
        const transcript = Array.from(event.results)
            .map(result => result[0].transcript)
            .join('');

        if (event.results[0].isFinal) {
            finalTranscript += transcript;
            insertText(finalTranscript);
            finalTranscript = '';
        }
    });

    function startRecognition() {
        isListening = true;
        recognition.start();
        console.log('Recording... (Release V to Stop)');
    }

    function stopRecognition() {
        isListening = false;
        recognition.stop();
        console.log('Stopped Recording');
    }

    function insertText(text) {
        const input = document.querySelector('textarea');
        input.value += text;
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址