commit
90d83bf739
@ -0,0 +1,48 @@
|
|||||||
|
"""Contain the online bayesian normalization augmentation model."""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from data_utils.augmentor.base import AugmentorBase
|
||||||
|
|
||||||
|
|
||||||
|
class OnlineBayesianNormalizationAugmentor(AugmentorBase):
|
||||||
|
"""Augmentation model for adding online bayesian normalization.
|
||||||
|
|
||||||
|
:param rng: Random generator object.
|
||||||
|
:type rng: random.Random
|
||||||
|
:param target_db: Target RMS value in decibels.
|
||||||
|
:type target_db: float
|
||||||
|
:param prior_db: Prior RMS estimate in decibels.
|
||||||
|
:type prior_db: float
|
||||||
|
:param prior_samples: Prior strength in number of samples.
|
||||||
|
:type prior_samples: int
|
||||||
|
:param startup_delay: Default 0.0s. If provided, this function will
|
||||||
|
accrue statistics for the first startup_delay
|
||||||
|
seconds before applying online normalization.
|
||||||
|
:type starup_delay: float.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
rng,
|
||||||
|
target_db,
|
||||||
|
prior_db,
|
||||||
|
prior_samples,
|
||||||
|
startup_delay=0.0):
|
||||||
|
self._target_db = target_db
|
||||||
|
self._prior_db = prior_db
|
||||||
|
self._prior_samples = prior_samples
|
||||||
|
self._rng = rng
|
||||||
|
self._startup_delay = startup_delay
|
||||||
|
|
||||||
|
def transform_audio(self, audio_segment):
|
||||||
|
"""Normalizes the input audio using the online Bayesian approach.
|
||||||
|
|
||||||
|
Note that this is an in-place transformation.
|
||||||
|
|
||||||
|
:param audio_segment: Audio segment to add effects to.
|
||||||
|
:type audio_segment: AudioSegment|SpeechSegment
|
||||||
|
"""
|
||||||
|
audio_segment.normalize_online_bayesian(self._target_db, self._prior_db,
|
||||||
|
self._prior_samples,
|
||||||
|
self._startup_delay)
|
@ -0,0 +1,33 @@
|
|||||||
|
"""Contain the resample augmentation model."""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from data_utils.augmentor.base import AugmentorBase
|
||||||
|
|
||||||
|
|
||||||
|
class ResampleAugmentor(AugmentorBase):
|
||||||
|
"""Augmentation model for resampling.
|
||||||
|
|
||||||
|
See more info here:
|
||||||
|
https://ccrma.stanford.edu/~jos/resample/index.html
|
||||||
|
|
||||||
|
:param rng: Random generator object.
|
||||||
|
:type rng: random.Random
|
||||||
|
:param new_sample_rate: New sample rate in Hz.
|
||||||
|
:type new_sample_rate: int
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, rng, new_sample_rate):
|
||||||
|
self._new_sample_rate = new_sample_rate
|
||||||
|
self._rng = rng
|
||||||
|
|
||||||
|
def transform_audio(self, audio_segment):
|
||||||
|
"""Resamples the input audio to a target sample rate.
|
||||||
|
|
||||||
|
Note that this is an in-place transformation.
|
||||||
|
|
||||||
|
:param audio: Audio segment to add effects to.
|
||||||
|
:type audio: AudioSegment|SpeechSegment
|
||||||
|
"""
|
||||||
|
audio_segment.resample(self._new_sample_rate)
|
@ -0,0 +1,47 @@
|
|||||||
|
"""Contain the speech perturbation augmentation model."""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from data_utils.augmentor.base import AugmentorBase
|
||||||
|
|
||||||
|
|
||||||
|
class SpeedPerturbAugmentor(AugmentorBase):
|
||||||
|
"""Augmentation model for adding speed perturbation.
|
||||||
|
|
||||||
|
See reference paper here:
|
||||||
|
http://www.danielpovey.com/files/2015_interspeech_augmentation.pdf
|
||||||
|
|
||||||
|
:param rng: Random generator object.
|
||||||
|
:type rng: random.Random
|
||||||
|
:param min_speed_rate: Lower bound of new speed rate to sample and should
|
||||||
|
not be smaller than 0.9.
|
||||||
|
:type min_speed_rate: float
|
||||||
|
:param max_speed_rate: Upper bound of new speed rate to sample and should
|
||||||
|
not be larger than 1.1.
|
||||||
|
:type max_speed_rate: float
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, rng, min_speed_rate, max_speed_rate):
|
||||||
|
if min_speed_rate < 0.9:
|
||||||
|
raise ValueError(
|
||||||
|
"Sampling speed below 0.9 can cause unnatural effects")
|
||||||
|
if max_speed_rate > 1.1:
|
||||||
|
raise ValueError(
|
||||||
|
"Sampling speed above 1.1 can cause unnatural effects")
|
||||||
|
self._min_speed_rate = min_speed_rate
|
||||||
|
self._max_speed_rate = max_speed_rate
|
||||||
|
self._rng = rng
|
||||||
|
|
||||||
|
def transform_audio(self, audio_segment):
|
||||||
|
"""Sample a new speed rate from the given range and
|
||||||
|
changes the speed of the given audio clip.
|
||||||
|
|
||||||
|
Note that this is an in-place transformation.
|
||||||
|
|
||||||
|
:param audio_segment: Audio segment to add effects to.
|
||||||
|
:type audio_segment: AudioSegment|SpeechSegment
|
||||||
|
"""
|
||||||
|
sampled_speed = self._rng.uniform(self._min_speed_rate,
|
||||||
|
self._max_speed_rate)
|
||||||
|
audio_segment.change_speed(sampled_speed)
|
@ -1,4 +1,4 @@
|
|||||||
SoundFile==0.9.0.post1
|
|
||||||
wget==3.2
|
wget==3.2
|
||||||
scipy==0.13.1
|
scipy==0.13.1
|
||||||
|
resampy==0.1.5
|
||||||
https://github.com/kpu/kenlm/archive/master.zip
|
https://github.com/kpu/kenlm/archive/master.zip
|
||||||
|
Loading…
Reference in new issue