Accept selected audio formats in transcription
This commit is contained in:
@@ -507,10 +507,6 @@ func requireRegularReadableFile(path string, label string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func isFlac(path string) bool {
|
||||
return strings.EqualFold(filepath.Ext(path), ".flac")
|
||||
}
|
||||
|
||||
func copyFileIfChanged(store artifacts.Store, src, dst string) (string, error) {
|
||||
srcChecksum, err := store.Checksum(src)
|
||||
if err != nil {
|
||||
|
||||
@@ -206,7 +206,7 @@ func discoverPreparedAudio(m *manifest.Manifest, paths artifacts.SessionPaths) (
|
||||
}
|
||||
p := strings.TrimSpace(in.Path)
|
||||
if p == "" {
|
||||
continue
|
||||
return nil, fmt.Errorf("audio path is required")
|
||||
}
|
||||
fromManifest = append(fromManifest, artifacts.ResolveSessionLocalPathForRead(paths, p))
|
||||
}
|
||||
@@ -230,7 +230,7 @@ func discoverPreparedAudio(m *manifest.Manifest, paths artifacts.SessionPaths) (
|
||||
continue
|
||||
}
|
||||
p := filepath.Join(paths.AudioDir, entry.Name())
|
||||
if !isFlac(p) {
|
||||
if !audio.IsCandidate(p) {
|
||||
continue
|
||||
}
|
||||
out = append(out, p)
|
||||
@@ -248,13 +248,11 @@ func validateAudioFiles(paths []string) error {
|
||||
}
|
||||
seen := map[string]struct{}{}
|
||||
for _, p := range paths {
|
||||
clean := filepath.Clean(strings.TrimSpace(p))
|
||||
if clean == "" {
|
||||
trimmed := strings.TrimSpace(p)
|
||||
if trimmed == "" {
|
||||
return fmt.Errorf("audio path is required")
|
||||
}
|
||||
if !isFlac(clean) {
|
||||
return fmt.Errorf("audio file %q must have .flac extension", clean)
|
||||
}
|
||||
clean := filepath.Clean(trimmed)
|
||||
info, err := os.Stat(clean)
|
||||
if err != nil {
|
||||
return fmt.Errorf("audio file %q not found: %w", clean, err)
|
||||
|
||||
@@ -505,3 +505,57 @@ func verifyJSONFile(t *testing.T, path string) {
|
||||
t.Fatalf("json decode %q: %v", path, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranscribeManifestSelectsAnyAudioSuffix(t *testing.T) {
|
||||
env, m := setupTranscribeEnv(t, nil)
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
for _, name := range []string{"alice.mp3", "bob.unusual", "cara", "sidecar.wav"} {
|
||||
writeFile(t, filepath.Join(paths.AudioDir, name), name)
|
||||
}
|
||||
for _, name := range []string{"alice.mp3", "bob.unusual", "cara"} {
|
||||
m.Inputs = append(m.Inputs, manifest.InputRecord{Kind: "audio", Path: filepath.Join(paths.AudioDir, name)})
|
||||
}
|
||||
var speakers []string
|
||||
env.WhisperX = &whisperx.FakeClient{TranscribeFn: func(_ context.Context, req whisperx.TranscribeRequest) (whisperx.TranscribeResult, error) {
|
||||
speakers = append(speakers, req.SpeakerID)
|
||||
writeFile(t, req.OutputRawTranscriptPath, `{"segments":[]}`)
|
||||
return whisperx.TranscribeResult{OutputRawTranscriptPath: req.OutputRawTranscriptPath}, nil
|
||||
}}
|
||||
one := 1
|
||||
env.Config.Pipeline.WhisperX.Concurrency = &one
|
||||
if _, err := (transcribeStage{}).Run(context.Background(), env, m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !slices.Equal(speakers, []string{"alice", "bob", "cara"}) {
|
||||
t.Fatalf("speakers %v", speakers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranscribeAudioDiscoveryValidatesSelectedInputs(t *testing.T) {
|
||||
env, m := setupTranscribeEnv(t, nil)
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
for _, name := range []string{"one.FLAC", "two.mp3", "sidecar.txt", "unlisted"} {
|
||||
writeFile(t, filepath.Join(paths.AudioDir, name), "audio")
|
||||
}
|
||||
jobs, err := buildTranscribeJobs(m, paths)
|
||||
if err != nil || len(jobs) != 2 || jobs[0].speakerID != "one" || jobs[1].speakerID != "two" {
|
||||
t.Fatalf("fallback jobs %v: %v", jobs, err)
|
||||
}
|
||||
for _, inputs := range [][]string{{"missing.mp3"}, {""}, {"one.FLAC", "one.FLAC"}, {"two.mp3", "two.wav"}, {"directory"}} {
|
||||
writeFile(t, filepath.Join(paths.AudioDir, "two.wav"), "audio")
|
||||
if err := os.MkdirAll(filepath.Join(paths.AudioDir, "directory"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m.Inputs = nil
|
||||
for _, name := range inputs {
|
||||
path := name
|
||||
if name != "" {
|
||||
path = filepath.Join(paths.AudioDir, name)
|
||||
}
|
||||
m.Inputs = append(m.Inputs, manifest.InputRecord{Kind: "audio", Path: path})
|
||||
}
|
||||
if _, err := buildTranscribeJobs(m, paths); err == nil {
|
||||
t.Errorf("expected error for %v", inputs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user