From 3de3a3770c36d97db896a4a8236f41e8ba161be2 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 26 Dec 2019 05:10:08 -0500 Subject: [PATCH] add random sampling --- Cargo.lock | 1 + tacotron_melgan/Cargo.toml | 1 + tacotron_melgan/src/main.rs | 3 ++- tacotron_melgan/src/melgan.rs | 8 ++++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index adb739c3c5..2bfb617b20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1153,6 +1153,7 @@ name = "tacotron_melgan" version = "0.0.1" dependencies = [ "hound 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "tch 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/tacotron_melgan/Cargo.toml b/tacotron_melgan/Cargo.toml index 49fb92fe0d..271ec2fb4a 100644 --- a/tacotron_melgan/Cargo.toml +++ b/tacotron_melgan/Cargo.toml @@ -10,4 +10,5 @@ path = "src/main.rs" [dependencies] hound = "3.4.0" # wav codec +rand = "0.7.2" # random sampling for testing (TODO: temp) tch = "0.1.3" # libtorch bindings (pytorch) diff --git a/tacotron_melgan/src/main.rs b/tacotron_melgan/src/main.rs index 72cc562516..58ab2c6957 100644 --- a/tacotron_melgan/src/main.rs +++ b/tacotron_melgan/src/main.rs @@ -1,5 +1,6 @@ -extern crate tch; extern crate hound; +extern crate rand; +extern crate tch; use tch::vision::imagenet; use tch::vision::resnet; diff --git a/tacotron_melgan/src/melgan.rs b/tacotron_melgan/src/melgan.rs index 9d3fc919bb..fa263aeaa1 100644 --- a/tacotron_melgan/src/melgan.rs +++ b/tacotron_melgan/src/melgan.rs @@ -3,6 +3,8 @@ use tch::CModule; use tch; use tch::nn::Module; +use rand::Rng; + //const TACOTRON_MODEL_PATH : &'static str = "/home/bt/models/tacotron2-nvidia/tacotron2_statedict.pt"; //const MELGAN_MODEL_PATH : &'static str = "/home/bt/models/melgan-swpark/firstgo_a7c2351_1100.pt"; const WRAPPED_MODEL_PATH : &'static str = "/home/bt/dev/voder/tacotron_melgan/container.pt"; @@ -118,6 +120,12 @@ pub fn run_melgan() { println!("Data: {:?}", data.get(5000)); println!("Data: {:?}", data.get(10000)); + let mut rng = rand::thread_rng(); + for _ in 0..30 { + let ri = rng.gen_range(0, length); + println!("data[{}]: {:?}", ri, data.get(ri as usize)); + } + let spec = hound::WavSpec { channels: 1, sample_rate: 16000,