I made this stock for use a "Text To Speech" feature in SourceMod easily.
Stocks:
PHP Code:
/**
* Sent text to speech to a client
*
* @param client Client target.
* @param language Language of voice.
* @param text Text to reproduce.
*
*/
stock void VoiceWare(int client, char[] language, char[] text)
{
ReplaceString(text, 255, "&", ""); // prevent error
char buffer[255];
Format(buffer, sizeof(buffer), "https://translate.google.com/translate_tts?ie=UTF-8&q=%s&tl=%s&client=tw-ob&ttsspeed=1.0", text, language); // use google traductor TTS
Handle Radio = CreateKeyValues("data");
KvSetString(Radio, "title", "Voice Ware");
KvSetString(Radio, "type", "2");
KvSetString(Radio, "msg", buffer);
ShowVGUIPanel(client, "info", Radio, false);
CloseHandle(Radio);
}
/**
* Sent text to speech to all clients
*
* @param language Language of voice.
* @param text Text to reproduce.
*
*/
stock void VoiceWareToAll(char[] language, char[] text)
{
for (int i = 1; i <= MaxClients; i++)
if(IsClientInGame(i))
VoiceWare(i, language, text);
}
Example plugin:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <voiceware>
#define LANGUAGE "en" // language voice used
public Plugin myinfo =
{
name = "SM Chat text to voice",
description = "Text to voice",
author = "Franc1sco franug",
version = "1.0",
url = "http://steamcommunity.com/id/franug"
};
public void OnPluginStart()
{
RegConsoleCmd("say", Say);
}
public Action Say(int client, int args)
{
if (client!=0)
{
char buffer[255];
GetCmdArgString(buffer,sizeof(buffer));
StripQuotes(buffer);
VoiceWareToAll(LANGUAGE, buffer);
}
return Plugin_Continue;
}