-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from emotechlab/docs/super-guide-time
Tutorial stuff
- Loading branch information
Showing
26 changed files
with
354 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Checks | ||
|
||
on: | ||
push: | ||
branches: ["master"] | ||
pull_request: | ||
jobs: | ||
build_and_test: | ||
name: Rust project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
components: rustfmt | ||
- name: Cargo build | ||
run: cargo build | ||
- name: Cargo test | ||
run: cargo test | ||
- name: Rustfmt | ||
run: cargo fmt --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,75 @@ | ||
use clap::Parser; | ||
use griffin_lim::GriffinLim; | ||
use hound::{SampleFormat, WavSpec, WavWriter}; | ||
use ndarray::prelude::*; | ||
use ndarray_npy::read_npy; | ||
use std::error::Error; | ||
use std::path::PathBuf; | ||
use std::result::Result; | ||
use std::time::Instant; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct Args { | ||
#[clap(long, short, default_value = "example_spectrogram.npy")] | ||
input: String, | ||
#[clap(short, long, default_value = "output.wav")] | ||
output: PathBuf, | ||
#[clap(long, default_value = "22050")] | ||
sample_rate: u32, | ||
#[clap(long, default_value = "1024")] | ||
ffts: usize, | ||
#[clap(long, default_value = "80")] | ||
mels: usize, | ||
#[clap(long, default_value = "256")] | ||
hop_length: usize, | ||
#[clap(long, default_value = "8000.0")] | ||
max_frequency: f32, | ||
#[clap(long, default_value = "1.7")] | ||
power: f32, | ||
#[clap(long, default_value = "10")] | ||
iters: usize, | ||
} | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let spectrogram: Array2<f32> = read_npy("resources/example_spectrogram.npy")?; | ||
|
||
let mel_basis = griffin_lim::mel::create_mel_filter_bank(22050.0, 1024, 80, 0.0, Some(8000.0)); | ||
|
||
for iter in [0, 1, 2, 5, 10] { | ||
let timer = Instant::now(); | ||
let mut vocoder = GriffinLim::new(mel_basis.clone(), 1024 - 256, 1.5, 1, 0.99)?; | ||
vocoder.iter = iter; | ||
let audio = vocoder.infer(&spectrogram)?; | ||
let duration = Instant::now().duration_since(timer); | ||
let rtf = duration.as_secs_f32() / (audio.len() as f32 / 22050_f32); | ||
println!("Iterations: {}, rtf: {}", iter, rtf); | ||
let spec = WavSpec { | ||
channels: 1, | ||
sample_rate: 22050, | ||
bits_per_sample: 32, | ||
sample_format: SampleFormat::Float, | ||
}; | ||
|
||
let mut writer = WavWriter::create(format!("audio_output_griffinlim_{}.wav", iter), spec)?; | ||
|
||
for sample in audio { | ||
writer.write_sample(sample)?; | ||
} | ||
|
||
writer.finalize()?; | ||
println!("Saved audio_output_griffinlim_{}.wav", iter); | ||
let args = Args::parse(); | ||
let spectrogram: Array2<f32> = read_npy(args.input)?; | ||
|
||
let mel_basis = griffin_lim::mel::create_mel_filter_bank( | ||
args.sample_rate as f32, | ||
args.ffts, | ||
args.mels, | ||
0.0, | ||
Some(args.max_frequency), | ||
); | ||
|
||
let timer = Instant::now(); | ||
let vocoder = GriffinLim::new( | ||
mel_basis.clone(), | ||
args.ffts - args.hop_length, | ||
args.power, | ||
args.iters, | ||
0.99, | ||
)?; | ||
let audio = vocoder.infer(&spectrogram)?; | ||
let duration = Instant::now().duration_since(timer); | ||
let rtf = duration.as_secs_f32() / (audio.len() as f32 / args.sample_rate as f32); | ||
println!("Iterations: {}, rtf: {}", args.iters, rtf); | ||
|
||
let spec = WavSpec { | ||
channels: 1, | ||
sample_rate: args.sample_rate, | ||
bits_per_sample: 16, | ||
sample_format: SampleFormat::Int, | ||
}; | ||
|
||
let mut wav_writer = WavWriter::create(&args.output, spec)?; | ||
|
||
let mut i16_writer = wav_writer.get_i16_writer(audio.len() as u32); | ||
for sample in &audio { | ||
i16_writer.write_sample((*sample * i16::MAX as f32) as i16); | ||
} | ||
i16_writer.flush()?; | ||
|
||
println!("Saved {}", args.output.display()); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
estimate_spec* |
Oops, something went wrong.