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
use std::path::PathBuf;

use config::Config;
use rocket::async_trait;
use rocket::{fairing::AdHoc, request::FromRequest};
use utils::phrase_package::PhrasePackage;

/// A trait indicating a tts generator that can be constructed and used to generate audio files from speech
#[async_trait]
pub trait TtsGenerator<'r>: Send + Sync + Sized + 'static {
    type Error: core::fmt::Debug;

    /// Create a new TTS builder
    fn new() -> Result<Self, <Self as TtsGenerator<'r>>::Error>;

    /// Generate an adhoc fairing which can be bound to a launching rocket.
    fn fairing() -> AdHoc
    where
        &'r Self: FromRequest<'r>,
    {
        AdHoc::on_ignite("Tts Generator", |rocket| {
            Box::pin(async move {
                let jenny = Self::new().unwrap();
                rocket.manage(jenny)
            })
        })
    }

    /// Generate a phrase utilising the TTS system, with the set parameters
    async fn generate(
        &self,
        details: &PhrasePackage,
        config: &Config,
    ) -> Result<PathBuf, <Self as TtsGenerator<'r>>::Error>;
}