Spaces:
Running
Running
update
Browse files- main.py +1 -1
- toolbox/audio_edit/augment.py +6 -2
main.py
CHANGED
@@ -201,7 +201,7 @@ def when_click_mix_speech_and_noise(speech_t, noise_t, snr_db: float):
|
|
201 |
mix_signal = speech
|
202 |
try:
|
203 |
if sample_rate1 != sample_rate2:
|
204 |
-
raise AssertionError
|
205 |
|
206 |
if speech.dtype == np.int16:
|
207 |
speech = np.array(speech, dtype=np.float32)
|
|
|
201 |
mix_signal = speech
|
202 |
try:
|
203 |
if sample_rate1 != sample_rate2:
|
204 |
+
raise AssertionError(f"sr of speech: {sample_rate1}, sr of noise: {sample_rate2}")
|
205 |
|
206 |
if speech.dtype == np.int16:
|
207 |
speech = np.array(speech, dtype=np.float32)
|
toolbox/audio_edit/augment.py
CHANGED
@@ -4,8 +4,12 @@ import numpy as np
|
|
4 |
|
5 |
|
6 |
def mix_speech_and_noise(speech: np.ndarray, noise: np.ndarray, snr_db: float):
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
# np.float32, value between (-1, 1).
|
10 |
|
11 |
speech_power = np.mean(np.square(speech))
|
|
|
4 |
|
5 |
|
6 |
def mix_speech_and_noise(speech: np.ndarray, noise: np.ndarray, snr_db: float):
|
7 |
+
l1 = len(speech)
|
8 |
+
l2 = len(noise)
|
9 |
+
l = min(l1, l2)
|
10 |
+
speech = speech[:l]
|
11 |
+
noise = noise[:l]
|
12 |
+
|
13 |
# np.float32, value between (-1, 1).
|
14 |
|
15 |
speech_power = np.mean(np.square(speech))
|