mirror of
https://github.com/cgzirim/seek-tune.git
synced 2025-12-18 09:24:19 +00:00
Find and return search duration.
This commit is contained in:
parent
7a757abb37
commit
5d3dbf5d03
1 changed files with 7 additions and 7 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"song-recognition/utils"
|
"song-recognition/utils"
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
|
|
@ -17,12 +18,13 @@ type Match struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindMatches processes the audio samples and finds matches in the database
|
// FindMatches processes the audio samples and finds matches in the database
|
||||||
func FindMatches(audioSamples []float64, audioDuration float64, sampleRate int) ([]Match, error) {
|
func FindMatches(audioSamples []float64, audioDuration float64, sampleRate int) ([]Match, time.Duration, error) {
|
||||||
|
startTime := time.Now()
|
||||||
logger := utils.GetLogger()
|
logger := utils.GetLogger()
|
||||||
|
|
||||||
spectrogram, err := Spectrogram(audioSamples, sampleRate)
|
spectrogram, err := Spectrogram(audioSamples, sampleRate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get spectrogram of samples: %v", err)
|
return nil, time.Since(startTime), fmt.Errorf("failed to get spectrogram of samples: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
peaks := ExtractPeaks(spectrogram, audioDuration)
|
peaks := ExtractPeaks(spectrogram, audioDuration)
|
||||||
|
|
@ -35,13 +37,13 @@ func FindMatches(audioSamples []float64, audioDuration float64, sampleRate int)
|
||||||
|
|
||||||
db, err := utils.NewDbClient()
|
db, err := utils.NewDbClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, time.Since(startTime), err
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
m, err := db.GetCouples(addresses)
|
m, err := db.GetCouples(addresses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, time.Since(startTime), err
|
||||||
}
|
}
|
||||||
|
|
||||||
matches := map[uint32][][2]uint32{} // songID -> [(sampleTime, dbTime)]
|
matches := map[uint32][][2]uint32{} // songID -> [(sampleTime, dbTime)]
|
||||||
|
|
@ -68,7 +70,6 @@ func FindMatches(audioSamples []float64, audioDuration float64, sampleRate int)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Song: %v, Score: %v\n", song.Title, points)
|
|
||||||
match := Match{songID, song.Title, song.Artist, song.YouTubeID, timestamps[songID], points}
|
match := Match{songID, song.Title, song.Artist, song.YouTubeID, timestamps[songID], points}
|
||||||
matchList = append(matchList, match)
|
matchList = append(matchList, match)
|
||||||
}
|
}
|
||||||
|
|
@ -77,8 +78,7 @@ func FindMatches(audioSamples []float64, audioDuration float64, sampleRate int)
|
||||||
return matchList[i].Score > matchList[j].Score
|
return matchList[i].Score > matchList[j].Score
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Println("MatchList len: ", len(matchList))
|
return matchList, time.Since(startTime), nil
|
||||||
return matchList, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnalyzeRelativeTiming checks for consistent relative timing and returns a score
|
// AnalyzeRelativeTiming checks for consistent relative timing and returns a score
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue