-
Notifications
You must be signed in to change notification settings - Fork 844
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
54 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 |
---|---|---|
|
@@ -4,4 +4,6 @@ logdir* | |
datasets | ||
.DS_Store | ||
outputs | ||
__* | ||
__* | ||
hparams/hparams.yaml | ||
tools |
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,46 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
#/usr/bin/python2 | ||
#!/usr/bin/env python | ||
|
||
from __future__ import print_function | ||
import os | ||
|
||
import librosa | ||
import numpy as np | ||
from scipy import signal | ||
|
||
def split_path(path): | ||
''' | ||
'a/b/c.wav' => ('a/b', 'c', 'wav') | ||
:param path: filepath = 'a/b/c.wav' | ||
:return: basename, filename, and extension = ('a/b', 'c', 'wav') | ||
''' | ||
basepath, filename = os.path.split(path) | ||
filename, extension = os.path.splitext(filename) | ||
return basepath, filename, extension | ||
|
||
def spectrogram2wav(mag, n_fft, win_length, hop_length, num_iters, phase_angle=None, length=None): | ||
assert(num_iters > 0) | ||
if phase_angle is None: | ||
phase_angle = np.pi * np.random.rand(*mag.shape) | ||
spec = mag * np.exp(1.j * phase_angle) | ||
for i in range(num_iters): | ||
wav = librosa.istft(spec, win_length=win_length, hop_length=hop_length, length=length) | ||
if i != num_iters - 1: | ||
spec = librosa.stft(wav, n_fft=n_fft, win_length=win_length, hop_length=hop_length) | ||
_, phase = librosa.magphase(spec) | ||
phase_angle = np.angle(phase) | ||
spec = mag * np.exp(1.j * phase_angle) | ||
return wav | ||
|
||
|
||
def preemphasis(x, coeff=0.97): | ||
return signal.lfilter([1, -coeff], [1], x) | ||
|
||
|
||
def inv_preemphasis(x, coeff=0.97): | ||
return signal.lfilter([1], [1, -coeff], x) | ||
|
||
|
||
def wav_random_crop(wav, sr, duration): | ||
assert (wav.ndim <= 2) | ||
|
||
target_len = sr * duration | ||
wav_len = wav.shape[-1] | ||
start = np.random.choice(range(np.maximum(1, wav_len - target_len)), 1)[0] | ||
end = start + target_len | ||
if wav.ndim == 1: | ||
wav = wav[start:end] | ||
else: | ||
wav = wav[:, start:end] | ||
return wav | ||
|
||
def remove_all_files(prefix): | ||
files = glob.glob(prefix + '*') | ||
for f in files: | ||
os.remove(f) |