samp.directory
← Scripts y librerías

roseeast/PawnTTS

Real-time clientless text-to-speech and 3D spatial voice streamer for SA-MP legacy plugins and native open.mp components.

Plugin★ 1actualizado hace 40 díasMITC++
Abrir en GitHub

README.md


Pawn TTS brings real-time, clientless text-to-speech (TTS) and spatial audio streaming to SA-MP and open.mp Pawn servers. Players on standard PC (GTA: San Andreas) and Android mobile launchers do not require any client modifications, ASI plugins, or external software. Audio is streamed natively through the GTA audio engine via PlayAudioStreamForPlayer with full 3D spatial sound (distance attenuation and stereo panning).

Overview

ItemDetail
Plugin namepawn_tts
TargetSA-MP (0.3.7) and open.mp
Plugin typeLegacy SA-MP plugin API & Native open.mp Component
LanguageC++17
Audio streamingNative HTTP chunked/range audio stream (audio/mpeg)
Default HTTP port7788
Default TTS voiceMicrosoft Edge voice ID (en-US-GuyNeural by default)
Default providerEdge provider ID with Google legacy as optional fallback
ProvidersElevenLabs, Edge TTS, Kokoro, Piper, Custom HTTP, Google legacy fallback
Caching engineRAM LRU cache + Disk caching with SHA-256 deduplication
Included platformsLinux x86_64, Linux x86 (32-bit), Windows x86 (32-bit)
Pawn includepawno/include/pawn_tts.inc

Features

FeatureNative / StockNotes
Check engine statusTTS_IsReadyReturns true if the HTTP stream server and audio engine are running.
Get streaming URLTTS_GetBaseURLRetrieves the active base stream URL (e.g. http://ip:7788/audio/).
Set public URLTTS_SetPublicURLOverrides the public URL (useful behind reverse proxies, NAT, or domain names).
Private speechTTS_SpeakStreams voice privately to a single player in 2D stereo.
Broadcast speechTTS_SpeakToAllStreams voice to all connected players simultaneously.
3D spatial speechTTS_SpeakAtPosPlays 3D positioned voice at world coordinates (X, Y, Z) with falloff distance.
3D speech for playerTTS_SpeakAtPosForPlayerPlays positioned 3D voice audible only to a targeted player.
Player body audioTTS_SpeakFromPlayerPlays 3D voice originating directly from a player's physical coordinate.
Stop player audioTTS_StopImmediately stops any active speech stream for a player.
Stop all audioTTS_StopAllImmediately stops active speech streams for all players.
Pre-cache audioTTS_PrecacheAsynchronously generates and caches frequent phrases for instant 0 ms playback.
Check cached statusTTS_IsCachedChecks if a phrase has already been synthesized and cached.
Cache statisticsTTS_GetStatsQueries memory cache count, disk cache count, and total cache size in KB.
Purge cacheTTS_ClearCacheClears memory and optionally disk audio cache.
Set providerTTS_SetProviderSelects ElevenLabs, Edge, Kokoro, Piper, Custom, or Google legacy.
Request controlTTS_CancelCancels queued requests and marks active requests cancelled when possible.
Request stateTTS_GetRequestStateQueries queued, processing, completed, failed, or cancelled state.
Synthesis callbackOnTTSGeneratedCalled when a speech synthesis request finishes generating.
Modern callbackOnTTSGeneratedExIncludes request ID, player ID, provider, and audio URL.
Playback callbackOnTTSReadyDispatches audio stream to the client via PlayAudioStreamForPlayer.

Release Files

Prebuilt release packages are available in release/.

FileFormatContents
release/pawn-tts-v0.2.0-windows-x86.zipZIPWindows 32-bit release archive (legacy plugin & native component).
release/pawn-tts-v0.2.0-linux-x86.zipZIPLinux 32-bit release archive (legacy plugin & native component).
release/pawn-tts-v0.2.0-linux-x86_64.tar.gztar.gzLinux 64-bit release archive (legacy plugin & native component).
release/pawn-tts-v0.2.0.zipZIPUniversal bundle containing all platforms and examples.

Package layout:

pawn-tts-v0.2.0/
  plugins/
    pawn_tts.so
    pawn_tts.dll
  components/
    pawn_tts.so
    pawn_tts.dll
  pawno/include/
    pawn_tts.inc
  examples/
    example.pwn
    commands.pwn
  pawn_tts.json
  README.md
  LICENSE

Compatibility

RuntimeStatusNotes
SA-MP Windows serverSupportedUse plugins/pawn_tts.dll (32-bit for classic SA-MP Windows servers).
SA-MP Linux serverSupportedUse plugins/pawn_tts.so (32-bit x86 for classic SA-MP Linux servers).
open.mp Windows serverSupported (Component & Plugin)Native component: components/pawn_tts.dll. Legacy plugin: plugins/pawn_tts.dll.
open.mp Linux serverSupported (Component & Plugin)Native component: components/pawn_tts.so. Legacy plugin: plugins/pawn_tts.so.
Android SA-MP clientsSupportedFully clientless; streams through native GTA audio stream engine.
PC SA-MP clientsSupported100% stock GTA San Andreas client, no ASI plugins required.

Pawn TTS does not hook RakNet, patch memory, or depend on internal server offsets. It registers standard Pawn natives and runs a high-performance HTTP stream listener to deliver audio directly to GTA game clients.

Installation

1. Install Files

For SA-MP (Legacy Plugin)

Copy the files into your server directory:

plugins/pawn_tts.so        -> Linux server plugins folder (use x86 32-bit for classic SA-MP)
plugins/pawn_tts.dll       -> Windows server plugins folder
pawno/include/pawn_tts.inc -> Pawn compiler include folder
pawn_tts.json              -> Server root folder
For open.mp (Native Component - Recommended)

Copy the files into your server directory:

components/pawn_tts.so     -> Linux server components folder
components/pawn_tts.dll    -> Windows server components folder
pawno/include/pawn_tts.inc -> Pawn compiler include folder
pawn_tts.json              -> Server root folder

For Qawno or custom build systems, place pawn_tts.inc in the include path used by your compiler.

2. Load The Plugin / Component

For SA-MP server.cfg:
plugins pawn_tts

On Linux setups where explicit extensions are required:

plugins pawn_tts.so
For open.mp config.json (Native Component Mode - Recommended):
{
  "components": [
    "pawn_tts"
  ]
}
For open.mp config.json (Legacy Plugin Mode):
{
  "pawn": {
    "legacy_plugins": ["pawn_tts"]
  }
}

3. Include In Pawn

#include <pawn_tts>

Quick Start

#include <a_samp>
#include <pawn_tts>

public OnGameModeInit()
{
    // Pre-cache frequent phrases for instant 0 ms playback
    TTS_SetProvider(TTS_PROVIDER_EDGE);
    TTS_SetVoice("en-US-GuyNeural");
    TTS_Precache("Welcome to the server!");
    return 1;
}

public OnPlayerConnect(playerid)
{
    // Private 2D stereo welcome greeting
    new requestid = TTS_Speak(playerid, "Welcome to Los Santos.");
    printf("[TTS] queued request %d", requestid);
    return 1;
}

// 3D Proximity Voice Chat: speech originates from the player character in world space
public OnPlayerText(playerid, text[])
{
    TTS_SpeakFromPlayer(playerid, text, "id", 25.0);
    return 1;
}

Native API

NativeSignatureReturnDescription
TTS_IsReadynoneboolChecks whether the HTTP server and audio engine are initialized.
TTS_GetBaseURLoutput[], maxlen = sizeof(output)1Copies the current base streaming URL into the output string.
TTS_SetPublicURLconst url[]1Dynamically overrides the public streaming URL.
TTS_SetProviderprovider1Changes the default provider for future requests.
TTS_GetProvidernoneproviderReturns the current default provider ID.
TTS_SetVoiceconst voice[]1Sets the default voice ID/name.
TTS_GetVoicedestination[], size1Copies the current default voice.
TTS_SetModelconst model[]1Sets the default model name/path.
TTS_SetSpeedFloat:speed1Sets the default speech speed.
TTS_SetPitchFloat:pitch1Sets the default pitch where the provider supports it.
TTS_SetVolumeFloat:volume1Sets the default volume where the provider supports it.
TTS_SetOptionconst key[], const value[]1Sets a provider-specific option for future requests.
TTS_Precacheconst text[], const voice[] = "", Float:speed = 1.0request IDSynthesizes and caches an audio phrase in the background without playing it.
TTS_IsCachedconst text[], const voice[] = "", Float:speed = 1.0boolChecks whether a phrase is already available in memory or disk cache.
TTS_ClearCachebool:clear_disk = false1Clears memory cache (and optionally disk cache).
TTS_GetStats&cached_mem, &cached_disk, &total_bytes_kb1Retrieves current cache counts and total memory footprint in KB.
TTS_Speakplayerid, const text[], const voice[] = "", Float:speed = 1.0request IDPlays private 2D stereo audio directly to a player.
TTS_SpeakExplayerid, const text[], provider, const voice[] = "", const model[] = "", Float:speed = 1.0, Float:pitch = 0.0, Float:volume = 1.0request IDQueues speech with per-request provider, voice, model, speed, pitch, and volume.
TTS_SpeakToAllconst text[], const voice[] = "", Float:speed = 1.0request IDBroadcasts audio to all connected players on the server.
TTS_SpeakAtPosconst text[], const voice[] = "", Float:x, Float:y, Float:z, Float:distance = 30.0, Float:speed = 1.0request IDPlays 3D spatial audio at specific world coordinates with distance falloff.
TTS_SpeakAtPosForPlayerplayerid, const text[], const voice[] = "", Float:x, Float:y, Float:z, Float:distance = 30.0, Float:speed = 1.0request IDPlays 3D spatial audio at specific coordinates audible only to a targeted player.
TTS_CancelrequestidboolCancels a queued request and marks active work cancelled when the worker observes it.
TTS_IsRequestActiverequestidboolReturns whether a request is queued or processing.
TTS_GetRequestProviderrequestidproviderReturns the provider used by a request.
TTS_GetRequestStaterequestidstateReturns queued, processing, completed, failed, or cancelled.
TTS_GetVoiceCountprovidercountReturns the cached/static voice count known by a provider.
TTS_SpeakFromPlayerspeakerid, const text[], const voice[] = "id", Float:distance = 25.0, Float:speed = 1.0boolPlays 3D spatial audio emanating from a player's character body.
TTS_Stopplayerid1Stops any active audio stream for a specific player.
TTS_StopAllnone1Stops active audio streams for all connected players.

Callbacks

forward OnTTSGenerated(const hash[], const text[], const voice[], bool:success);
forward OnTTSRequestQueued(requestid, playerid, provider);
forward OnTTSGeneratedEx(requestid, playerid, provider, const audio_url[]);
forward OnTTSError(requestid, playerid, provider, error_code, const error_message[]);
forward OnTTSCacheHit(requestid, playerid, const cache_key[]);
forward OnTTSFallback(requestid, playerid, old_provider, new_provider);
forward OnTTSReady(playerid, const hash[], const url[], Float:x, Float:y, Float:z, Float:distance, usepos);

OnTTSGenerated

Called asynchronously when a speech synthesis request finishes:

public OnTTSGenerated(const hash[], const text[], const voice[], bool:success)
{
    if (success) {
        printf("[TTS] Audio generated: hash=%s voice=%s", hash, voice);
    }
    return 1;
}

OnTTSReady

Dispatched automatically by the include hook to play audio via PlayAudioStreamForPlayer. If you define TTS_OnTTSReady, you can customize or filter stream playback before dispatch.

Configuration

Configuration is managed via pawn_tts.json in the server root folder:

{
  "port": 7788,
  "bind_ip": "0.0.0.0",
  "public_url": "",
  "provider": "edge",
  "default_voice": "en-US-GuyNeural",
  "default_model": "",
  "default_speed": 1.0,
  "default_pitch": 0.0,
  "default_volume": 1.0,
  "worker_threads": 2,
  "cache_dir": "cache/tts",
  "cache_memory_limit": 256,
  "edge_enabled": true,
  "edge_command": "",
  "elevenlabs_enabled": false,
  "elevenlabs_api_key_env": "ELEVENLABS_API_KEY",
  "elevenlabs_command": "",
  "kokoro_enabled": false,
  "kokoro_command": "",
  "piper_enabled": false,
  "piper_command": "",
  "custom_enabled": false,
  "custom_http_url": "http://127.0.0.1:5000/tts",
  "google_legacy_enabled": true
}
KeyTypeDefaultDescription
portInteger7788Port for the embedded HTTP audio server.
bind_ipString"0.0.0.0"Network interface to bind the HTTP server.
public_urlString""Public base URL sent to clients (e.g. "http://play.example.com:7788"). If empty, auto-detects from client connection.
providerString"edge"Default provider ("elevenlabs", "edge", "kokoro", "piper", "custom", or "google_legacy").
default_voiceString"en-US-GuyNeural"Default provider voice ID.
default_modelString""Default provider model name/path.
default_speedNumber1.0Default speech speed.
default_pitchNumber0.0Default pitch value where supported.
default_volumeNumber1.0Default volume value where supported.
worker_threadsInteger2Number of background synthesis workers.
cache_dirString"cache/tts"Directory path for persistent MP3 disk cache.
cache_memory_limitInteger256Maximum memory cache size in megabytes (MB).
*_enabledBooleanvariesEnables a provider. Google legacy is fallback-only and is not the default provider.
*_commandString""Optional command adapter for Edge, ElevenLabs, Kokoro, or Piper. Supports {text}, {voice}, {model}, {output}, {request_id}, {speed}, {pitch}, and {volume}.
custom_http_urlString""Endpoint URL when using custom or local HTTP TTS engines.

The C++ core now uses a provider interface internally. Edge, Kokoro, Piper, and ElevenLabs are isolated provider modules; this repository currently exposes them through command/config adapters unless you wire a native backend in the provider module. ElevenLabs API keys must come from an environment variable such as ELEVENLABS_API_KEY and are never exposed to Pawn.

3D Spatial Audio Mechanics

When using TTS_SpeakAtPos or TTS_SpeakFromPlayer, audio streams leverage GTA San Andreas's built-in BASS audio engine:

  • Distance Falloff: Audio volume decreases smoothly from the center coordinate out to the configured radius (distance).
  • Stereo Panning: Audio dynamically pans between the player's left and right audio channels based on their camera and character orientation relative to the sound source.
  • Client Compatibility: Fully operational on standard PC GTA:SA clients and official Android mobile launchers without any custom .asi or APK modifications.

Build From Source

This repository uses CMake (version 3.20+).

Requirements

TargetRequirement
Linux .so (x86_64)CMake 3.20+, C++17 compiler (g++ / clang++)
Linux .so (x86 32-bit)CMake 3.20+, Multilib 32-bit C++ compiler (g++ -m32)
Windows .dll (x86 32-bit)CMake 3.20+, MinGW toolchain (i686-w64-mingw32-g++-posix) or MSVC

Linux (Native x86_64)

cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release

Output:

  • build/plugins/pawn_tts.so (Legacy SA-MP plugin)
  • build/components/pawn_tts.so (Native open.mp component)

Linux (32-bit x86 for Classic SA-MP)

cmake -B build-linux-x86 -S . \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_CXX_FLAGS="-m32" \
  -DCMAKE_SHARED_LINKER_FLAGS="-m32"
cmake --build build-linux-x86 --config Release

Output:

  • build-linux-x86/plugins/pawn_tts.so (Legacy SA-MP plugin)
  • build-linux-x86/components/pawn_tts.so (Native open.mp component)

Windows (Cross-compile with MinGW)

cmake -B build-win -S . \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_C_COMPILER=i686-w64-mingw32-gcc-posix \
  -DCMAKE_CXX_COMPILER=i686-w64-mingw32-g++-posix
cmake --build build-win --config Release

Output:

  • build-win/plugins/pawn_tts.dll (Legacy SA-MP plugin)
  • build-win/components/pawn_tts.dll (Native open.mp component)

Troubleshooting

ProblemFix
Failed (plugins/pawn_tts.so: wrong ELF class: ELFCLASS64)Standard SA-MP Linux server is 32-bit. Use the 32-bit Linux binary from build-linux-x86/plugins/pawn_tts.so or release/pawn-tts-v0.2.0-linux-x86.zip.
Failed (plugins/pawn_tts.so: cannot open shared object file)Verify that pawn_tts.so is inside your plugins/ directory and referenced correctly in server.cfg.
Players cannot hear speechEnsure TCP port 7788 is open in your firewall/security group, or configure "public_url" in pawn_tts.json with your server's reachable public IP or domain.
Audio stream cuts off or stuttersIncrease "cache_memory_limit" in pawn_tts.json and use TTS_Precache during OnGameModeInit for frequently repeated server phrases.
undefined symbol: TTS_Speak while compiling PawnEnsure pawn_tts.inc is placed in pawno/include/ and #include <pawn_tts> is present after #include <a_samp>.

License

Pawn TTS is released under the MIT License.

audio-streamingopenmppawnpawn-packagesa-mpsa-mp-librarysa-mp-pluginspatial-audiotext-to-speechtts

Esta página se genera con lo que GitHub publica sobre el repositorio. samp.directory no aloja el código. Informar de un problema con esta ficha