From 2b85c7fd973e91f2b6dfb9979908e1b6b87c0415 Mon Sep 17 00:00:00 2001 From: Chigozirim Igweamaka Date: Tue, 15 Jul 2025 15:35:33 +0100 Subject: [PATCH] feat: update ConvertToWAV function to determine channels from environment variable --- server/wav/convert.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/wav/convert.go b/server/wav/convert.go index e587d6f..4262d20 100644 --- a/server/wav/convert.go +++ b/server/wav/convert.go @@ -6,18 +6,26 @@ import ( "os/exec" "path/filepath" "song-recognition/utils" + "strconv" "strings" ) // ConvertToWAV converts an input audio file to WAV format with specified channels. -func ConvertToWAV(inputFilePath string, channels int) (wavFilePath string, err error) { +func ConvertToWAV(inputFilePath string) (wavFilePath string, err error) { _, err = os.Stat(inputFilePath) if err != nil { return "", fmt.Errorf("input file does not exist: %v", err) } - if channels < 1 || channels > 2 { - channels = 1 + to_stereoStr := utils.GetEnv("FINGERPRINT_STEREO", "false") + to_stereo, err := strconv.ParseBool(to_stereoStr) + if err != nil { + return "", fmt.Errorf("failed to convert env variable (%s) to bool: %v", "FINGERPRINT_STEREO", err) + } + + channels := 1 + if to_stereo { + channels = 2 } fileExt := filepath.Ext(inputFilePath)