Expand description
§VoiRS FFI (Foreign Function Interface)
C-compatible bindings for VoiRS speech synthesis framework with comprehensive language support for C/C++, Python, Node.js, and WebAssembly.
§Features
- C API: Complete C-compatible interface for maximum portability
- Python Bindings: PyO3-based Python integration with NumPy support
- Node.js Bindings: N-API bindings for JavaScript/TypeScript
- WebAssembly: WASM bindings for browser-based synthesis
- Zero-Copy Operations: Efficient memory management across FFI boundaries
- Thread Safety: Comprehensive threading support with work-stealing schedulers
- Platform Integration: Native integration with Windows, macOS, and Linux
§Module Organization
c_api: Core C API functions for synthesis, audio, and voice management- [
python]: PyO3 bindings for Python integration (requirespythonfeature) - [
nodejs]: N-API bindings for Node.js (requiresnodejsfeature) - [
wasm]: WebAssembly bindings (requireswasmfeature) memory: Advanced memory management with custom allocators and zero-copy operationsthreading: Thread pools, synchronization primitives, and callback managementerror: Comprehensive error handling with i18n supportperformance: Performance monitoring and optimization utilitiesplatform: Platform-specific integrations (Windows, macOS, Linux)utils: Utility functions for audio processing, string conversion, and performance analysis
§Quick Start (C API)
#include "voirs_ffi.h"
// Initialize pipeline
VoirsPipelineHandle* pipeline = voirs_create_pipeline();
// Synthesize speech
VoirsAudioBuffer* buffer = NULL;
VoirsErrorCode result = voirs_synthesize(
pipeline,
"Hello, world!",
&buffer
);
if (result == VOIRS_SUCCESS) {
// Process audio...
voirs_free_audio_buffer(buffer);
}
voirs_destroy_pipeline(pipeline);§Quick Start (Python)
from voirs_ffi import VoirsPipeline
# Create pipeline
pipeline = VoirsPipeline()
# Synthesize speech
result = pipeline.synthesize("Hello, world!")
audio_data = result.audio_data # NumPy array§Safety
All FFI functions are marked as unsafe and require careful handling:
- Null pointer checks for all pointer parameters
- Proper memory management (use provided free functions)
- Thread safety guarantees where documented
- No undefined behavior when contracts are followed
§Performance
The FFI layer is designed for minimal overhead:
- Zero-copy operations where possible
- Efficient memory pooling
- SIMD-optimized audio processing
- Work-stealing thread pools for parallelism
Re-exports§
pub use utils::audio::VoirsAudioAnalysis;pub use c_api::*;pub use error::*;pub use performance::*;pub use types::*;
Modules§
- c_api
- C API module organization.
- config
- Configuration management for VoiRS FFI operations.
- error
- memory
- Advanced memory management for FFI operations.
- performance
- Performance optimizations for VoiRS FFI operations.
- platform
- Platform-specific functionality for VoiRS FFI
- threading
- Advanced threading utilities for VoiRS FFI
- types
- FFI-safe type definitions.
- utils
- FFI utility functions and audio processing utilities.
Macros§
- track_
allocation - Macro to track allocations with source location
Structs§
- Voirs
Audio Buffer - FFI-safe audio buffer
- Voirs
Synthesis Config - FFI-safe synthesis configuration
Enums§
- Voirs
Audio Format - FFI-safe audio format enum
- Voirs
Error Code - FFI-safe error codes
- Voirs
Quality Level - FFI-safe quality level enum
Functions§
- set_
last_ error - Set the last error message for the current thread
- voirs_
clear_ error - Clear the last error for the current thread
- voirs_
error_ message - Convert error code to string description
- voirs_
free_ ⚠audio_ buffer - Free an audio buffer allocated by this library
- voirs_
free_ ⚠string - Free a C string allocated by this library
- voirs_
get_ last_ error - Get the last error message for the current thread
- voirs_
has_ error - Check if there is a pending error for the current thread