refactor(voice): share audio format support and restrict transcriber selection

This commit is contained in:
RussellLuo
2026-03-22 23:40:13 +08:00
parent 92678d1700
commit 4d2b244522
4 changed files with 68 additions and 23 deletions
+16 -1
View File
@@ -1,6 +1,7 @@
package utils
import (
"fmt"
"io"
"net/http"
"net/url"
@@ -15,9 +16,23 @@ import (
"github.com/sipeed/picoclaw/pkg/media"
)
var (
audioExtensions = []string{".mp3", ".wav", ".ogg", ".m4a", ".flac", ".aac", ".wma"}
)
func AudioFormat(path string) (string, error) {
ext := strings.ToLower(filepath.Ext(path))
for _, supportedExt := range audioExtensions {
if ext == supportedExt {
return strings.TrimPrefix(ext, "."), nil
}
}
return "", fmt.Errorf("unsupported audio format for %q", path)
}
// IsAudioFile checks if a file is an audio file based on its filename extension and content type.
func IsAudioFile(filename, contentType string) bool {
audioExtensions := []string{".mp3", ".wav", ".ogg", ".m4a", ".flac", ".aac", ".wma"}
audioTypes := []string{"audio/", "application/ogg", "application/x-ogg"}
for _, ext := range audioExtensions {