def inject_noise_sample(self, data, noise_path, noise_level):
    noise_len = get_audio_length(noise_path)
    data_len = (len(data) / self.sample_rate)
    noise_start = (np.random.rand() * (noise_len - data_len))
    noise_end = (noise_start + data_len)
    noise_dst = audio_with_sox(noise_path, self.sample_rate, noise_start, noise_end)
    assert (len(data) == len(noise_dst))
    noise_energy = np.sqrt((noise_dst.dot(noise_dst) / noise_dst.size))
    data_energy = np.sqrt((data.dot(data) / data.size))
    data += (((noise_level * noise_dst) * data_energy) / noise_energy)
    return data
def inject_noise_sample(self, data, noise_path, noise_level):
    noise_len = get_audio_length(noise_path)
    data_len = (len(data) / self.sample_rate)
    noise_start = (np.random.rand() * (noise_len - data_len))
    noise_end = (noise_start + data_len)
    noise_dst = audio_with_sox(noise_path, self.sample_rate, noise_start, noise_end)
    assert (len(data) == len(noise_dst))
    noise_energy = np.sqrt((noise_dst.dot(noise_dst) / noise_dst.size))
    data_energy = np.sqrt((data.dot(data) / data.size))
    data += (((noise_level * noise_dst) * data_energy) / noise_energy)
    return data