cogentapps / chat-with-gpt

An open-source ChatGPT app with a voice
https://www.chatwithgpt.ai
MIT License
2.31k stars 493 forks source link

added the browser tts api as fallback for ElevenLabs #55

Closed tluyben closed 1 year ago

tluyben commented 1 year ago

Browser text-to-speech fallback for people who don't want to use ElevenLabs.

cogentapps commented 1 year ago

Adding support for the browser's native TTS is a good idea, but I don't think it should be enabled by default, because the quality is very low on many devices. My experience has been that the 'default' voice chosen by the web speech API is not always the best choice.

Probably the design should be something like: clicking Play still opens speech settings, but the dropdown for the Voice setting shows native voices by default, and ElevenLabs voices if you enter your API key.

This would also work for adding other TTS providers (Google, AWS, Coqui? etc.) in the future.

tluyben commented 1 year ago

It is free and easy and on some browsers it works quite well: not sure if there is a reason to not enable it? But further I completely agree.

tao1020 commented 1 year ago

Browser text-to-speech fallback for people who don't want to use ElevenLabs.

I came across your pull request and noticed an issue with the code involving API calls. Specifically, the SpeechSynthesis.getVoices() method does not work on Edge browser, and should be replaced with speechSynthesis.onvoiceschanged as seen below:

speechSynthesis.onvoiceschanged = () => {
    const voices = speechSynthesis.getVoices();
}

I've made some modifications to the code and uploaded them to my forked repository at https://github.com/tao1020/chat-with-gpt.git for your reference. Please note that I'm not familiar with TypeScript, so there may be errors in my changes,however,it works correctly on my computer.

You can find more information about using the Web Speech API, including this specific issue, at the following link: https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API/Using_the_Web_Speech_API#:~:text=When%20we%20come,statement%20seen%20below.

cogentapps commented 1 year ago

Hi, just wanted to update you on this - I decided to approach this in a different way. Browser TTS has been added, but I rewrote the text-to-speech code to use a new 'plugin' format. This will make it easier to add new TTS providers in the future.