The ToxMod Server-Side SDK is designed to integrate into a voice chat server, handling multiple streams of player audio in potentially multiple voice chat rooms simultaneously. It is designed to copy mono-channel Opus packets from individual player audio streams in a realtime-safe way to an internal circular buffer, then build and upload Ogg Opus files to the ToxMod server for further analysis. The results of that analysis appear, triaged and prioritized for toxic content, in the ToxMod web console.
Included in this release is the core tox_server shared library, along with a header file tox_server.h to enable integration into a voice chat server application. Additionally, the full source code behind tox_server is included to allow for performance tweaking and profiling, as well as compilation for new platforms. Finally, two test programs program are included which simulate voice chat by running a test file (also included) through tox_server as if one or multiple players were speaking. Checking the ToxMod web console should show clips from the test file on the Livestreams page to verify that the library is functioning properly.
Please contact suppo.nosp@m.rt@m.nosp@m.odula.nosp@m.te.a.nosp@m.i with any questions, comments, or feedback.
Supported platforms for pre-compiled libraries are x86_64 Windows 10, macOSX 10.15 and later, and Linux. The pre-compiled libraries are in the lib/ subdirectory, with the following structure:
tox_server depends on the cURL and Ogg libraries, for upload functions and packing Opus packets into Ogg formatted data buffers. Additionally, building the example programs require including the Ogg header files, so installing a developer version of the Ogg library may be necessary.
The Server-Side SDK integration consists of a few moving pieces to safely move data from the realtime audio threads through to upload to the ToxMod severs:
The ToxMod Server-Side SDK comes pre-compiled for specific platforms as part of the downloaded release, however it may also be compiled from source. There is no pre-configuration required to do so beyond installing the cURL and Ogg libraries as dependencies, defining LIBTOX_SERVER_EXPORTS on Windows or TOX_SERVER_EXPORT_SHARED on other platforms for public symbol visibility, and compiling the sources in src/ along with the public header in include/.
A CMakeLists.txt file is included for convenience in building the SDK across various systems. To build using CMake, use the following commands. If building for Windows, you may need to use cmake.exe instead of cmake depending on your shell settings.
To install dependencies with VCPKG, use:
To build the SDK using VCPKG dependencies, just add the path to the VCPKG CMAKE_TOOLCHAIN_FILE:
The pre-compiled ToxMod Server-Side libraries included in this release are built with exceptions supported internally (though no exceptions pass through the C interface exposed in tox_server.h). If needed, the SDK may be compiled without exception support by defining the flag TOX_SERVER_NO_EXCEPTIONS at compile time. This compilation mode is officially supported on Linux and macOSX.
The ToxMod Server-Side SDK exposes the following public header file in the include/ subdirectory:
The source code to build the library consists of the above header plus source code in the src/ subdirectory:
Source code for building a basic example program (example/basic_example.c) which verifies tox_server functionality, as well as a more realistic multistream example program (example/multistream_example.cpp) are included. Before compiling the example programs, please add the Modulate-provided account id, api key, and (if applicable) single tenant prefix to the top of the files. The example programs may be compiled by linking to the Ogg library and tox_server library, assuming the Ogg headers are installed on the system.
The basic example program runs an Opus file through the ToxServer library by reading Opus packets from the file and adding them to the library under the guise of a single player. The contents of the example file should show up on the ToxMod web console Livestreams page in several short clips. The clips should be intelligible and transcribed understandably, though they may show up out of temporal order since the basic example program reads through the entire file as fast as possible (instead of in realtime).
The basic example program takes no arguments, and expects to read a file called test_clip.opus from the same directory as the executable. The relevant test_clip.opus included in the example/ may be copied to the correct location if building with the provided CMakeLists.txt file, but on some platforms may need to be copied to the correct location manually. If experimenting with a clip other than the provided test_clip.opus, the max_packet_size and frame_size parameters in basic_example.c may need to be updated to reflect the properties of the new Opus clip. You may also manually set the properties of a new file by adjusting its frame duration, bitrate, and VBR setting, such as with
The basic example program will print outputs from cURL uploads, to indicate successful clip upload to ToxMod (error code 0), or some clip upload error.
Additionally, source code for a more realistic example program (example/multistream_example.cpp) is included, which behaves similarly to the basic example but has the following differences: multiple players are simulated as if they are all "speaking" the input file, grouped into multiple voice chat sessions; the buffer copy, begin upload, and run upload functions are all run in timed loops as in a real production voice chat server; the simulated voice chat happens in approximately realtime (by adding packet, then sleeping for the duration of that packet) instead of as fast as possible.
The multistream example program is intended as a reference for production usage of tox_server. However, the multistream example program is not an exact simulation of production usage: for example, it simulates all speakers speaking simultaneously all of the time, and all speaking exactly the same thing - therefore buffer copies, clip uploads, etc. all happen at exactly the same time for all players; as opposed to production usage where a smaller set of players will be speaking at any given time, and buffer copies and clip uploads will be more evenly distributed over time.
The multistream example program will print out dots once per second to show that it is running, as well as outputs from cURL approximately once ever 15 seconds, to indicate successful clip upload to ToxMod (error code 0), or some clip upload error.
Wrappers of the Server-Side C API to provide bindings for other languages are provided in the bindings/ subdirectory. In each case the wrapper file is name tox_server.<typical language extension>, and is shipped alongside a simple API test program to verify that the bindings are functional and a makefile to build/run the API tests.