mirror of
https://github.com/cgzirim/seek-tune.git
synced 2025-12-17 17:04:22 +00:00
Write ReformatWav function
This commit is contained in:
parent
be91117a39
commit
8d9608c3cb
1 changed files with 27 additions and 1 deletions
|
|
@ -14,7 +14,7 @@ func ConvertToWAV(inputFilePath string, channels int) (wavFilePath string, errr
|
|||
return "", fmt.Errorf("input file does not exist: %v", err)
|
||||
}
|
||||
|
||||
if channels != 1 || channels != 2 {
|
||||
if channels < 1 || channels > 2 {
|
||||
channels = 1
|
||||
}
|
||||
|
||||
|
|
@ -39,3 +39,29 @@ func ConvertToWAV(inputFilePath string, channels int) (wavFilePath string, errr
|
|||
|
||||
return outputFile, nil
|
||||
}
|
||||
|
||||
func ReformatWAV(inputFilePath string, channels int) (reformatedFilePath string, errr error) {
|
||||
if channels < 1 || channels > 2 {
|
||||
channels = 1
|
||||
}
|
||||
|
||||
fileExt := filepath.Ext(inputFilePath)
|
||||
outputFile := strings.TrimSuffix(inputFilePath, fileExt) + "rfm.wav"
|
||||
|
||||
cmd := exec.Command(
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-i", inputFilePath,
|
||||
"-c", "pcm_s16le",
|
||||
"-ar", "44100",
|
||||
"-ac", fmt.Sprint(channels),
|
||||
outputFile,
|
||||
)
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to convert to WAV: %v, output %v", err, string(output))
|
||||
}
|
||||
|
||||
return outputFile, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue