Jump to content

TextSpeech - how to get what did player said and put in here


Kafka

Recommended Posts

Hello, I've got a question:

How to get, what did player said and send it to TextSpeech resource?

I tried to write some scripts, but every failed - text wasn't readed and /debugscript 3 haven't show any errors.

If i made any language mistakes, excuse me.

Thanks in advance - Kafka.

Link to comment

I'm rather looking for ready-made solution, but if it would help.. (I don't know, is it that script, which hadn't show errors, because I deleted that)

  
function playerChat() 
    local message = () 
    exports.textspeech:speak( ..message, en ) //Here little edit, error in pasting 
    outputChatBox ( "Message:" ..message.. "." ) 
end 
addEventHandler( "onPlayerChat", playerChat ) 
  

Sth like it.

Edited by Guest
Link to comment

It is full script. If you want to see TextSpeech resource, here it is:

Client:

--// 
--|| TextSpeech Resource 
--|| Author:    x0rh4x 
--|| Date:      15th October 2011 
--|| Time:      04:45 UTC+2 
--\\ 
  
--// 
--|| [url=http://translate.google.com/translate_tts?tl=en&q=Hello]http://translate.google.com/translate_tts?tl=en&q=Hello[/url] World! 
--|| Limited to 100 chars by Google 
--\\ 
addEvent("speak", true); 
addEventHandler("speak", root, function(text, lang) 
    if(type(text) == "string" and type(lang) == "string") then 
        return playSound("http://translate.google.com/translate_tts?tl="..lang.."&q="..text, false) ~= false; 
    end 
    return false; 
end) 
  
--// 
--|| Syntax: bool speak(string text, string lang) 
--|| 
--|| Required Arguments: 
--||  - text: Limited to 100 chars. 
--||  - lang: Language code E.g. "en", "de", ... (Note: not every language is supported.) 
--|| 
--|| Returns: 
--||  - Returns true if the sound gets played, false if invalid arguments were specified. 
--\\ 
function speak(text, lang) 
    if(text and type(text) == "string" and type(lang) == "string") then 
        local cancelled = triggerEvent("onClientSpeech", root, text, lang); 
        if(not cancelled) then 
            return triggerEvent("speak", root, text, lang); 
        end 
    end 
    return false; 
end 

Server:

--// 
--|| TextSpeech Resource 
--|| Author:    x0rh4x 
--|| Date:      15th October 2011 
--|| Time:      04:45 UTC+2 
--\\ 
  
--// 
--|| Syntax: bool speak(string text, string lang [, triggerFor]) 
--|| 
--|| Required Arguments: 
--||  - text: Limited to 100 chars. 
--||  - lang: Language code E.g. "en", "de", ... (Note: not every language is supported.) 
--||  - triggerFor: By default this is the root element. 
--|| 
--|| Returns: 
--||  - Returns true if the event was triggered sucessfully. 
--\\ 
function speak(text, lang, triggerFor) 
    if(text and type(text) == "string" and type(lang) == "string") then 
        if(triggerFor == nil) then  
            triggerFor = root 
        end 
        if(isElement(triggerFor) and getElementType(triggerFor) == "player" or getElementType(triggerFor) == "root") then 
            local cancelled = triggerEvent("onSpeech", triggerFor, text, lang); 
            if(not cancelled) then 
                return triggerClientEvent(triggerFor, "speak", resourceRoot, text, lang); 
            end 
        end 
    end 
    return false; 
end 

Meta:

<meta> 
    <info name="TextSpeech" description="TextToSpeech" author="x0rh4x" type="script" version="1.0"/> 
    <script src="server.lua" type="server"/> 
    <script src="client.lua" type="client"/> 
     
    <export function="speak"/> 
    <export function="speak" type="client"/> 
</meta> 

Link to comment

You better take some Lua tutorial, the comment in Lua is --.

  
function playerChat(message) 
    exports.textspeech:speak( message, "en" ) --Here little edit, error in pasting 
    outputChatBox ( "Message:" ..message.. "." ) 
end 
addEventHandler( "onPlayerChat", root,playerChat ) 
  

If it's TextSpeech you need to edit the exports line, and change textspeech to TextSpeech.

Link to comment

Changing textspeech in TextSpeech nothing changed. I see, that is difficult, so start with something easier: saying the text and player nick (ex. Welcome Kafka!) after joining the server (So far, the script didn't say anything -.-). Thanks JR10, I'll read more about Lua ;) .

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...