Files
transcribe/pkg/audio/audio.go
2026-01-17 19:18:58 -06:00

57 lines
994 B
Go

package audio
import (
"errors"
"os"
"path/filepath"
"strings"
)
// SupportedAudioFormats lists the audio formats that can be processed
type SupportedAudioFormats []string
var DefaultSupportedFormats = SupportedAudioFormats{
".mp3",
".wav",
".flac",
".m4a",
".ogg",
".opus",
}
// IsSupported checks if a file has a supported audio format
type AudioFile struct {
Path string
Format string
Size int64
}
func NewAudioFile(path string) (*AudioFile, error) {
fileInfo, err := os.Stat(path)
if err != nil {
return nil, err
}
ext := filepath.Ext(path)
if !IsSupported(ext) {
return nil, errors.New("unsupported audio format: " + ext)
}
return &AudioFile{
Path: path,
Format: ext,
Size: fileInfo.Size(),
}, nil
}
// IsSupported checks if the given extension is in supported formats
func IsSupported(ext string) bool {
ext = strings.ToLower(ext)
for _, format := range DefaultSupportedFormats {
if ext == format {
return true
}
}
return false
}