6 releases

new 0.2.1 Apr 30, 2025
0.2.0 Apr 1, 2025
0.1.5 Jul 2, 2024
0.1.4 Jun 20, 2024

#63 in Accessibility

Download history 5/week @ 2025-01-27 1/week @ 2025-02-03 28/week @ 2025-02-10 1/week @ 2025-02-17 3/week @ 2025-02-24 3/week @ 2025-03-03 1/week @ 2025-03-10 6/week @ 2025-03-17 1/week @ 2025-03-24 115/week @ 2025-03-31 40/week @ 2025-04-07 35/week @ 2025-04-14 23/week @ 2025-04-21 141/week @ 2025-04-28

246 downloads per month
Used in ochat

MIT license

99KB
2K SLoC

Natural TTS Rust

Linux Windows macOS

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

To Do:

  • Add support for Piper TTS.
  • Remove all pyo3 usage.

Available TTS Engines / AIs:

Parler TTS
Google Gtts
TTS-RS
MSEdge TTS
MetaVoice TTS
Coqui TTS

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, meta::MetaModel}};

fn main() -> Result<(), Box<dyn Error>>{
    // Create the NaturalTts using the Builder pattern
    let mut natural = NaturalTtsBuilder::default()
        .default_model(Model::Gtts)
        .gtts_model(GttsModel::default())
        .parler_model(ParlerModel::default())
        .msedge_model(MSEdgeModel::default())
        .meta_model(MetaModel::default())
        .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()
        .meta_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 NaturalTts using the Builder pattern
    let mut natural = NaturalTtsBuilder::default()
        .parler_model(ParlerModel::default())
        .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 only in test feature.

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.

Dependencies

~2–42MB
~657K SLoC