lencx / ChatGPT

🔮 ChatGPT Desktop Application (Mac, Windows and Linux)
https://nofwl.com
52.87k stars 5.95k forks source link

[Feature] Add automatic reading function? #534

Open Lufffya opened 1 year ago

Lufffya commented 1 year ago

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

dsernst commented 1 year ago

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

dsernst commented 1 year ago

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.
chuyueye commented 1 year ago

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

lencx commented 1 year ago

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.

neoOpus commented 1 year ago

it would be better also to use Edge TTS

null15 commented 1 year ago

Can I use ElevenLabs for the TTS?

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

LeonChow5929 commented 1 year ago

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

OMGHWORK commented 1 year ago

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

pablorq commented 1 year ago

The workaround doesn't work on Ubuntu 23.04:

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

Any idea?

Frank15140156026 commented 1 year ago

hello