Make fingerprint storage path configurable

This commit is contained in:
Correl Roush 2020-09-05 12:32:53 -04:00
parent 6e12cc2a48
commit 112ddbe916
3 changed files with 8 additions and 2 deletions

View file

@ -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

View file

@ -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
),

View file

@ -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)