Skip to content

MichTronics76/TsPy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TsPy - TeamSpeak 3 Plugin with Python Scripting

A professional TeamSpeak 3 client plugin with embedded Python scripting engine, audio monitoring, and event system.

🎯 Overview

TsPy is a feature-rich TeamSpeak 3 plugin that brings Python scripting capabilities to your TeamSpeak client. Write custom scripts to automate tasks, respond to events, and create interactive audio monitoring tools.

Key Features

  • 🐍 Python 3.10+ Integration - Full embedded Python interpreter with custom ts3api module
  • 🎀 Audio Monitoring - Real-time audio level visualization with PyGame UI
  • πŸ“‘ Event System - React to TeamSpeak events (connections, messages, talk status, etc.)
  • βš™οΈ Command System - Extensible command handling with /tspy commands
  • πŸ—οΈ Modern Architecture - Clean, modular C11 codebase with CMake build system
  • πŸ“Š Comprehensive Logging - Professional logging system for debugging

πŸ“‹ Requirements

Build Requirements

  • CMake 3.20 or higher
  • Visual Studio 2022 (MSVC 19.39+)
  • TeamSpeak 3 Client (API version 26)
  • Python 3.10+ (development libraries)

Runtime Requirements

  • TeamSpeak 3 Client
  • Python 3.10+ (installed on system)
  • PyGame (for audio monitor): pip install pygame

πŸš€ Quick Start

Building the Plugin

# Clone or navigate to the project directory
cd E:\Projects\HamRadio\TsPy

# Configure CMake (first time only)
cmake -S . -B build -G "Visual Studio 17 2022" -A x64

# Build the plugin
cmake --build build --config Release

# Install to TeamSpeak plugins folder
.\install.ps1

Using the Plugin

  1. Start TeamSpeak - The plugin loads automatically
  2. Check status: /tspy status in chat
  3. Load a script: /tspy python load <script_name>
  4. Try audio monitor: /tspy python load audio_monitor

🐍 Python Scripting

Available API Functions

The ts3api module provides these functions:

import ts3api

# Information
client_id = ts3api.get_client_id(server_id)
name = ts3api.get_client_name(server_id, client_id)

# Messaging
ts3api.print_message("Hello TeamSpeak!")
ts3api.send_channel_message(server_id, "Hello channel!")
ts3api.send_server_message(server_id, "Hello server!")

# Audio (v1.5.0+)
level = ts3api.get_audio_level(server_id)  # Returns dB (-60 to 0)
ts3api.start_recording(server_id)
ts3api.stop_recording(server_id)

# Logging
ts3api.log("Debug message", level=0)  # 0=INFO, 1=WARNING, 2=ERROR

Event Handlers

Your scripts can implement these event handlers:

def on_connect(server_id, client_id):
    """Called when you connect to a server"""
    print(f"Connected to server {server_id}")

def on_disconnect(server_id):
    """Called when you disconnect from a server"""
    print(f"Disconnected from server {server_id}")

def on_client_move(server_id, client_id, old_channel, new_channel):
    """Called when a client moves channels"""
    print(f"Client {client_id} moved to channel {new_channel}")

def on_text_message(server_id, from_id, to_id, target_mode, message):
    """Called when a text message is received"""
    print(f"Message from {from_id}: {message}")

def on_talk_status_change(server_id, status, client_id):
    """Called when someone starts/stops talking"""
    if status == 1:  # STATUS_TALKING
        print(f"Client {client_id} started talking")

Example Scripts

Simple Greeter

# greeter.py
import ts3api

def on_connect(server_id, client_id):
    ts3api.send_channel_message(server_id, "Hello everyone! πŸ‘‹")

Echo Bot

# echobot.py
import ts3api

def on_text_message(server_id, from_id, to_id, target_mode, message):
    if not "(auto-reply from Python)" in message:
        reply = f"Echo: {message} (auto-reply from Python)"
        ts3api.send_channel_message(server_id, reply)

🎀 Audio Monitor

The audio_monitor.py example script provides a real-time audio monitoring UI:

Features

  • VU Meter - Real-time microphone level visualization (-60dB to 0dB)
  • Color Coding - Green (safe), Yellow (loud), Red (clipping)
  • Recording Control - Click button to start/stop voice recording
  • Talk Status - Live list of currently talking clients with indicators

Usage

First, copy the example to your scripts folder:

Copy-Item "examples\audio_monitor.py" "$env:APPDATA\TS3Client\plugins\scripts\"

Then load it in TeamSpeak:

/tspy python load audio_monitor

A PyGame window opens showing real-time audio monitoring. Press ESC or close the window to exit.

Requirements

pip install pygame

πŸ“š More Examples

Check the examples/ directory for more Python scripts:

  • auto_greeter.py - Automatic welcome messages
  • callsign_logger.py - Ham radio callsign logger
  • hello_world.py - Basic example script

See examples/README.md for detailed documentation.

βš™οΈ Commands

Command Description
/tspy help Show available commands
/tspy status Show plugin status
/tspy python status Show Python engine status
/tspy python load <script> Load a Python script
/tspy python reload <script> Reload a running script
/tspy python unload <script> Unload a script

πŸ“ Project Structure

TsPy/
β”œβ”€β”€ CMakeLists.txt                 # Build configuration
β”œβ”€β”€ CMakePresets.json              # VS2022 presets
β”œβ”€β”€ README.md                      # This file
β”‚
β”œβ”€β”€ include/                       # TeamSpeak SDK headers
β”‚   β”œβ”€β”€ ts3_functions.h
β”‚   β”œβ”€β”€ plugin_definitions.h
β”‚   └── teamspeak/
β”‚
β”œβ”€β”€ src/                           # Source code
β”‚   β”œβ”€β”€ core/                      # Core plugin
β”‚   β”‚   β”œβ”€β”€ plugin_main.c/h
β”‚   β”‚   β”œβ”€β”€ plugin_interface.c/h
β”‚   β”‚   └── plugin_config.c/h
β”‚   β”‚
β”‚   β”œβ”€β”€ commands/                  # Command system
β”‚   β”‚   β”œβ”€β”€ command_handler.c/h
β”‚   β”‚   └── python_commands.c/h
β”‚   β”‚
β”‚   β”œβ”€β”€ events/                    # Event handlers
β”‚   β”‚   β”œβ”€β”€ connection_events.c/h
β”‚   β”‚   β”œβ”€β”€ channel_events.c/h
β”‚   β”‚   └── client_events.c/h
β”‚   β”‚
β”‚   β”œβ”€β”€ python/                    # Python engine
β”‚   β”‚   β”œβ”€β”€ python_engine.c/h
β”‚   β”‚   β”œβ”€β”€ python_api.c/h
β”‚   β”‚   └── python_events.c/h
β”‚   β”‚
β”‚   β”œβ”€β”€ ui/                        # User interface
β”‚   β”‚   β”œβ”€β”€ menu_handler.c/h
β”‚   β”‚   └── hotkey_handler.c/h
β”‚   β”‚
β”‚   └── utils/                     # Utilities
β”‚       β”œβ”€β”€ logging.c/h
β”‚       └── string_utils.c/h
β”‚
β”œβ”€β”€ scripts/                       # Python scripts location
β”‚   └── tspy_init.py              # Auto-loaded on startup
β”‚
β”œβ”€β”€ examples/                      # Example Python scripts
β”‚   β”œβ”€β”€ README.md                 # Examples documentation
β”‚   β”œβ”€β”€ audio_monitor.py          # Audio monitoring UI
β”‚   β”œβ”€β”€ auto_greeter.py           # Welcome message bot
β”‚   β”œβ”€β”€ callsign_logger.py        # Ham radio callsign logger
β”‚   └── hello_world.py            # Basic example
β”‚
└── resources/                     # Resources
    └── icons/                     # Plugin icons

πŸ”§ Building from Source

1. Prerequisites

Install the required tools:

  • Visual Studio 2022 with C++ desktop development workload
  • CMake 3.20+ (cmake.org)
  • Python 3.10+ with development libraries (python.org)

2. Configure CMake

cmake -S . -B build -G "Visual Studio 17 2022" -A x64

CMake will automatically find your Python installation.

3. Build

# Release build (recommended)
cmake --build build --config Release

# Debug build (for development)
cmake --build build --config Debug

4. Install

# Automatic installation
.\install.ps1

# Manual installation
Copy-Item "build\bin\Release\tspy_plugin.dll" "$env:APPDATA\TS3Client\plugins\"

5. Verify

  1. Start TeamSpeak
  2. Go to Plugins menu
  3. Look for "TsPy Plugin" with Python version in description
  4. Type /tspy status in any chat

πŸ› Troubleshooting

Plugin doesn't load

  • Make sure TeamSpeak is completely closed before installing
  • Check the TeamSpeak client log: %APPDATA%\TS3Client\logs\
  • Verify Python 3.10+ is installed and in PATH

Python scripts don't work

  • Verify Python engine status: /tspy python status
  • Check plugin log: %APPDATA%\TS3Client\plugins\tspy_plugin.log
  • Ensure scripts are in: %APPDATA%\TS3Client\plugins\scripts\

Audio monitor issues

  • Install pygame: pip install pygame
  • Check microphone permissions in TeamSpeak
  • Verify you're connected to a server

Build errors

  • Ensure Visual Studio 2022 is installed
  • Update CMake to latest version
  • Verify Python development libraries are installed
  • Check Python version: python --version

πŸ“Š Version History

v1.5.0 (Current) - Audio Monitoring

  • βœ… Audio API: get_audio_level, start_recording, stop_recording
  • βœ… Talk status events for real-time speaker detection
  • βœ… PyGame audio monitor with VU meter and recording control
  • βœ… Color-coded visualization of audio levels

v1.4.0 - Event System Complete

  • βœ… Full event dispatcher for Python scripts
  • βœ… 6 event types: connect, disconnect, client_move, text_message, talk_status
  • βœ… Proper DLL export of TeamSpeak callbacks
  • βœ… Loop prevention for bot messages

v1.3.1 - Python Commands

  • βœ… /tspy python command system
  • βœ… Script loading/reloading/unloading
  • βœ… Python engine status reporting

v1.3.0 - Python Integration

  • βœ… Embedded Python 3.10+ interpreter
  • βœ… Custom ts3api module with TeamSpeak functions
  • βœ… Event callback system for Python scripts
  • βœ… Auto-loading of tspy_init.py

v1.2.0 - Modular Rewrite

  • βœ… CMake build system with VS2022 support
  • βœ… Modular architecture (28 files)
  • βœ… Professional logging system
  • βœ… Command and event handling

v1.0.0 - Initial Release

  • βœ… Basic TeamSpeak plugin functionality
  • βœ… Menu and hotkey support

πŸ“ License

This project is provided as-is for use with TeamSpeak 3. See TeamSpeak's plugin development guidelines for usage terms.

🀝 Contributing

This is a personal project, but suggestions and improvements are welcome!

πŸ“§ Support

For issues or questions:

  1. Check the Troubleshooting section above
  2. Review the plugin log file
  3. Check TeamSpeak client logs

πŸ”— Resources


Made with ❀️ for the TeamSpeak and Ham Radio communities

About

A feature-rich TeamSpeak 3 plugin with embedded Python 3.10+ interpreter. Create custom scripts to automate tasks, respond to events (connections, messages, talk status), and monitor audio in real-time. Includes PyGame-based audio monitor with VU meter and recording control. Built with modern C11 and CMake for VS2022.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors