From 112ddbe916b109a300fc5f618f2bb7191e0a2328 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Sat, 5 Sep 2020 12:32:53 -0400 Subject: [PATCH] Make fingerprint storage path configurable --- turntable.sample.json | 1 + turntable/application.py | 3 +++ turntable/turntable.py | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/turntable.sample.json b/turntable.sample.json index 84bf8b7..a40c1ce 100644 --- a/turntable.sample.json +++ b/turntable.sample.json @@ -11,6 +11,7 @@ "silence_threshold": 100, "check_interval": 0.5, "sample_seconds": 30, + "fingerprint_store_path": "/tmp/fingerprint.wav", "fingerprint_store_seconds": 30, "fingerprint_identify_seconds": 5, "fingerprint_delay": 5 diff --git a/turntable/application.py b/turntable/application.py index a73f39b..f9006c5 100644 --- a/turntable/application.py +++ b/turntable/application.py @@ -93,6 +93,9 @@ class Application: fingerprint_identify_seconds=turntable_config.get( "fingerprint_identify_seconds", 5 ), + fingerprint_store_path=turntable_config.get( + "fingerprint_store_path", "/tmp/fingerprint.wav" + ), fingerprint_store_seconds=turntable_config.get( "fingerprint_store_seconds", 30 ), diff --git a/turntable/turntable.py b/turntable/turntable.py index 906b64d..5aa2da4 100644 --- a/turntable/turntable.py +++ b/turntable/turntable.py @@ -60,11 +60,12 @@ class Turntable(Process): fingerprint_delay: int = 5, fingerprint_identify_delay: int = 5, fingerprint_identify_seconds: int = 5, + fingerprint_store_path: str = "/tmp/fingerprint.wav", fingerprint_store_seconds: int = 30, sample_seconds: int = 30, silence_threshold: int = 20, stop_delay: int = 5, - ) -> none: + ) -> None: super().__init__() maxlen = channels * 2 * framerate * sample_seconds self.buffer = PCM(framerate=framerate, channels=channels, maxlen=maxlen) @@ -78,6 +79,7 @@ class Turntable(Process): self.fingerprint_delay = fingerprint_delay self.fingerprint_identify_delay = fingerprint_identify_delay self.fingerprint_identify_seconds = fingerprint_identify_seconds + self.fingerprint_store_path = fingerprint_store_path self.fingerprint_store_seconds = fingerprint_store_seconds self.silence_threshold = silence_threshold self.stop_delay = stop_delay @@ -130,7 +132,7 @@ class Turntable(Process): ): startframe = -self.buffer.framerate * self.fingerprint_store_seconds sample = self.buffer[startframe:] - with wave.open("/tmp/fingerprint.wav", "wb") as wavfile: + with wave.open(self.fingerprint_store_path, "wb") as wavfile: wavfile.setsampwidth(2) wavfile.setnchannels(sample.channels) wavfile.setframerate(sample.framerate)