From fed73b6aad3292446c13436ffdaa76cd8522c727 Mon Sep 17 00:00:00 2001 From: Alisha Maddy <59581465+am831@users.noreply.github.com> Date: Fri, 10 May 2024 09:46:11 -0700 Subject: [PATCH] Replace print statements with logger.info() (#446) * segmentation class using silero * pipeline segmenter with transcriber * transcibe segments progress * fix arg error * pipeline segmenter with transcriber * unit test * implement pdac algorithm and remove segment_speech logic * fix segment len * fix pdac algorithm * remove unused param * change min segment size * add threshold filter * change default pause len * demucs class * pipeline with transcriber * fix issues * add dependency * write process output to file instead of console * create dataclass DenoisingConfig * hide denoise logic in transcriber * fix type error * unit test * fix args * fix dir name * fix unit test * remove demucs from setup.py * nits * fix cleanup * replace print statements * add config * fix syntax --- src/seamless_communication/denoise/demucs.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/seamless_communication/denoise/demucs.py b/src/seamless_communication/denoise/demucs.py index ae7c1904..2205a621 100644 --- a/src/seamless_communication/denoise/demucs.py +++ b/src/seamless_communication/denoise/demucs.py @@ -14,9 +14,17 @@ from dataclasses import dataclass from typing import Optional import os +import logging SAMPLING_RATE = 16000 +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s %(levelname)s -- %(name)s: %(message)s", +) + +logger = logging.getLogger("demucs") + @dataclass class DenoisingConfig: def __init__( @@ -45,17 +53,17 @@ def run_command_with_temp_file(self, cmd): with tempfile.NamedTemporaryFile(mode='w+', delete=False) as temp: self.temp_files.append(temp.name) result = sp.run(cmd, stdout=temp, stderr=temp, text=True) - # If there was an error, print the content of the file + # If there was an error, log the content of the file if result.returncode != 0: temp.seek(0) - print(temp.read()) + logger.info(temp.read()) def cleanup_temp_files(self): for temp_file in self.temp_files: try: os.remove(temp_file) except Exception as e: - print(f"Failed to remove temporary file: {temp_file}. Error: {e}") + logger.info(f"Failed to remove temporary file: {temp_file}. Error: {e}") def denoise(self, audio: Union[str, Tensor]): @@ -69,7 +77,7 @@ def denoise(self, audio: Union[str, Tensor]): audio = temp_wav.name if not Path(audio).exists(): - print("Input file does not exist.") + logger.info("Input file does not exist.") return None with tempfile.TemporaryDirectory() as temp_dir: @@ -85,13 +93,13 @@ def denoise(self, audio: Union[str, Tensor]): audio_name = audio_path.stem audio = [str(audio)] - print("Executing command:", " ".join(cmd)) + logger.info("Executing command:", " ".join(cmd)) self.run_command_with_temp_file(cmd + audio) separated_files = list(Path(temp_dir + "/htdemucs/" + audio_name).glob("*vocals.wav*")) if not separated_files: - print("Separated vocals file not found.") + logger.info("Separated vocals file not found.") return None waveform, sample_rate = torchaudio.load(separated_files[0])