mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-25 12:39:37 +00:00
FFI: Implement tts_new(backend)
This required giving the Backends enum and Features struct a C representation.
This commit is contained in:
parent
ab558cbbd2
commit
56a2d554fa
16
src/ffi.rs
16
src/ffi.rs
|
@ -5,7 +5,7 @@ use std::{
|
|||
ptr,
|
||||
};
|
||||
|
||||
use crate::TTS;
|
||||
use crate::{Backends, TTS};
|
||||
|
||||
thread_local! {
|
||||
/// Stores the last reported error, so it can be retrieved at will from C
|
||||
|
@ -38,6 +38,20 @@ pub extern "C" fn tts_clear_error() {
|
|||
});
|
||||
}
|
||||
|
||||
/// Creates a new TTS object with the specified backend and returns a pointer to it.
|
||||
/// If an error occured, a null pointer is returned,
|
||||
/// Call `tts_get_error()` for more information about the specific error.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn tts_new(backend: Backends) -> *mut TTS {
|
||||
match TTS::new(backend) {
|
||||
Ok(tts) => Box::into_raw(Box::new(tts)),
|
||||
Err(e) => {
|
||||
set_last_error(e.to_string()).unwrap();
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new TTS object with the default backend and returns a pointer to it.
|
||||
/// If an error occured, a null pointer is returned,
|
||||
/// Call `tts_get_error()` for more information about the specific error.
|
||||
|
|
|
@ -31,6 +31,7 @@ mod backends;
|
|||
#[cfg(feature = "ffi")]
|
||||
pub mod ffi;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Backends {
|
||||
#[cfg(target_os = "linux")]
|
||||
|
@ -75,6 +76,7 @@ unsafe impl Send for UtteranceId {}
|
|||
|
||||
unsafe impl Sync for UtteranceId {}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Features {
|
||||
pub stop: bool,
|
||||
pub rate: bool,
|
||||
|
|
Loading…
Reference in New Issue
Block a user