2 releases

0.1.1 Jul 17, 2022
0.1.0 Dec 7, 2021

#423 in Machine learning

MIT/Apache

145KB
2K SLoC

IBM Watson

A wrapper for interacting with IBM Watson's API

Crates.io docs.rs GitHub Workflow Status Crates.io

Usage

Add ibm-watson to your Cargo.toml

[dependencies]
ibm-watson = "0.1.1"

Feature Flags

This crate uses a set of featue flags to reduce the amount of compiled code. By default, none of the features are enabled and it is therefore recommended that you do so for only those services you intend to use.

  • full - Enables all the features listed below
  • http2 - Enables support of HTTP/2.0 requests
  • tts - Enables interacting with the Text To Speech API

Example

To use the Text To Speech API to synthesise some text with the default options, enable the tts feature

[dependencies]
ibm-watson = { version = "0.1.1", features = [ "tts" ] }
// Get your IAM access token with the API Key of the particular service you want to use
let auth = IamAuthenticator::new("my_api_key").await?;
// Create a new Text To Speech instance that you will use to interact with the API
let tts = TextToSpeech::new(&auth, "tts-endpoint");
// Call whatever method you would like to use from it
let synth = tts.synthesise("Hello world", None, None).await?;
let mut file = File::create("file.ogg")?;
file.write_all(&synth)?;

To perform synthesis with a custom voice and in a different audio format:

// This sets Kate (United Kingdom) to be the default voice for your requests
tts.set_voice(WatsonVoice::EnGbKateV3);
// set the format to MP3 with a sample rate of 44100khz
let format = AudioFormat::AudioMp3 {
// If `None` is passed, then the crate will default to 22050.
    sample_rate: Some(44100),
};
let synth = tts.synthesise("Hello world", Some(format), None).await?;

There are examples ready to get you started quickly. To run an example that uses the Text To Speech service to print available voices and then synthesise the text you entered to a file:

cargo run --example tts --features="tts" -- -a "my_api_key" -s "my_service_url" -t "Greetings from Rust"

License

This crate is licensed under either of:

  • Apache License, Version 2.0
  • MIT License

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

This is currently unofficial, experimental software that is under development. As such, contributions are welcome. This crate's documentation is sourced from IBM Watson's official API Documentation. If you would like to know more about Watson's API, that would be a good place to start.

Dependencies

~7–22MB
~259K SLoC