Skip to content

Commit

Permalink
Update noise suppression test-suites.
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-plus committed Jul 1, 2024
1 parent 8f9af1d commit 978303f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions openlrc/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def noise_suppression(self, audio_paths: Union[str, Path, List[str], List[Path]]
if not ns_path.exists():
audio, info = load_audio(audio_path, sr=df_state.sr())

# Split audio into 10 min chunks
# Split audio into 3 min chunks
audio_chunks = [audio[:, i:i + chunk_size * info.sample_rate]
for i in range(0, audio.shape[1], chunk_size * info.sample_rate)]

Expand All @@ -79,7 +79,7 @@ def noise_suppression(self, audio_paths: Union[str, Path, List[str], List[Path]]

enhanced = torch.cat(enhanced_chunks, dim=1)

assert enhanced.shape == audio.shape, 'Enhanced audio shape does not match original audio shape.'
assert enhanced.shape == audio.shape, f'Enhanced audio shape does not match original audio shape: {enhanced.shape} != {audio.shape}'

save_audio(ns_path, enhanced, sr=df_state.sr())

Expand Down
7 changes: 5 additions & 2 deletions tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ def tearDown(self) -> None:
@patch('openlrc.preprocess.release_memory')
def test_noise_suppression_returns_path_objects(self, mock_release_memory, mock_save_audio, mock_load_audio,
mock_init_df, mock_enhance):
mock_enhance.return_value = torch.zeros((2, 300 * 16000))
chunk_size = 180
mock_audio_size = chunk_size * 5

mock_enhance.return_value = torch.zeros((2, chunk_size * 16000))
mock_init_df.return_value = (Mock(), Mock(), Mock())

mock_info = Mock()
mock_info.sample_rate = 16000
mock_load_audio.return_value = (torch.zeros((2, 1200 * 16000)), mock_info)
mock_load_audio.return_value = (torch.zeros((2, mock_audio_size * 16000)), mock_info)

mock_save_audio.return_value = None
mock_release_memory.return_value = None
Expand Down

0 comments on commit 978303f

Please sign in to comment.