2 个版本

0.1.1 2022 年 7 月 17 日
0.1.0 2021 年 12 月 7 日

#334 in 机器学习

MIT/Apache

145KB
2K SLoC

IBM Watson

用于与 IBM Watson API 交互的包装器

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

使用方法

ibm-watson 添加到您的 Cargo.toml

[dependencies]
ibm-watson = "0.1.1"

功能标志

此 crate 使用一组功能标志来减少编译代码的量。默认情况下,没有启用任何功能,因此建议您只为打算使用的服务启用它们。

  • full - 启用以下列出的所有功能
  • http2 - 启用对 HTTP/2.0 请求的支持
  • tts - 启用与语音到文本 API 交互

示例

要使用默认选项使用语音到文本 API 合成一些文本,请启用 tts 功能

[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)?;

要使用自定义语音和不同的音频格式进行合成

// 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?;

已准备好示例,可快速入门。要运行使用文本到语音服务打印可用语音并将您输入的文本合成到文件的示例

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

许可协议

此 crate 依据以下任一协议授权:

  • Apache 许可协议第 2 版
  • MIT 许可协议

任选其一。

贡献

除非您明确表示,否则您有意提交以供包括在本作品中的任何贡献,如 Apache-2.0 许可协议中定义的,应按上述方式双授权,没有任何附加条款或条件。

这是一款目前为非官方、实验性软件,处于开发中。因此,欢迎贡献。 此 crate 的文档来源于 IBM Watson 的官方 API 文档。如果您想了解更多关于 Watson API 的信息,那将是一个好起点。

依赖项

~6–18MB
~266K SLoC