ChatGPT icon indicating copy to clipboard operation
ChatGPT copied to clipboard

[Feature] Add automatic reading function?

Open Lufffya opened this issue 1 year ago • 5 comments

Feature description

Can you add automatic reading function for chatgpt answers? As shown in the figure: image I hope that after I say hello, there will be a reading button behind the chatgpt answer (Like those three). Click this button to automatically read the chatgpt answer(Hello! How can I assist you today?)

Motivation

I just think it can be beneficial to learning, because chatgpt originally supports multiple languages. When I have to ask questions in an unskilled language, reading can help me understand better and will be more interesting. Thanks!!!

Alternatives

No response

Additional context

No response

Lufffya avatar Mar 01 '23 08:03 Lufffya

Do you mean reading the response out loud, as audio?

dsernst avatar Mar 04 '23 03:03 dsernst

I have been playing with this, I was able to get some basic JS working to find the most recent reply and read it aloud using the built in SpeechSynthesizer API.

I added this to my ~/.chatgpt/main.js file:

// Say command: read text aloud
function say(text) {
  speechSynthesis.speak(new SpeechSynthesisUtterance(text))
}

// Find the most recent reply
function lastReply() {
  const replies = document.getElementsByClassName('prose')
  const last = replies[replies.length - 1]
  return last.textContent
}

// Register a sayLast function to the global window so we can call it later.
window.sayLast = () => say(lastReply())

// Register hotkey Cmd+S (Ctrl+S on Windows) to start/stop
document.addEventListener('keydown', function (event) {
  // Ctrl + S or Cmd + S hotkey
  if ((event.ctrlKey || event.metaKey) && event.key === 's') {
    if (speechSynthesis.speaking) {
      speechSynthesis.cancel()
    } else {
      sayLast()
    }

    event.preventDefault() // Prevent the default action of saving the page
  }
})
console.log('sayLast() 🔈 function installed, Cmd + S hotkey to activate')

Then in a conversation, I can press Cmd+S to have the most recent answer read aloud.

Previous: ~~Then in a conversation, I open the Dev Tools (Right click > Inspect Element), switch to the Console tab, and can invoke the sayLast() function to have ChatGPT's most recent reply read aloud.~~


Possible Improvements

The hotkey works pretty well for me, but some other options:

  1. Add a button next to replies to have them read aloud, as OP originally suggested.
  2. Add a toggleable preference to automatically read all replies aloud. Ideally this would be a little thing visible in the window, so it can be turned on/off easily.

dsernst avatar Mar 04 '23 04:03 dsernst

Can voice engine pronounce bilingual text?Now I can only select on lingua in the setting

chuyueye avatar Mar 06 '23 09:03 chuyueye

Can voice engine pronounce bilingual text?Now I can only select on lingua in the setting

It is a built-in browser API and does not seem to support multilingual synthesis.

lencx avatar Mar 06 '23 10:03 lencx

it would be better also to use Edge TTS

neoOpus avatar Mar 08 '23 02:03 neoOpus

Can I use ElevenLabs for the TTS?

https://api.elevenlabs.io/docs#/voices/Get_voices_v1_voices_get

null15 avatar Apr 05 '23 14:04 null15

There is "No Data" when I choose Set Speech Language. Dose anyone could tell me way?

LeonChow5929 avatar Apr 11 '23 08:04 LeonChow5929

There is "No Data" when I choose Set Speech Language. Dose anyone could tell me way?

Workaround: open developer tools, execute speechSynthesis.getVoices() in the console and copy the voiceURI to the speech_lang parameter in chat.conf.json

OMGHWORK avatar Apr 27 '23 09:04 OMGHWORK

The workaround doesn't work on Ubuntu 23.04:

> speechSynthesis.getVoices()
> ReferenceError: Can't find variable: speechSynthesis

Any idea?

pablorq avatar May 09 '23 13:05 pablorq

hello

Frank15140156026 avatar May 22 '23 10:05 Frank15140156026