Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
output_fname,
n_fft=4096,
n_layers=1,
n_filters=4096,
hop_length=256,
alpha=0.05,
k_w=15,
k_h=3,
optimizer='bfgs',
stride=1,
iterations=300,
sr=22050):
frame_size = n_fft // 2
audio, fs = librosa.load(content_fname, sr=sr)
content = chop(audio, hop_size=hop_length, frame_size=frame_size)
audio, fs = librosa.load(style_fname, sr=sr)
style = chop(audio, hop_size=hop_length, frame_size=frame_size)
n_frames = min(content.shape[0], style.shape[0])
n_samples = min(content.shape[1], style.shape[1])
content = content[:n_frames, :n_samples]
style = style[:n_frames, :n_samples]
content_features, style_gram, kernels, freqs = compute_features(
content=content,
style=style,
stride=stride,
n_fft=n_fft,
n_layers=n_layers,
n_filters=n_filters,
def test_resample_vs_librosa_load(self):
# Check against librosa load function
a = nussl.AudioSignal(self.audio_input1)
a.resample(48000)
b_audio_data, b_sample_rate = librosa.load(self.audio_input1, sr=48000)
assert (a.sample_rate == b_sample_rate)
assert (np.allclose(a.audio_data, b_audio_data))
def test_sample_data():
y, sr = librosa.load(EXAMPLE_FILE)
assert audio.analysis_samples.all() == y.all()
if mask_type == 1:
mask = np.greater(np.abs(S), (gain * np.abs(L)))
S = S * mask
L = S_mix - S
voice = librosa.core.istft(S.T, hop_length=hop_size, win_length=win_size)
accom = librosa.core.istft(L.T, hop_length=hop_size, win_length=win_size)
voice = voice / np.max(np.abs(voice))
accom = accom / np.max(np.abs(accom))
return voice, accom
if __name__ == '__main__':
clip, fs = librosa.load('examples/c1.wav', mono=False,sr=44100)
clip = clip.T
clip = clip[:,1] + clip[:,0]
voice, accom = svs_RPCA(clip)
librosa.output.write_wav('voice.wav', voice, sr=44100)
librosa.output.write_wav('accom.wav', accom, sr=44100)
Arguments
---------
infile -- (str) path to input file
Returns
-------
analysis -- (dict) of various useful things
'''
A = {}
A['filename'] = infile
y, sr = librosa.load(infile, sr=SR)
# First, get the track duration
A['duration'] = float(len(y)) / sr
# Then, get the beats
tempo, beats = librosa.beat.beat_track(y, sr, hop_length=HOP)
# Push the last frame as a phantom beat
A['tempo'] = tempo
A['beats'] = librosa.frames_to_time(beats, sr, hop_length=HOP).tolist()
S = librosa.feature.melspectrogram(y, sr, n_fft=2048,
hop_length=HOP,
n_mels=80,
fmax=8000)
offset=clean_cfg["offset"]
)
random.shuffle(clean_speech_paths)
clean_ys = load_wavs(
file_paths=clean_speech_paths,
sr=clean_cfg["sampling_rate"],
min_sampling=clean_cfg["min_sampling"],
)
print("Loaded clean speeches.")
# 加载噪声信号,存至 dict 中
noise_cfg = dataset_cfg["noise"]
noise_database_dir = Path(noise_cfg["database"])
noise_ys = {}
for noise_type in tqdm(noise_cfg["types"], desc="Loading noise files"):
mixture, _ = librosa.load(
(noise_database_dir / (noise_type + ".wav")).as_posix(),
sr=noise_cfg["sampling_rate"])
noise_ys[noise_type] = mixture
print("Loaded noise.")
# 合成带噪语音
mixture_store = {}
clean_store = {}
for i, clean in tqdm(enumerate(clean_ys, start=1), desc="合成带噪语音"):
num = str(i).zfill(4)
for snr in dataset_cfg["snr"]:
for noise_type in noise_ys.keys():
basename_text = f"{num}_{noise_type}_{snr}"
clean, noise = corrected_the_length_of_noise_and_clean_speech(
clean_y=clean,
def __init__(self, noises_dir, snr_levels=[0, 5, 10], do_IRS=False,
prob=1):
self.prob = prob
self.noises_dir = noises_dir
self.snr_levels = snr_levels
self.do_IRS = do_IRS
# read noises in dir
noises = glob.glob(os.path.join(noises_dir, '*.wav'))
if len(noises) == 0:
raise ValueError('[!] No noises found in {}'.format(noises_dir))
else:
print('[*] Found {} noise files'.format(len(noises)))
self.noises = []
for n_i, npath in enumerate(noises, start=1):
#nwav = wavfile.read(npath)[1]
nwav = librosa.load(npath, sr=None)[0]
self.noises.append({'file':npath,
'data':nwav.astype(np.float32)})
log_noise_load = 'Loaded noise {:3d}/{:3d}: ' \
'{}'.format(n_i, len(noises),
npath)
print(log_noise_load)
self.eps = 1e-22
def thread_main(self, sess):
stop = False
while not stop:
for fname in self.fnames:
if self.coord.should_stop():
stop = True
break
try:
audio = librosa.load(fname, sr=self.sample_rate)[0]
except:
print 'could not read file', fname, 'skipping...'
continue
rand_start_idx = np.random.randint(0, len(audio) - self.sample_rate * self.seconds_of_audio)
audio = audio[rand_start_idx:rand_start_idx + self.sample_rate * self.seconds_of_audio]
label = self.data_dict[fname]
sess.run(self.enqueue_op, feed_dict={self.x: audio, self.y: label})
def process_stft(f):
y, sr = librosa.load(f, sr=config.samplerate)
if config.pre_emphasis:
y = pre_emphasis(y)
linearspec = np.transpose(np.abs(
librosa.core.stft(y, config.fft_size,
config.hop_size)))
return linearspec, y