Added AI Disabled mode
This commit is contained in:
		@@ -1,8 +1,10 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
from utils import config
 | 
			
		||||
# config may modify imports
 | 
			
		||||
import logging
 | 
			
		||||
import sentry_sdk
 | 
			
		||||
from sentry_sdk.integrations.logging import LoggingIntegration
 | 
			
		||||
from utils import config, LoopingTimer
 | 
			
		||||
from utils import LoopingTimer
 | 
			
		||||
from signal_processor import SoundSignalProcessor
 | 
			
		||||
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver, BirbnetesIoTPlatformRecordDriver
 | 
			
		||||
from actuator import Loudspeaker
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +1,19 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
import requests
 | 
			
		||||
from urllib.parse import urljoin
 | 
			
		||||
from pyAudioAnalysis.audioTrainTest import load_model, load_model_knn, classifier_wrapper
 | 
			
		||||
from utils import config
 | 
			
		||||
from .abcpreprocessor import AbcPreProcessor
 | 
			
		||||
import tempfile
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from pyAudioAnalysis import audioBasicIO
 | 
			
		||||
from pyAudioAnalysis import MidTermFeatures
 | 
			
		||||
import numpy
 | 
			
		||||
if not config.DISABLE_AI:
 | 
			
		||||
    import tempfile
 | 
			
		||||
    import requests
 | 
			
		||||
    from urllib.parse import urljoin
 | 
			
		||||
    import os
 | 
			
		||||
 | 
			
		||||
    from pyAudioAnalysis.audioTrainTest import load_model, load_model_knn, classifier_wrapper
 | 
			
		||||
    from pyAudioAnalysis import audioBasicIO
 | 
			
		||||
    from pyAudioAnalysis import MidTermFeatures
 | 
			
		||||
    import numpy
 | 
			
		||||
 | 
			
		||||
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver
 | 
			
		||||
 | 
			
		||||
@@ -24,7 +27,7 @@ __module_name__ = "soundpreprocessor"
 | 
			
		||||
__version__text__ = "1"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SoundPreProcessor(AbcPreProcessor):
 | 
			
		||||
class SoundPreProcessorLegit(AbcPreProcessor):
 | 
			
		||||
    """
 | 
			
		||||
    SoundPreProcessor class, responsible for detecting birb chirps in sound sample.
 | 
			
		||||
    """
 | 
			
		||||
@@ -142,3 +145,18 @@ class SoundPreProcessor(AbcPreProcessor):
 | 
			
		||||
            os.remove(self._temp_means_name)
 | 
			
		||||
        except FileNotFoundError:
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SoundPreProcessorDummy(AbcPreProcessor):
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        print("AI is disabled! Initializing dummy sound pre-processor...")
 | 
			
		||||
 | 
			
		||||
    def preprocesssignal(self, file_path) -> bool:
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if config.DISABLE_AI:
 | 
			
		||||
    SoundPreProcessor = SoundPreProcessorDummy
 | 
			
		||||
else:
 | 
			
		||||
    SoundPreProcessor = SoundPreProcessorLegit
 | 
			
		||||
 
 | 
			
		||||
@@ -32,3 +32,5 @@ SVM_MODEL_ID = os.environ.get("SVM_MODEL_ID")
 | 
			
		||||
API_URL = os.environ.get("API_URL", "http://localhost:8080")
 | 
			
		||||
REPORT_URL = os.environ.get("REPORT_URL", None)
 | 
			
		||||
REPORT_INTERVAL = float(os.environ.get("REPORT_INTERVAL", 15))
 | 
			
		||||
 | 
			
		||||
DISABLE_AI = os.environ.get("DISABLE_AI").lower() in ['yes', '1', 'true']
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user