mirror of
https://github.com/cgzirim/seek-tune.git
synced 2025-12-18 09:24:19 +00:00
feat: implement FingerprintAudio function to process audio files and generate fingerprints
This commit is contained in:
parent
8a68843bc6
commit
64e8ee696d
1 changed files with 37 additions and 0 deletions
|
|
@ -1,7 +1,10 @@
|
||||||
package shazam
|
package shazam
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"song-recognition/models"
|
"song-recognition/models"
|
||||||
|
"song-recognition/utils"
|
||||||
|
"song-recognition/wav"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -44,3 +47,37 @@ func createAddress(anchor, target Peak) uint32 {
|
||||||
|
|
||||||
return address
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FingerprintAudio(songFilePath string, songID uint32) (map[uint32]models.Couple, error) {
|
||||||
|
wavFilePath, err := wav.ConvertToWAV(songFilePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error converting input file to WAV: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
wavInfo, err := wav.ReadWavInfo(wavFilePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error reading WAV info: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fingerprint := make(map[uint32]models.Couple)
|
||||||
|
|
||||||
|
spectro, err := Spectrogram(wavInfo.LeftChannelSamples, wavInfo.SampleRate)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error creating spectrogram: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
peaks := ExtractPeaks(spectro, wavInfo.Duration)
|
||||||
|
utils.ExtendMap(fingerprint, Fingerprint(peaks, songID))
|
||||||
|
|
||||||
|
if wavInfo.Channels == 2 {
|
||||||
|
spectro, err = Spectrogram(wavInfo.RightChannelSamples, wavInfo.SampleRate)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error creating spectrogram for right channel: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
peaks = ExtractPeaks(spectro, wavInfo.Duration)
|
||||||
|
utils.ExtendMap(fingerprint, Fingerprint(peaks, songID))
|
||||||
|
}
|
||||||
|
|
||||||
|
return fingerprint, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue