19.10.2014, 14:56
(
Last edited by Abagail; 19/10/2014 at 05:10 PM.
)
Basically this covers some cool things you can do with the "PlayAudioStreamForPlayer" feature.
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.
Now basically msg, and language are both strings. So using the stock would look like,
If we do this the language will default to english and the parameter becomes optional.
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.
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.
pawn Code:
native PlayAudioStreamForPlayer(playerid, url[], Float:posX = 0.0, Float:posY = 0.0, Float:posZ = 0.0, Float:distance = 50.0, usepos = 0)
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[])
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")
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;
}
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;
}
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.