Compile-time macros¶
These optional preprocessor macros apply to the native C API only. They are not used by the Java, Python, or Android Java/Kotlin bindings.
Define library macros before #include <snsr.h>, or pass them as compiler flags (for example -DSNSR_USE_SUBSET). Define generated-model macros before compiling snsr-edit output (files such as spot-voicegenie-enUS-6.5.1-m.c or snsr-custom-init.c).
For SDK-provided read-only values such as VERSION, see Constants.
Library initialization¶
By default, new maps to snsrNewIncludeOSS(), which initializes the full library including Open Source components (STT support). You can select a smaller variant instead.
| Macro | snsrNew() expands to | When to use |
|---|---|---|
| (none) | snsrNewIncludeOSS() | Default. Full library with OSS/STT. |
SNSR_OMIT_OSS_COMPONENTS | snsrNewOmitOSS() | Omit OSS/STT modules. See also SnsrLibraryOmitOSS. |
SNSR_USE_SUBSET | snsrNewSubset() | Custom init code for a fixed model set. Mutually exclusive with SNSR_OMIT_OSS_COMPONENTS. |
snsrNew() selection (C)
#ifndef SNSR_USE_SUBSET
# ifdef SNSR_OMIT_OSS_COMPONENTS
# define snsrNew(s) snsrNewOmitOSS((s), SNSR_VERSION)
# else
# define snsrNew(s) snsrNewIncludeOSS((s), SNSR_VERSION)
# endif
#else
# define snsrNew(s) snsrNewSubset((s), SNSR_VERSION)
#endif
SNSR_USE_SUBSET¶
Limits the linked library to modules required by models you include in the build. Requires custom initialization code that implements snsrNewSubset().
Generate the init file with snsr-edit -i, or at runtime with save and SUBSET_INIT after setting model:ids. Add the generated snsr-custom-init.c to your project and compile with -DSNSR_USE_SUBSET.
reduce code size, model:ids, snsr-eval.c
SNSR_OMIT_OSS_COMPONENTS¶
Selects snsrNewOmitOSS(), which initializes the library without the Open Source Software components (and therefore without STT). Those modules are then unreferenced, so the linker can drop them and reduce executable size.
With CMake, the separate SnsrLibraryOmitOSS target adds this define for you. With Make, add -DSNSR_OMIT_OSS_COMPONENTS to CFLAGS.
Open Source licenses, oss-components
Linkage¶
These macros control how public API symbols are declared in <snsr.h>. Most applications leave them at their defaults.
SNSR_API¶
Prefixes each public function declaration in <snsr.h>. Empty by default. Override when you need custom export or visibility attributes (for example when building a shared library wrapper).
Emscripten builds set SNSR_API to __attribute__((used)) automatically.
SNSR_DLL¶
When defined before #include <snsr.h> on Windows, sets SNSR_API to __declspec(dllimport) for applications that link against a DLL build of the SDK. The standard distribution ships static libraries only; Windows DLLs are provided through custom SDK ports.
Generated model code¶
snsr-edit emits C source with -c (run from ROM/code space) or -C (load into RAM). save with SOURCE, SOURCE_RAM, or SOURCE_PRUNED produces the same pattern. Each generated file defines default values for the macros below unless you define them first.
Define overrides on the compiler command line, in a wrapper header included before the generated file, or in your build system before the translation unit is compiled.
SNSR_MODEL_ATTR¶
Applied to every static model object in generated code (weights, strings, tables, and the exported fromCode model symbol). Defaults to empty.
Override to control linker placement — for example, force model data into a specific flash section on embedded targets:
#define SNSR_MODEL_ATTR __attribute__((section(".model_flash")))
#include "spot-voicegenie-enUS-6.5.1-m.c"
.model_flash above is an example; use the section name your own linker script defines. On toolchains without GCC-style attributes, define SNSR_MODEL_ATTR to the macro or pragma your linker expects.
SNSR_ALIGNED¶
Used as SNSR_ALIGNED(n) on selected model blobs in generated code. On GCC and Clang the default expands to __attribute__((aligned(n))); on other compilers it defaults to empty.
Override when your toolchain needs a different alignment syntax.