CIT Forum Index

Ingame Community => News and Updates => Topic started by: Egekan on 04 06, 2021, 03:53:42 am

Title: [Danzy] Adding Text-to-Speech Feature for /highlights
Post by: Egekan on 04 06, 2021, 03:53:42 am
Hello,

Sometimes when you are busy, something triggers one of your /highlights entries. Unfortunately, it is not possible to change the sound for different highlights. So the only way to know which one was it to go back to the game and find the chat output in question. Instead of adding different sound options it is possible to make Google read them for you!

This suggestion is about making /highlights GUI read notifications using Google's Text-to-Speech instead of playing the same sound for every single notification. This is the GUI that appears when you use /highlights command:

(https://i.imgur.com/yIRpGjW.png)

Another checkbox (https://wiki.multitheftauto.com/images/7/72/Checkbox.png) can be placed under sound option which says "Use Google Text-to-Speech" to enable/disable this TTS feature.

Also adding an edit box (https://wiki.multitheftauto.com/images/b/bc/Gui-edit.png) or maybe a combobox (https://wiki.multitheftauto.com/images/5/53/Gui-combobox.jpg) that has language options in it below that checkbox sounds cool. So it will be possible to make it read them in different languages, this will help a lot if you are unable to speak English but still want to use that feature in your language.

Function you need to use in order to implement this feature to MTA:
Client:
Code: Lua
  1. addEvent("playTTS", true) -- Add the event
  2.  
  3. local function playTTS(text, lang)
  4.     --local URL = "http://translate.google.com/translate_tts?tl=" .. lang .. "&q=" .. text
  5.     --local URL = "https://code.responsivevoice.org/getvoice.php?tl=" .. lang .. "&t=" .. text
  6.     local URL = "http://translate.google.com/translate_tts?tl="..lang.."&q="..text.."&client=tw-ob"
  7.     -- Play the TTS. BASS returns the sound element even if it can not be played.
  8.     return true, playSound(URL), URL
  9. end
  10. addEventHandler("playTTS", root, playTTS)
  11.  

Shared:
Code: Lua
  1. function convertTextToSpeech(text, broadcastTo, lang)
  2.     -- Ensure first argument is valid
  3.     assert(type(text) == "string", "Bad argument 1 @ convertTextToSpeech [ string expected, got " .. type(text) .. "]")
  4.     assert(#text <= 100, "Bad argument 1 @ convertTextToSpeech [ too long string; 100 characters maximum ]")
  5.     if triggerClientEvent then -- Is this function called serverside?
  6.         -- Ensure second and third arguments are valid
  7.         assert(broadcastTo == nil or type(broadcastTo) == "table" or isElement(broadcastTo), "Bad argument 2 @ convertTextToSpeech [ table/element expected, got " .. type(broadcastTo) .. "]")
  8.         assert(lang == nil or type(lang) == "string", "Bad argument 3 @ convertTextToSpeech [ string expected, got " .. type(lang) .. "]")
  9.         -- Tell the client to play the speech
  10.         return triggerClientEvent(broadcastTo or root, "playTTS", root, text, lang or "en")
  11.     else -- This function is executed clientside
  12.         local lang = broadcastTo
  13.         -- Ensure second argument is valid
  14.         assert(lang == nil or type(lang) == "string", "Bad argument 2 @ convertTextToSpeech [ string expected, got " .. type(lang) .. "]")
  15.         return playTTS(text, lang or "en")
  16.     end
  17. end
  18.  
Please refer to this MTA wiki page (https://wiki.multitheftauto.com/wiki/ConvertTextToSpeech) for details of the function. Everything is explained well there.

List of languages supported by Google Text-to-Speech and their codes: Click Here (https://cloud.google.com/text-to-speech/docs/voices)

An example to give you an idea about how it works:
http://translate.google.com/translate_tts?tl=en-GB&q=Thissuggestionisamazing&client=tw-ob (http://translate.google.com/translate_tts?tl=en-GB&q=Thissuggestionisamazing&client=tw-ob)

Title: Re: Adding Text-to-Speech Feature for /highlights
Post by: Senza on 04 06, 2021, 03:57:59 am
Such a cool suggestion and also easy to implement, always wondered what we can use TTS for, but this is definitely a good start. Positive.
Title: Re: Adding Text-to-Speech Feature for /highlights
Post by: Arran on 05 06, 2021, 05:58:41 pm
@Danzy since this is in your repo you can add it.
Title: Re: [Danzy] Adding Text-to-Speech Feature for /highlights
Post by: Danzy on 06 06, 2021, 01:33:22 pm
Work in progress.
Title: Re: [Danzy] Adding Text-to-Speech Feature for /highlights
Post by: Arran on 30 06, 2021, 04:52:48 pm
@Danzy any progress?
Title: Re: [Danzy] Adding Text-to-Speech Feature for /highlights
Post by: Danzy on 30 06, 2021, 05:16:00 pm
Uh yes it should be done, might need some testing on com dev though.
Title: Re: [Danzy] Adding Text-to-Speech Feature for /highlights
Post by: Vampire on 03 07, 2021, 02:13:41 pm
Uh yes it should be done, might need some testing on com dev though.
Tested it and it seems to be working just fine.
Title: Re: [Danzy] Adding Text-to-Speech Feature for /highlights
Post by: Arran on 03 07, 2021, 07:25:22 pm
If I'm to add this I need details / a submission topic.
Title: Re: [Danzy] Adding Text-to-Speech Feature for /highlights
Post by: Vampire on 13 07, 2021, 04:26:25 am
- Added text to speech support to /highlights. If you already have existing highlights, you can select them, select a language and click 'Save' to enable text to speech support with a set language. (Danzy + Egekan)