Selaa lähdekoodia

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
Alisha Maddy 1 vuosi sitten
vanhempi
commit
fed73b6aad
1 muutettua tiedostoa jossa 14 lisäystä ja 6 poistoa
  1. 14 6
      src/seamless_communication/denoise/demucs.py

+ 14 - 6
src/seamless_communication/denoise/demucs.py

@@ -14,9 +14,17 @@ from fairseq2.memory import MemoryBlock
 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 @@ class Demucs():
         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 @@ class Demucs():
                 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 @@ class Demucs():
             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])