ソースを参照

feat: add init_logging option to allow users to use their own logging framework

oddlama 10 ヶ月 前
コミット
2d76fd4d78
2 ファイル変更22 行追加16 行削除
  1. 2 0
      README.md
  2. 20 16
      RealtimeSTT/audio_recorder.py

+ 2 - 0
README.md

@@ -271,6 +271,8 @@ When you initialize the `AudioToTextRecorder` class, you have various options to
 
 - **level** (int, default=logging.WARNING): Logging level.
 
+- **init_logging** (bool, default=True): Whether to initialize the logging framework. Set to False to manage this yourself.
+
 - **handle_buffer_overflow** (bool, default=True): If set, the system will log a warning when an input overflow occurs during recording and remove the data from the buffer.
 
 - **beam_size** (int, default=5): The beam size to use for beam search decoding.

+ 20 - 16
RealtimeSTT/audio_recorder.py

@@ -100,6 +100,7 @@ class AudioToTextRecorder:
                  use_microphone=True,
                  spinner=True,
                  level=logging.WARNING,
+                 init_logging=True,
 
                  # Realtime transcription parameters
                  enable_realtime_transcription=False,
@@ -192,6 +193,8 @@ class AudioToTextRecorder:
         - spinner (bool, default=True): Show spinner animation with current
             state.
         - level (int, default=logging.WARNING): Logging level.
+        - init_logging (bool, default=True): Whether to initialize
+            the logging framework. Set to False to manage this yourself.
         - enable_realtime_transcription (bool, default=False): Enables or
             disables real-time transcription of audio. When set to True, the
             audio will be transcribed continuously as it is being recorded.
@@ -369,26 +372,27 @@ class AudioToTextRecorder:
         self.initial_prompt = initial_prompt
         self.suppress_tokens = suppress_tokens
 
-        # Initialize the logging configuration with the specified level
-        log_format = 'RealTimeSTT: %(name)s - %(levelname)s - %(message)s'
+        if init_logging:
+            # Initialize the logging configuration with the specified level
+            log_format = 'RealTimeSTT: %(name)s - %(levelname)s - %(message)s'
 
-        # Create a logger
-        logger = logging.getLogger()
-        logger.setLevel(level)  # Set the root logger's level
+            # Create a logger
+            logger = logging.getLogger()
+            logger.setLevel(level)  # Set the root logger's level
 
-        # Create a file handler and set its level
-        file_handler = logging.FileHandler('realtimesst.log')
-        file_handler.setLevel(logging.DEBUG)
-        file_handler.setFormatter(logging.Formatter(log_format))
+            # Create a file handler and set its level
+            file_handler = logging.FileHandler('realtimesst.log')
+            file_handler.setLevel(logging.DEBUG)
+            file_handler.setFormatter(logging.Formatter(log_format))
 
-        # Create a console handler and set its level
-        console_handler = logging.StreamHandler()
-        console_handler.setLevel(level)
-        console_handler.setFormatter(logging.Formatter(log_format))
+            # Create a console handler and set its level
+            console_handler = logging.StreamHandler()
+            console_handler.setLevel(level)
+            console_handler.setFormatter(logging.Formatter(log_format))
 
-        # Add the handlers to the logger
-        logger.addHandler(file_handler)
-        logger.addHandler(console_handler)
+            # Add the handlers to the logger
+            logger.addHandler(file_handler)
+            logger.addHandler(console_handler)
 
         self.is_shut_down = False
         self.shutdown_event = mp.Event()