From 8a68843bc65616b5f73582b21a2cedc5a7e7ac9a Mon Sep 17 00:00:00 2001 From: Chigozirim Igweamaka Date: Tue, 15 Jul 2025 15:37:28 +0100 Subject: [PATCH] refactor: simplify WAV conversion and fingerprinting process --- server/cmdHandlers.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/cmdHandlers.go b/server/cmdHandlers.go index b04ede5..6defb35 100644 --- a/server/cmdHandlers.go +++ b/server/cmdHandlers.go @@ -34,19 +34,24 @@ const ( var yellow = color.New(color.FgYellow) func find(filePath string) { - wavInfo, err := wav.ReadWavInfo(filePath) + wavFilePath, err := wav.ConvertToWAV(filePath) if err != nil { - yellow.Println("Error reading wave info:", err) + yellow.Println("Error converting to WAV:", err) return } - samples, err := wav.WavBytesToSamples(wavInfo.Data) + fingerprint, err := shazam.FingerprintAudio(wavFilePath, utils.GenerateUniqueID()) if err != nil { - yellow.Println("Error converting to samples:", err) + yellow.Println("Error generating fingerprint for sample: ", err) return } - matches, searchDuration, err := shazam.FindMatches(samples, wavInfo.Duration, wavInfo.SampleRate) + sampleFingerprint := make(map[uint32]uint32) + for address, couple := range fingerprint { + sampleFingerprint[address] = couple.AnchorTimeMs + } + + matches, searchDuration, err := shazam.FindMatchesFGP(sampleFingerprint) if err != nil { yellow.Println("Error finding matches:", err) return