mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-25 12:39:37 +00:00
FFI: Take only const pointers to TTS objects when we don't modify them.
This commit is contained in:
parent
9ab38f550f
commit
060a057c0f
31
src/ffi.rs
31
src/ffi.rs
|
@ -81,7 +81,7 @@ pub unsafe extern "C" fn tts_free(tts: *mut TTS) {
|
|||
/// Returns the features supported by this TTS engine.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_supported_features(tts: *mut TTS) -> Features {
|
||||
pub unsafe extern "C" fn tts_supported_features(tts: *const TTS) -> Features {
|
||||
tts.as_ref().unwrap().supported_features()
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ pub unsafe extern "C" fn tts_speak(
|
|||
utterance: *mut *mut UtteranceId,
|
||||
) -> bool {
|
||||
if tts.is_null() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
let text = CStr::from_ptr(text).to_string_lossy().into_owned();
|
||||
match tts.as_mut().unwrap().speak(text, interrupt) {
|
||||
|
@ -126,6 +126,7 @@ pub unsafe extern "C" fn tts_free_utterance(utterance: *mut UtteranceId) {
|
|||
}
|
||||
Box::from_raw(utterance);
|
||||
}
|
||||
|
||||
/// Stops current speech.
|
||||
/// Returns true on success, false on error or if `tts` is NULL.
|
||||
#[no_mangle]
|
||||
|
@ -145,21 +146,21 @@ pub unsafe extern "C" fn tts_stop(tts: *mut TTS) -> bool {
|
|||
/// Returns the minimum rate for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_min_rate(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_min_rate(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().min_rate()
|
||||
}
|
||||
|
||||
/// Returns the maximum rate for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_max_rate(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_max_rate(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().max_rate()
|
||||
}
|
||||
|
||||
/// Returns the normal rate for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_normal_rate(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_normal_rate(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().normal_rate()
|
||||
}
|
||||
|
||||
|
@ -168,7 +169,7 @@ pub unsafe extern "C" fn tts_normal_rate(tts: *mut TTS) -> c_float {
|
|||
/// or if `tts` is NULL.
|
||||
/// Does nothing if `rate` is NULL.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_get_rate(tts: *mut TTS, rate: *mut c_float) -> bool {
|
||||
pub unsafe extern "C" fn tts_get_rate(tts: *const TTS, rate: *mut c_float) -> bool {
|
||||
if tts.is_null() {
|
||||
return false;
|
||||
}
|
||||
|
@ -206,21 +207,21 @@ pub unsafe extern "C" fn tts_set_rate(tts: *mut TTS, rate: c_float) -> bool {
|
|||
/// Returns the minimum pitch for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_min_pitch(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_min_pitch(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().min_pitch()
|
||||
}
|
||||
|
||||
/// Returns the maximum pitch for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_max_pitch(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_max_pitch(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().max_pitch()
|
||||
}
|
||||
|
||||
/// Returns the normal pitch for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_normal_pitch(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_normal_pitch(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().normal_pitch()
|
||||
}
|
||||
|
||||
|
@ -229,7 +230,7 @@ pub unsafe extern "C" fn tts_normal_pitch(tts: *mut TTS) -> c_float {
|
|||
/// or if `tts` is NULL.
|
||||
/// Does nothing if `pitch` is NULL.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_get_pitch(tts: *mut TTS, pitch: *mut c_float) -> bool {
|
||||
pub unsafe extern "C" fn tts_get_pitch(tts: *const TTS, pitch: *mut c_float) -> bool {
|
||||
if tts.is_null() {
|
||||
return false;
|
||||
}
|
||||
|
@ -267,21 +268,21 @@ pub unsafe extern "C" fn tts_set_pitch(tts: *mut TTS, pitch: c_float) -> bool {
|
|||
/// Returns the minimum volume for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_min_volume(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_min_volume(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().min_volume()
|
||||
}
|
||||
|
||||
/// Returns the maximum volume for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_max_volume(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_max_volume(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().max_volume()
|
||||
}
|
||||
|
||||
/// Returns the normal volume for this speech synthesizer.
|
||||
/// `tts` must be a valid pointer to a TTS object.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_normal_volume(tts: *mut TTS) -> c_float {
|
||||
pub unsafe extern "C" fn tts_normal_volume(tts: *const TTS) -> c_float {
|
||||
tts.as_ref().unwrap().normal_volume()
|
||||
}
|
||||
|
||||
|
@ -290,7 +291,7 @@ pub unsafe extern "C" fn tts_normal_volume(tts: *mut TTS) -> c_float {
|
|||
/// or if `tts` is NULL.
|
||||
/// Does nothing if `volume` is NULL.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_get_volume(tts: *mut TTS, volume: *mut c_float) -> bool {
|
||||
pub unsafe extern "C" fn tts_get_volume(tts: *const TTS, volume: *mut c_float) -> bool {
|
||||
if tts.is_null() {
|
||||
return false;
|
||||
}
|
||||
|
@ -331,7 +332,7 @@ pub unsafe extern "C" fn tts_set_volume(tts: *mut TTS, volume: c_float) -> bool
|
|||
/// If `speaking` is NULL, returns this value instead, meaning you can't tell the difference
|
||||
/// between an error occuring and the synth not speaking.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tts_is_speaking(tts: *mut TTS, speaking: *mut bool) -> bool {
|
||||
pub unsafe extern "C" fn tts_is_speaking(tts: *const TTS, speaking: *mut bool) -> bool {
|
||||
if tts.is_null() {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user