File size: 1,528 Bytes
4e1096a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | use tauri::{
plugin::{Builder, TauriPlugin},
Manager, Runtime,
};
pub use models::*;
#[cfg(desktop)]
mod desktop;
#[cfg(mobile)]
mod mobile;
mod commands;
mod error;
mod models;
pub use error::{Error, Result};
#[cfg(desktop)]
use desktop::NativeTts;
#[cfg(mobile)]
use mobile::NativeTts;
/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the native-tts APIs.
pub trait NativeTtsExt<R: Runtime> {
fn native_tts(&self) -> &NativeTts<R>;
}
impl<R: Runtime, T: Manager<R>> crate::NativeTtsExt<R> for T {
fn native_tts(&self) -> &NativeTts<R> {
self.state::<NativeTts<R>>().inner()
}
}
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("native-tts")
.invoke_handler(tauri::generate_handler![
commands::init,
commands::speak,
commands::stop,
commands::pause,
commands::resume,
commands::set_rate,
commands::set_pitch,
commands::set_voice,
commands::get_all_voices,
commands::set_media_session_active,
commands::update_media_session_state,
commands::update_media_session_metadata,
])
.setup(|app, api| {
#[cfg(mobile)]
let native_tts = mobile::init(app, api)?;
#[cfg(desktop)]
let native_tts = desktop::init(app, api)?;
app.manage(native_tts);
Ok(())
})
.build()
}
|