#tts #text-to-speech #api-bindings #parler #gtts #coqui-ai

natural-tts

High-level bindings to a variety of text-to-speech libraries

3 releases

new 0.1.4 Jun 20, 2024
0.1.3 Jun 2, 2024
0.1.2 Jun 1, 2024
0.1.1 Jun 1, 2024
0.1.0 Jun 1, 2024

#75 in Science

Download history 251/week @ 2024-05-31 25/week @ 2024-06-07 41/week @ 2024-06-14

317 downloads per month

MIT/Apache

72KB
1.5K SLoC

Natural TTS

Natural TTS (natural-tts) is a rust crate for easily implementing Text-To-Speech into your rust programs.

Available TTS Engines / AIs:

Coqui TTS
Parler TTS
Google Gtts
TTS-RS
MSEdge TTS

Install Rust

Install Rust

On Linux or MacOS:

curl --proto '=https' --tlsv1.2 -ssf https://sh.rustup.rs | sh

Example of saying something using Gtts but initializing every model.

use std::error::Error;
use crate::{*, models::{gtts::GttsModel, tts_rs::TtsModel, parler::ParlerModel, msedge::MSEdgeModel}};

fn main() -> Result<(), Box<dyn Error>>{
    // Create the ParlerModel
    let desc = "A female speaker in fast calming voice in a quiet environment".to_string();
    let model = "parler-tts/parler-tts-mini-expresso".to_string();
    let parler = ParlerModel::new(desc, model, false);
    
    // Create the NaturalTts using the Builder pattern
    let mut natural = NaturalTtsBuilder::default()
        .default_model(Model::Gtts)
        .gtts_model(GttsModel::default())
        .parler_model(parler.unwrap())
        .tts_model(TtsModel::default())
        .build()?;
        
    // Use the pre-included function to say a message using the default_model.
    let _ = natural.say_auto("Hello, World!".to_string())?;
}

Example of saying something using Meta Voice

use std::error::Error;
use natural_tts::{*, models::meta::MetaModel};

fn main() -> Result<(), Box<dyn Error>>{
    // Create the NaturalTts struct using the builder pattern.
    let mut natural = NaturalTtsBuilder::default()
        .gtts_model(MetaModel::default())
        .default_model(Model::Meta)
        .build()?;

    // Use the pre-included function to say a message using the default_model.
    let _ = natural.say_auto("Hello, World!".to_string())?;
    Ok(())
}

Example of saying something using Parler

use std::error::Error;
use natural_tts::{*, models::parler::ParlerModel};

fn main() -> Result<(), Box<dyn Error>>{
    // Create the ParlerModel
    let desc = "A female speaker in fast calming voice in a quiet environment".to_string();
    let model = "parler-tts/parler-tts-mini-expresso".to_string();
    let parler = ParlerModel::new(desc, model, false);
    
    // Create the NaturalTts using the Builder pattern
    let mut natural = NaturalTtsBuilder::default()
        .parler_model(parler.unwrap())
        .default_model(Model::Parler)
        .build()?;
        
    // Use the pre-included function to say a message using the default_model.
    let _ = natural.say_auto("Hello, World!".to_string())?;
}

Example of saying something using Gtts

use std::error::Error;
use natural_tts::{*, models::gtts::GttsModel};

fn main() -> Result<(), Box<dyn Error>>{
    // Create the NaturalTts struct using the builder pattern.
    let mut natural = NaturalTtsBuilder::default()
        .gtts_model(GttsModel::default())
        .default_model(Model::Gtts)
        .build()?;

    // Use the pre-included function to say a message using the default_model.
    let _ = natural.say_auto("Hello, World!".to_string())?;
    Ok(())
}

Example of saying something using MSEdge

use std::error::Error;
use natural_tts::{*, models::msedge::MSEdgeModel};

fn main() -> Result<(), Box<dyn Error>>{

    // Create the NaturalTts struct using the builder pattern.
    let mut natural = NaturalTtsBuilder::default()
        .msedge_model(MSEdgeModel::default())
        .default_model(Model::MSEdge)
        .build()?;

    // Use the pre-included function to say a message using the default_model.
    let _ = natural.say_auto("Hello, World!".to_string())?;
    Ok(())
}

Example of saying something using TTS

use std::error::Error;
use natural_tts::{*, models::parler::TtsModel};

fn main() -> Result<(), Box<dyn Error>>{

    // Create the NaturalTts struct using the builder pattern.
    let mut natural = NaturalTtsBuilder::default()
        .tts_model(TtsModel::default())
        .default_model(Model::TTS)
        .build()?;

    // Use the pre-included function to say a message using the default_model.
    let _ = natural.say_auto("Hello, World!".to_string())?;
    Ok(())
}

Example of saying something using Coqui Tts

Disclaimer : Currently not supported.

use std::error::Error;
use natural_tts::{*, models::parler::CoquiModel};

fn main() -> Result<(), Box<dyn Error>>{

    // Create the NaturalTts struct using the builder pattern.
    let mut natural = NaturalTtsBuilder::default()
        .coqui_model(CoquiModel::default())
        .default_model(Model::Coqui)
        .build().unwrap();

    // Use the pre-included function to say a message using the default_model.
    let _ = natural.say_auto("Hello, World!".to_string())?;
    Ok(())
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Dependencies

~2–38MB
~606K SLoC