コード例 #1
0
 def __init__(
     self,
     sounds_path=None,
     min_snr_in_db=3,
     max_snr_in_db=30,
     p=0.5,
     lru_cache_size=2,
 ):
     """
     :param sounds_path: Path to a folder that contains sound files to randomly mix in. These
         files can be flac, mp3, ogg or wav.
     :param min_snr_in_db: Minimum signal-to-noise ratio in dB
     :param max_snr_in_db: Maximum signal-to-noise ratio in dB
     :param p:
     :param lru_cache_size: Maximum size of the LRU cache for storing noise files in memory
     """
     super().__init__(p)
     self.sound_file_paths = get_file_paths(sounds_path)
     self.sound_file_paths = [str(p) for p in self.sound_file_paths]
     assert len(self.sound_file_paths) > 0
     self.min_snr_in_db = min_snr_in_db
     self.max_snr_in_db = max_snr_in_db
     self._load_sound = functools.lru_cache(maxsize=lru_cache_size)(
         AddBackgroundNoise._load_sound
     )
コード例 #2
0
 def __init__(
     self,
     ir_path="/tmp/ir",
     p=0.5,
     lru_cache_size=128,
     leave_length_unchanged: bool = False,
 ):
     """
     :param ir_path: Path to a folder that contains one or more wav files of impulse
     responses. Must be str or a Path instance.
     :param p:
     :param lru_cache_size: Maximum size of the LRU cache for storing impulse response files
     in memory.
     :param leave_length_unchanged: When set to True, the tail of the sound (e.g. reverb at
         the end) will be chopped off so that the length of the output is equal to the
         length of the input.
     """
     super().__init__(p)
     self.ir_files = get_file_paths(ir_path)
     self.ir_files = [str(p) for p in self.ir_files]
     assert len(self.ir_files) > 0
     self.__load_ir = functools.lru_cache(maxsize=lru_cache_size)(
         AddImpulseResponse.__load_ir
     )
     self.leave_length_unchanged = leave_length_unchanged
コード例 #3
0
 def test_get_file_paths_uppercase_extension(self):
     file_paths = get_file_paths(DEMO_DIR, traverse_subdirectories=False)
     found_it = False
     for file_path in file_paths:
         if file_path.name == "stereo_24bit.WAV":
             found_it = True
             break
     self.assertTrue(found_it)
コード例 #4
0
 def __init__(self, ir_path="/tmp/ir", p=0.5):
     """
     :param ir_path: Path to a folder that contains one or more wav files of impulse
     responses. Must be str or a Path instance.
     :param p:
     """
     super().__init__(p)
     self.ir_files = get_file_paths(ir_path)
     self.ir_files = [str(p) for p in self.ir_files]
     assert len(self.ir_files) > 0
コード例 #5
0
ファイル: transforms.py プロジェクト: alumae/audiomentations
 def __init__(self, ir_path="/tmp/ir", p=0.5, lru_cache_size=128):
     """
     :param ir_path: Path to a folder that contains one or more wav files of impulse
     responses. Must be str or a Path instance.
     :param p:
     :param lru_cache_size: Maximum size of the LRU cache for storing impuls files 
     in memory.
     """
     super().__init__(p)
     self.ir_files = get_file_paths(ir_path)
     self.ir_files = [str(p) for p in self.ir_files]
     assert len(self.ir_files) > 0
     self.__load_ir = functools.lru_cache(
         maxsize=lru_cache_size)(AddImpulseResponse.__load_ir)
コード例 #6
0
ファイル: transforms.py プロジェクト: k-nar/audiomentations
 def __init__(self, sounds_path=None, min_snr_in_db=3, max_snr_in_db=30, p=0.5):
     """
     :param sounds_path: Path to a folder that contains sound files to randomly mix in. These
         files can be flac, mp3, ogg or wav.
     :param min_snr_in_db: Minimum signal-to-noise ratio in dB
     :param max_snr_in_db: Maximum signal-to-noise ratio in dB
     :param p:
     """
     super().__init__(p)
     self.sound_file_paths = get_file_paths(sounds_path)
     self.sound_file_paths = [str(p) for p in self.sound_file_paths]
     assert len(self.sound_file_paths) > 0
     self.min_snr_in_db = min_snr_in_db
     self.max_snr_in_db = max_snr_in_db
コード例 #7
0
    def __init__(
        self,
        sounds_path=None,
        min_snr_in_db=0,
        max_snr_in_db=24,
        min_time_between_sounds=4.0,
        max_time_between_sounds=16.0,
        burst_probability=0.22,
        min_pause_factor_during_burst=0.1,
        max_pause_factor_during_burst=1.1,
        min_fade_in_time=0.005,
        max_fade_in_time=0.08,
        min_fade_out_time=0.01,
        max_fade_out_time=0.1,
        p=0.5,
    ):
        """
        :param sounds_path: Path to a folder that contains sound files to randomly mix in. These
            files can be flac, mp3, ogg or wav.
        :param min_snr_in_db: Minimum signal-to-noise ratio in dB. A lower value means the added
            sounds/noises will be louder.
        :param max_snr_in_db: Maximum signal-to-noise ratio in dB. A lower value means the added
            sounds/noises will be louder.
        :param min_time_between_sounds: Minimum pause time between the added sounds/noises
        :param max_time_between_sounds: Maximum pause time between the added sounds/noises
        :param burst_probability: The probability of adding an extra sound/noise that overlaps
        :param min_pause_factor_during_burst: Min value of how far into the current sound (as
            fraction) the burst sound should start playing. The value must be greater than 0.
        :param max_pause_factor_during_burst: Max value of how far into the current sound (as
            fraction) the burst sound should start playing. The value must be greater than 0.
        :param min_fade_in_time: Min sound/noise fade in time in seconds. Use a value larger
            than 0 to avoid a "click" at the start of the sound/noise.
        :param max_fade_in_time: Min sound/noise fade out time in seconds. Use a value larger
            than 0 to avoid a "click" at the start of the sound/noise.
        :param min_fade_out_time: Min sound/noise fade out time in seconds. Use a value larger
            than 0 to avoid a "click" at the end of the sound/noise.
        :param max_fade_out_time: Max sound/noise fade out time in seconds. Use a value larger
            than 0 to avoid a "click" at the end of the sound/noise.
        :param p: The probability of applying this transform
        """
        super().__init__(p)
        self.sound_file_paths = get_file_paths(sounds_path)
        self.sound_file_paths = [str(p) for p in self.sound_file_paths]
        assert len(self.sound_file_paths) > 0
        assert min_snr_in_db <= max_snr_in_db
        assert min_time_between_sounds <= max_time_between_sounds
        assert 0.0 < burst_probability <= 1.0
        if burst_probability == 1.0:
            assert (min_pause_factor_during_burst > 0.0
                    )  # or else an infinite loop will occur
        assert 0.0 < min_pause_factor_during_burst <= 1.0
        assert max_pause_factor_during_burst > 0.0
        assert max_pause_factor_during_burst >= min_pause_factor_during_burst
        assert min_fade_in_time >= 0.0
        assert max_fade_in_time >= 0.0
        assert min_fade_in_time <= max_fade_in_time
        assert min_fade_out_time >= 0.0
        assert max_fade_out_time >= 0.0
        assert min_fade_out_time <= max_fade_out_time

        self.min_snr_in_db = min_snr_in_db
        self.max_snr_in_db = max_snr_in_db
        self.min_time_between_sounds = min_time_between_sounds
        self.max_time_between_sounds = max_time_between_sounds
        self.burst_probability = burst_probability
        self.min_pause_factor_during_burst = min_pause_factor_during_burst
        self.max_pause_factor_during_burst = max_pause_factor_during_burst
        self.min_fade_in_time = min_fade_in_time
        self.max_fade_in_time = max_fade_in_time
        self.min_fade_out_time = min_fade_out_time
        self.max_fade_out_time = max_fade_out_time