Skip to content

Commit

Permalink
docs(readme): updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjercan committed Jul 8, 2023
1 parent 135c279 commit 56aed4f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 6 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ Then use the crate in your Rust code:

```rust
// Import the dependencies
// Import the dependencies
use fakeyou_api::{
tts::{InferenceBody, TtsApi, TtsJobStatus},
*,
};
use fakeyou_api::{tts::InferenceBody, util::tts::TtsApiSync, *};

// You can create a default client without any api key.
// You can also load the API key from environment FAKEYOU_API_KEY.
Expand All @@ -78,45 +74,11 @@ let inference_body = InferenceBody {
};

// Call the TTS API
let inference_result = fakeyou.tts_inference(&inference_body).unwrap();

// Print the result
println!("{:?}", inference_result);

loop {
// Call the TTS API
let job_result = fakeyou.tts_job(&inference_result.inference_job_token).unwrap();

// Check if the job is done
match job_result.state.status {
TtsJobStatus::Pending => {
println!("Job is pending");
}
TtsJobStatus::Started => {
println!("Job is started");
}
TtsJobStatus::AttemptFailed => {
println!("Job attempt failed. Trying again...");
}
TtsJobStatus::CompleteSuccess => {
println!("Job completed successfully");
let output_result = fakeyou.tts_output(&job_result.state.maybe_public_bucket_wav_audio_path.unwrap()).unwrap();

// Do what you need with the audio file
std::fs::write("output.wav", output_result.bytes).unwrap();

break;
}
_ => {
println!("Job failed");

break;
}
}

// Wait 1 second before trying again
std::thread::sleep(std::time::Duration::from_secs(1));
}
// This uses the util module of this crate and will block the thread until the task is done
let output_result = fakeyou.create_tts_task(&inference_body).unwrap();

// Do what you need with the audio file
std::fs::write("output.wav", output_result.bytes).unwrap();
```

### License
Expand Down
50 changes: 6 additions & 44 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@
//! ```no_run
//! # fn main() {
//! // Import the dependencies
//! // Import the dependencies
//! use fakeyou_api::{
//! tts::{InferenceBody, TtsApi, TtsJobStatus},
//! *,
//! };
//! use fakeyou_api::{tts::InferenceBody, util::tts::TtsApiSync, *};
//!
//! // You can create a default client without any api key.
//! // You can also load the API key from environment FAKEYOU_API_KEY.
Expand All @@ -79,45 +75,11 @@
//! };
//!
//! // Call the TTS API
//! let inference_result = fakeyou.tts_inference(&inference_body).unwrap();
//!
//! // Print the result
//! println!("{:?}", inference_result);
//!
//! loop {
//! // Call the TTS API
//! let job_result = fakeyou.tts_job(&inference_result.inference_job_token).unwrap();
//!
//! // Check if the job is done
//! match job_result.state.status {
//! TtsJobStatus::Pending => {
//! println!("Job is pending");
//! }
//! TtsJobStatus::Started => {
//! println!("Job is started");
//! }
//! TtsJobStatus::AttemptFailed => {
//! println!("Job attempt failed. Trying again...");
//! }
//! TtsJobStatus::CompleteSuccess => {
//! println!("Job completed successfully");
//! let output_result = fakeyou.tts_output(&job_result.state.maybe_public_bucket_wav_audio_path.unwrap()).unwrap();
//!
//! // Do what you need with the audio file
//! std::fs::write("output.wav", output_result.bytes).unwrap();
//!
//! break;
//! }
//! _ => {
//! println!("Job failed");
//!
//! break;
//! }
//! }
//!
//! // Wait 1 second before trying again
//! std::thread::sleep(std::time::Duration::from_secs(1));
//! }
//! // This uses the util module of this crate and will block the thread until the task is done
//! let output_result = fakeyou.create_tts_task(&inference_body).unwrap();
//!
//! // Do what you need with the audio file
//! std::fs::write("output.wav", output_result.bytes).unwrap();
//! # }
//! ```
//!
Expand Down

0 comments on commit 56aed4f

Please sign in to comment.