A Rust library for Google Translate’s text-to-speech API. Writes audio to an mp3 file and plays it using the rodio crate.
Add this to your Cargo.toml:
[dependencies]
gtts_rs = "0.1"using default configuration:
use gtts_rs::tts::{ GttsClient, Language, Speed };
fn main() -> Result<(), String> {
let client = GttsClient::default();
client.speak("Hello world!")?;
Ok(())
}this will produce an audio: hello_world
with custom configuration:
use gtts_rs::tts::{ GttsClient, Language, Speed };
fn main() -> Result<(), String> {
let mut client: GttsClient = GttsClient {
volume: 1.0,
language: Language::English,
speed: Speed::Slow,
tld: "com",
};
client.speak("Hello, world!")?;
Ok(())
}or a different language:
use gtts_rs::tts::{ GttsClient, Language, Speed };
fn main() -> Result<(), String> {
let client = GttsClient {
volume: 1.0,
language: Language::Japanese,
speed: Speed::Normal,
tld: "co.jp",
};
client.speak("こんにちは、元気ですか?")?;
Ok(())
}This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are very welcome! Please feel free to submit issues and pull requests.