Author Topic: [Danzy] Adding Text-to-Speech Feature for /highlights  (Read 1495 times)

Offline Egekan

  • eggplant
  • Outstanding Community Member
  • *****
  • Posts: 1480
  • Registered: 31/08/2011
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Group: SAPD
  • Ingame: Egekan
[Danzy] Adding Text-to-Speech Feature for /highlights
« 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:



Another checkbox can be placed under sound option which says "Use Google Text-to-Speech" to enable/disable this TTS feature.

Also adding an edit box or maybe a combobox 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 for details of the function. Everything is explained well there.

List of languages supported by Google Text-to-Speech and their codes: Click Here

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

« Last Edit: 05 06, 2021, 06:01:34 pm by Arran »

Offline Senza

  • Mr. Catface
  • Honorable
  • *****
  • Posts: 3324
  • A cat
  • Registered: 13/01/2016
    YearsYearsYearsYearsYearsYearsYearsYears
Re: Adding Text-to-Speech Feature for /highlights
« Reply #1 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.

Offline Arran

  • Administrator
  • ******
  • Posts: 5593
  • Registered: 20/11/2010
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Ingame: [CIT]Arran
Re: Adding Text-to-Speech Feature for /highlights
« Reply #2 on: 05 06, 2021, 05:58:41 pm »
@Danzy since this is in your repo you can add it.
Proof You Are so Much More Than What You Realise
Authority is not truth. Truth is authority.

Offline Danzy

  • The Amplifier
  • L4 Staff
  • ****
  • Posts: 2470
  • infernoob
  • Registered: 21/05/2011
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
Re: [Danzy] Adding Text-to-Speech Feature for /highlights
« Reply #3 on: 06 06, 2021, 01:33:22 pm »
Work in progress.
We don't search for old songs, we search for old memories.

Offline Arran

  • Administrator
  • ******
  • Posts: 5593
  • Registered: 20/11/2010
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Ingame: [CIT]Arran
Re: [Danzy] Adding Text-to-Speech Feature for /highlights
« Reply #4 on: 30 06, 2021, 04:52:48 pm »
@Danzy any progress?
Proof You Are so Much More Than What You Realise
Authority is not truth. Truth is authority.

Offline Danzy

  • The Amplifier
  • L4 Staff
  • ****
  • Posts: 2470
  • infernoob
  • Registered: 21/05/2011
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
Re: [Danzy] Adding Text-to-Speech Feature for /highlights
« Reply #5 on: 30 06, 2021, 05:16:00 pm »
Uh yes it should be done, might need some testing on com dev though.
We don't search for old songs, we search for old memories.

Offline Vampire

  • vompire
  • Non Administrative Staff
  • ****
  • Posts: 3304
  • The Undeadly Thirst
  • Registered: 17/04/2015
    YearsYearsYearsYearsYearsYearsYearsYears
  • Ingame: [CIT]Vampire
Re: [Danzy] Adding Text-to-Speech Feature for /highlights
« Reply #6 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.
"Being reminded for something you worked really hard is good to your soul, and see that you left your mark behind is good to your mind" - Vampire 2017

Offline Arran

  • Administrator
  • ******
  • Posts: 5593
  • Registered: 20/11/2010
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Ingame: [CIT]Arran
Re: [Danzy] Adding Text-to-Speech Feature for /highlights
« Reply #7 on: 03 07, 2021, 07:25:22 pm »
If I'm to add this I need details / a submission topic.
Proof You Are so Much More Than What You Realise
Authority is not truth. Truth is authority.

Offline Vampire

  • vompire
  • Non Administrative Staff
  • ****
  • Posts: 3304
  • The Undeadly Thirst
  • Registered: 17/04/2015
    YearsYearsYearsYearsYearsYearsYearsYears
  • Ingame: [CIT]Vampire
Re: [Danzy] Adding Text-to-Speech Feature for /highlights
« Reply #8 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)
"Being reminded for something you worked really hard is good to your soul, and see that you left your mark behind is good to your mind" - Vampire 2017