1use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4};
5
6pub use models::*;
7
8#[cfg(desktop)]
9mod desktop;
10#[cfg(mobile)]
11mod mobile;
12
13mod commands;
14mod error;
15mod models;
16
17pub use error::{Error, Result};
18
19#[cfg(desktop)]
20use desktop::Tts;
21#[cfg(mobile)]
22use mobile::Tts;
23
24pub trait TtsExt<R: Runtime> {
26 fn tts(&self) -> &Tts<R>;
27}
28
29impl<R: Runtime, T: Manager<R>> crate::TtsExt<R> for T {
30 fn tts(&self) -> &Tts<R> {
31 self.state::<Tts<R>>().inner()
32 }
33}
34
35pub fn init<R: Runtime>() -> TauriPlugin<R> {
36 Builder::new("tts")
37 .invoke_handler(tauri::generate_handler![
38 commands::speak,
39 commands::stop,
40 commands::get_voices,
41 commands::is_speaking,
42 commands::is_initialized,
43 commands::pause_speaking,
44 commands::resume_speaking,
45 commands::preview_voice,
46 commands::set_background_behavior,
47 commands::register_listener
48 ])
49 .setup(|app, api| {
50 #[cfg(mobile)]
51 {
52 let tts = mobile::init(app, api)?;
53 app.manage(tts);
54 }
55 #[cfg(desktop)]
56 {
57 let tts = desktop::init(app, api)?;
58 app.manage(tts);
59 }
60 Ok(())
61 })
62 .build()
63}