Skip to content

Commit

Permalink
style: format code for consistency and readability in TTS modules
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Jan 18, 2025
1 parent c544c96 commit 5ceaeef
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions crates/sherpa-rs/src/tts/kokoro.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{ mem, ptr::null };
use std::{mem, ptr::null};

use crate::{ utils::RawCStr, OnnxConfig };
use crate::{utils::RawCStr, OnnxConfig};
use eyre::Result;
use sherpa_rs_sys;

use super::{ CommonTtsConfig, TtsAudio };
use super::{CommonTtsConfig, TtsAudio};

pub struct KokoroTts {
tts: *const sherpa_rs_sys::SherpaOnnxOfflineTts,
Expand Down
6 changes: 3 additions & 3 deletions crates/sherpa-rs/src/tts/matcha.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{ mem, ptr::null };
use std::{mem, ptr::null};

use crate::{ utils::RawCStr, OnnxConfig };
use crate::{utils::RawCStr, OnnxConfig};
use eyre::Result;
use sherpa_rs_sys;

use super::{ CommonTtsConfig, TtsAudio };
use super::{CommonTtsConfig, TtsAudio};

pub struct MatchaTts {
tts: *const sherpa_rs_sys::SherpaOnnxOfflineTts,
Expand Down
10 changes: 5 additions & 5 deletions crates/sherpa-rs/src/tts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ mod kokoro;
mod matcha;
mod vits;

use eyre::{ bail, Result };
use eyre::{bail, Result};

pub use kokoro::{ KokoroTts, KokoroTtsConfig };
pub use matcha::{ MatchaTts, MatchaTtsConfig };
pub use vits::{ VitsTts, VitsTtsConfig };
pub use kokoro::{KokoroTts, KokoroTtsConfig};
pub use matcha::{MatchaTts, MatchaTtsConfig};
pub use vits::{VitsTts, VitsTtsConfig};

use crate::utils::RawCStr;

Expand Down Expand Up @@ -59,7 +59,7 @@ pub unsafe fn create(
tts: *const sherpa_rs_sys::SherpaOnnxOfflineTts,
text: &str,
sid: i32,
speed: f32
speed: f32,
) -> Result<TtsAudio> {
let text = RawCStr::new(text);
let audio_ptr = sherpa_rs_sys::SherpaOnnxOfflineTtsGenerate(tts, text.as_ptr(), sid, speed);
Expand Down
6 changes: 3 additions & 3 deletions crates/sherpa-rs/src/tts/vits.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{ mem, ptr::null };
use std::{mem, ptr::null};

use crate::{ utils::RawCStr, OnnxConfig };
use crate::{utils::RawCStr, OnnxConfig};
use eyre::Result;
use sherpa_rs_sys;

use super::{ CommonTtsConfig, TtsAudio };
use super::{CommonTtsConfig, TtsAudio};

pub struct VitsTts {
tts: *const sherpa_rs_sys::SherpaOnnxOfflineTts,
Expand Down
6 changes: 4 additions & 2 deletions examples/tts_kokoro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tar xf kokoro-en-v0_19.tar.bz2
rm kokoro-en-v0_19.tar.bz2
cargo run --example tts_kokoro
*/
pub use sherpa_rs::tts::{ KokoroTts, KokoroTtsConfig };
pub use sherpa_rs::tts::{KokoroTts, KokoroTtsConfig};

fn main() {
let config = KokoroTtsConfig {
Expand All @@ -20,7 +20,9 @@ fn main() {
// 0->af, 1->af_bella, 2->af_nicole, 3->af_sarah, 4->af_sky, 5->am_adam
// 6->am_michael, 7->bf_emma, 8->bf_isabella, 9->bm_george, 10->bm_lewis
let sid = 0;
let audio = tts.create("Hello! This audio generated by Kokoro!", sid, 1.0).unwrap();
let audio = tts
.create("Hello! This audio generated by Kokoro!", sid, 1.0)
.unwrap();
sherpa_rs::write_audio_file("audio.wav", &audio.samples, audio.sample_rate).unwrap();
println!("Created audio.wav")
}
6 changes: 4 additions & 2 deletions examples/tts_vits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ wget https://huggingface.co/csukuangfj/vits-ljs/resolve/main/lexicon.txt
wget https://huggingface.co/csukuangfj/vits-ljs/resolve/main/tokens.txt
cargo run --example tts_vits --features="tts"
*/
pub use sherpa_rs::tts::{ VitsTts, VitsTtsConfig };
pub use sherpa_rs::tts::{VitsTts, VitsTtsConfig};

fn main() {
let config = VitsTtsConfig {
Expand All @@ -16,7 +16,9 @@ fn main() {
};
let mut tts = VitsTts::new(config);
let sid = 0;
let audio = tts.create("Hello! This audio generated by onnx model!", sid, 1.0).unwrap();
let audio = tts
.create("Hello! This audio generated by onnx model!", sid, 1.0)
.unwrap();
sherpa_rs::write_audio_file("audio.wav", &audio.samples, audio.sample_rate).unwrap();
println!("Created audio.wav")
}

0 comments on commit 5ceaeef

Please sign in to comment.