# Echoion Music Bot A modern music bot for TeamSpeak 3, featuring YouTube integration, playlist support, and hot-reload capabilities. ## Features - 🎡 **YouTube Integration** - Play music directly from YouTube URLs or search queries via a native innertube client (fastest path) with yt-dlp as the resolver/fallback - 🎢 **Two Catalogs** - Search and play from YouTube and Yandex Music (native, full tracks with a Plus token). `!play` searches both; `!pyt`/`!pya` target one. Direct audio URLs / radio streams and other yt-dlp extractors (SoundCloud, Bandcamp, VK, …) also work - ⚑ **Hedged Resolution** - A slow source is raced by the next candidate after 300ms; first success wins - πŸ” **Gapless Playback & Crossfade** - The next track's decoder is pre-warmed while the current one plays; optional crossfade (`bot.crossfade`) - πŸ”Š **Loudness Normalization** - Optional slow AGC evens out quiet/loud tracks (`features.normalizeLoudness`) - πŸ“» **Autoplay / Radio Mode** - When the queue runs dry, `!radio` keeps the music going with related tracks from YouTube or Yandex (`features.autoplay`) - πŸ’Ύ **Track Cache** - Downloaded audio is reused across plays and restarts (`advanced.cache*`) - ⭐ **History & Favorites** - `!history`, `!stats`, `!fav add|list|play` backed by SQLite - πŸ“‹ **Playlist Support** - Queue management with shuffle, repeat, and skip functionality - 🎧 **High Quality Audio** - 192kHz stereo internal pipeline - πŸ”„ **Hot Reload** - Update the bot without disconnecting from the server - βš™οΈ **Configurable** - JSON-based configuration system - πŸ”Š **TeamSpeak Native** - Uses TeamSpeak's native audio system for best quality ## Building ### Requirements - C++26 compatible compiler with reflections (GCC 16+) - CMake 4.0+ - Qt6 (for desktop client) - FFmpeg (for audio decoding) - Boost (system installation preferred; the build vendors one only when absent β€” mixing a vendored and a system Boost in one process breaks boost.url) - TeamSpeak 3 Client SDK ### Build Instructions ```bash mkdir build && cd build cmake .. cmake --build . ``` ### Tests ```bash cmake .. -DBUILD_TESTS=ON cmake --build . && ctest ``` The suite covers the decoder (against generated audio fixtures), the queue and shuffle bookkeeping, the gapless playback engine (asserting a seamless track boundary), and the source router (fall-through, hedging and stream caching). ## Configuration Copy `config.example.json` to your config directory: - **Linux**: `~/.config/echoion/config.json` - **Windows**: `%APPDATA%\echoion\config.json` - **macOS**: `~/Library/Application Support/echoion/config.json` Edit the configuration file with your server details: ```json { "server": { "address": "your.server.com", "port": 9987, "nickname": "MusicBot", "serverPassword": "" } } ``` ## Installation ### TeamSpeak Plugin 1. Build the project 2. Copy the plugin to your TeamSpeak plugins folder: - **Linux**: `~/.ts3client/plugins/` - **Windows**: `%APPDATA%\TS3Client\plugins\` 3. Enable the plugin in TeamSpeak's plugins menu ## Commands All commands use the configured prefix (default: `!`) | Command | Description | Example | |---------|-------------|---------| | `!play ` | Play a song or add to queue | `!play never gonna give you up` | | `!pause` | Pause playback | `!pause` | | `!resume` | Resume playback | `!resume` | | `!stop` | Stop playback | `!stop` | | `!skip` | Skip current track | `!skip` | | `!seek <+/-secs>` | Seek within the track | `!seek +30` | | `!queue` | Show current queue | `!queue` | | `!clear` | Clear the queue | `!clear` | | `!shuffle` | Toggle shuffle mode | `!shuffle` | | `!repeat` | Toggle repeat mode | `!repeat` | | `!volume <0-100>` | Set volume | `!volume 50` | | `!nowplaying` | Show current track | `!nowplaying` | | `!search ` | Search YouTube + Yandex Music | `!search daft punk` | | `!youtube ` | Search YouTube only (alias `yb`, `yt`) | `!yb daft punk` | | `!yandex ` | Search Yandex Music only (alias `ya`) | `!ya Π³Ρ€ΠΈΠ±Ρ‹` | | `!history [n]` | Recently played tracks | `!history 15` | | `!stats` | Playback statistics | `!stats` | | `!fav add\|list\|play ` | Manage your favorites | `!fav play 2` | | `!announce ` | **Admin:** message all subscribers once | `!announce New update live!` | ## Architecture The bot consists of three main components: 1. **EchoionApi** - Shared interfaces and types 2. **EchoionCore** - Core music playback logic (hot-reloadable) 3. **EchoionPlugin** - TeamSpeak plugin wrapper ### Audio Flow ``` query β†’ SourceRouter (innertube β†’ Yandex β†’ direct URL β†’ yt-dlp) β†’ PlaybackEngine (dual AudioDecoder, gapless handoff) β†’ Core β†’ PluginInterface β†’ TeamSpeak ``` Audio is decoded using FFmpeg at 192kHz stereo and emitted in 20ms chunks to TeamSpeak's custom audio device by a single real-time engine thread. See `docs/09-audio-pipeline.md` for details. ## Development ### Hot Reload The core library can be hot-reloaded without disconnecting from the server: 1. Build the new core: `cmake --build . --target EchoionCore` 2. Use the "Reload Core" menu item or send plugin command `reload` ### Adding Commands To add a new command: 1. Create a new command class in `EchoionCore/src/commands/` 2. Inherit from `CommandBase` 3. Register in `CommandManager::initialize()` Example: ```cpp class MyCommand : public CommandBase { public: MyCommand() : CommandBase("mycommand", "Description") {} Api::Result execute(uint64_t clientId, const std::vector& args) override { return "Hello, World!"; } }; ``` ## Packaging and Distribution ### Using CPack The project includes CPack configuration for creating installers: ```bash cd build # Create tarball cpack -G TGZ # Create DEB package (Debian/Ubuntu) cpack -G DEB # Create RPM package (Fedora/RHEL) cpack -G RPM # Create ZIP (Windows) cpack -G ZIP # Create NSIS installer (Windows) cpack -G NSIS ``` ### Static Linking For a standalone distribution without external dependencies: ```bash cmake .. -DECHOION_STATIC_LINK=ON cmake --build . ``` Note: Some dependencies (Qt6, FFmpeg) may still require bundling. See `packaging/README.md` for detailed instructions. ### CMake Package Support The project uses [PackageProject.cmake](https://github.com/TheLartians/PackageProject.cmake) to export CMake targets: ```cmake find_package(EchoionCore REQUIRED) target_link_libraries(myapp PRIVATE Echoion::Core) ``` ## License MIT License - See LICENSE file for details ## Credits - TeamSpeak Systems GmbH for the TeamSpeak SDK - FFmpeg team for audio decoding - Glaze library for JSON handling - PackageProject.cmake for CMake packaging