Skip to main content

Crate voirs_ffi

Crate voirs_ffi 

Source
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 (requires python feature)
  • [nodejs]: N-API bindings for Node.js (requires nodejs feature)
  • [wasm]: WebAssembly bindings (requires wasm feature)
  • memory: Advanced memory management with custom allocators and zero-copy operations
  • threading: Thread pools, synchronization primitives, and callback management
  • error: Comprehensive error handling with i18n support
  • performance: Performance monitoring and optimization utilities
  • platform: 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§

VoirsAudioBuffer
FFI-safe audio buffer
VoirsSynthesisConfig
FFI-safe synthesis configuration

Enums§

VoirsAudioFormat
FFI-safe audio format enum
VoirsErrorCode
FFI-safe error codes
VoirsQualityLevel
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