Skip to content

Commit

Permalink
add unwrap() to speak()
Browse files Browse the repository at this point in the history
  • Loading branch information
notnightly committed Dec 5, 2021
1 parent 5b69f76 commit 8437523
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 3 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use structopt::StructOpt;
use tts_rust::{ GTTSClient, languages::Languages };
use quicli::prelude::*;

use structopt::StructOpt;
use tts_rust::{languages::Languages, GTTSClient};

#[derive(Debug, StructOpt)]
struct GTTSCli {
Expand All @@ -11,13 +10,12 @@ struct GTTSCli {
language: Languages,
}


fn main() -> CliResult {
let args = GTTSCli::from_args();
let client = GTTSClient {
volume: 1.0,
language: args.language,
};
client.speak(&args.text);
client.speak(&args.text).unwrap();
Ok(())
}
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,17 @@ impl GTTSClient {
sink.sleep_until_end();
}
/// Speak the input according to the volume and language
pub fn speak(&self, input: &str) {
pub fn speak(&self, input: &str) -> Result<(), String> {
self.save_to_file(input, "audio.mp3").unwrap();
self.play_mp3("audio.mp3");
if Path::new("./audio.mp3").exists() {
fs::remove_file("./audio.mp3").unwrap();
}
Ok(())
}
/// Speak and println! the input according to the volume and language
pub fn display_and_speak(&self, input: &str) {
self.speak(input);
self.speak(input).unwrap();
println!("{}", input);
}
/// Fastest way to check if gTTS API works
Expand All @@ -154,12 +155,12 @@ fn check_function_1() {
volume: 1.0,
language: Languages::Telugu,
};
narrator.speak("Starting test?");
narrator.speak("Starting test?").unwrap();
let ms = std::time::Duration::from_millis(1000);
for _x in 1..9 {
narrator.volume += 1.0;
let to_speak: String = String::from("Loop ") + &narrator.volume.to_string();
narrator.speak(&to_speak);
narrator.speak(&to_speak).unwrap();
std::thread::sleep(ms);
}
}
Expand Down

0 comments on commit 8437523

Please sign in to comment.