[Tutorial] Making the most out of audio streaming! - Tips and tricks
#1

Basically this covers some cool things you can do with the "PlayAudioStreamForPlayer" feature.

pawn Code:
native PlayAudioStreamForPlayer(playerid, url[], Float:posX = 0.0, Float:posY = 0.0, Float:posZ = 0.0, Float:distance = 50.0, usepos = 0)
Tip 1: Using ****** translate/text to speech.

This may sound hard but it actually isn't. All you really need is the right URL addresses. Now let's break down ****** translate.

It's main URL is translate.******.com. This takes you to the general main page. The first "parameter" is the language code. This is basically two letters that correlate to a language.

For example, english would be "en". It is most likely the first letters of the language's name. After this comes the actual message being translated.

A URL saying "hello" in english would look like this,

http://translate.******.com/translate_tts?tl=en&q=hello

Now let's make a function to generate a URL. We'll make a stock function for this tutorial.

pawn Code:
stock GetTranslateURL(msg[], language[])
Now basically msg, and language are both strings. So using the stock would look like,

pawn Code:
new msg[64], language[3];
format(msg, sizeof(msg), "hello");
format(language, sizeof(language), "en");
GetTranslateURL(msg, language);
pawn Code:
stock GetTranslateURL(msg[], language[]="en")
If we do this the language will default to english and the parameter becomes optional.

pawn Code:
stock GetTranslateURL(msg[], language[]="en")
{
    new string[200]; // Declare a new string variable. We'll put 200 cells just to be safe incase the message is long.
    if(strlen(language) > 2) return -1; // The language should never be longer than 2 characters.
    format(string, sizeof(string), "http://translate.******.com/translate_tts?tl=%s&q=%s", language, msg);
    return string;
}
This would return the URL. Now to actually use it we have to get the URL and then play it as a stream. We'll make another stock to accomplish this.
pawn Code:
stock TranslateTextForPlayer(playerid, msg[], language[]="en")
{
     if(IsPlayerConnected(playerid)) // Always check if the player is connected before accessing any player functions.
     {
            if(strlen(GetTranslateURL(msg, language) > 1)
            {
                 new url[75];
                 format(url, sizeof(url), "%s", GetTranslateURL(msg, language); // Format the string using our stock.
                 PlayAudioStreamForPlayer(playerid, url);
                 return true;
             }
             else return 0;
     }
    else return INVALID_PLAYER_ID;
}
Our stock will return 1 if successful/valid input, false if GetTranslateURL is invalid and INVALID_PLAYER_ID if an invalid player id has been passed.

A list of language codes can be found below.

en - english
turkish - tr
crotian - hr
african - af
Danish - da
German - ga
Spanish - es
More can be used, how-ever I can't be bothered to list them all.

I plan on adding some more soon.
Reply


Messages In This Thread
Making the most out of audio streaming! - Tips and tricks - by Abagail - 19.10.2014, 14:56
Re: Making the most out of audio streaming! - Tips and tricks - by Lordzy - 19.10.2014, 15:59
Re: Making the most out of audio streaming! - Tips and tricks - by Abagail - 19.10.2014, 17:09

Forum Jump:


Users browsing this thread: 1 Guest(s)