Share prepared audio names and speaker identities
This commit is contained in:
@@ -3,6 +3,7 @@ package stage
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/audio"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -17,8 +18,8 @@ func TestLocalAudioDestinationsPreserveDistinctRecordings(t *testing.T) {
|
||||
generated := "one-" + hex.EncodeToString(digest[:8]) + ".flac"
|
||||
third := filepath.Join(t.TempDir(), generated)
|
||||
inputs := []string{first, second, third}
|
||||
destinations := localAudioDestinations(inputs)
|
||||
if reversed := localAudioDestinations([]string{third, second, first}); !reflect.DeepEqual(reversed, destinations) {
|
||||
destinations := audio.PreparedNames(inputs)
|
||||
if reversed := audio.PreparedNames([]string{third, second, first}); !reflect.DeepEqual(reversed, destinations) {
|
||||
t.Fatal("destination ownership depends on input order")
|
||||
}
|
||||
if destinations[third] != generated {
|
||||
|
||||
@@ -366,7 +366,7 @@ func resolveLocalAudioFiles(sessionDir string, inputs config.SessionInputsConfig
|
||||
}
|
||||
|
||||
func materializeLocalAudioInputs(env *Env, paths artifacts.SessionPaths, resolvedAudio []string, registerInput func(kind, path, checksum string)) error {
|
||||
destinations := localAudioDestinations(resolvedAudio)
|
||||
destinations := audio.PreparedNames(resolvedAudio)
|
||||
for _, src := range resolvedAudio {
|
||||
dst := filepath.Join(paths.AudioDir, destinations[src])
|
||||
checksum, err := copyFileIfChanged(env.ArtifactStore, src, dst)
|
||||
@@ -378,43 +378,6 @@ func materializeLocalAudioInputs(env *Env, paths artifacts.SessionPaths, resolve
|
||||
return nil
|
||||
}
|
||||
|
||||
func localAudioDestinations(audioPaths []string) map[string]string {
|
||||
byBase := make(map[string][]string, len(audioPaths))
|
||||
occupied := make(map[string]bool, len(audioPaths))
|
||||
for _, audioPath := range audioPaths {
|
||||
base := filepath.Base(audioPath)
|
||||
byBase[base] = append(byBase[base], audioPath)
|
||||
occupied[base] = true
|
||||
}
|
||||
|
||||
destinations := make(map[string]string, len(audioPaths))
|
||||
ordered := append([]string(nil), audioPaths...)
|
||||
sort.Strings(ordered)
|
||||
nextSuffix := make(map[string]int)
|
||||
for _, source := range ordered {
|
||||
if _, assigned := destinations[source]; assigned {
|
||||
continue
|
||||
}
|
||||
base := filepath.Base(source)
|
||||
if len(byBase[base]) == 1 {
|
||||
destinations[source] = base
|
||||
continue
|
||||
}
|
||||
extension := filepath.Ext(base)
|
||||
stem := strings.TrimSuffix(base, extension)
|
||||
digest := sha256.Sum256([]byte(filepath.Clean(source)))
|
||||
generatedStem := stem + "-" + hex.EncodeToString(digest[:8])
|
||||
candidate := generatedStem + extension
|
||||
for occupied[candidate] {
|
||||
nextSuffix[generatedStem+extension]++
|
||||
candidate = fmt.Sprintf("%s-%d%s", generatedStem, nextSuffix[generatedStem+extension], extension)
|
||||
}
|
||||
destinations[source] = candidate
|
||||
occupied[candidate] = true
|
||||
}
|
||||
return destinations
|
||||
}
|
||||
|
||||
type s3AudioMaterializationStats struct {
|
||||
Reused int
|
||||
Downloads int
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/audio"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -213,7 +214,7 @@ func currentPrepareAudioSourceInputs(ctx context.Context, env *Env, m *manifest.
|
||||
return expected, nil
|
||||
}
|
||||
|
||||
destinations := localAudioDestinations(local)
|
||||
destinations := audio.PreparedNames(local)
|
||||
expected := make([]prepareExpectedInput, 0, len(local))
|
||||
for _, source := range local {
|
||||
checksum, err := env.ArtifactStore.Checksum(source)
|
||||
|
||||
@@ -2,6 +2,7 @@ package stage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/audio"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -138,7 +139,7 @@ func prepareAudioSemantics(cfg *config.Config) prepareAudioSelection {
|
||||
selection := prepareAudioSelection{Mode: "local_directory"}
|
||||
if len(inputs.AudioFiles) > 0 {
|
||||
selection.Mode = "local_files"
|
||||
destinations := localAudioDestinations(inputs.AudioFiles)
|
||||
destinations := audio.PreparedNames(inputs.AudioFiles)
|
||||
for _, name := range destinations {
|
||||
selection.LocalNames = append(selection.LocalNames, filepath.ToSlash(name))
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/whisperx"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/audio"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
@@ -178,16 +179,15 @@ func buildTranscribeJobs(m *manifest.Manifest, paths artifacts.SessionPaths) ([]
|
||||
return nil, err
|
||||
}
|
||||
jobs := make([]transcribeJob, 0, len(audioFiles))
|
||||
seenSpeaker := map[string]string{}
|
||||
sources := make([]audio.Source, 0, len(audioFiles))
|
||||
for _, audioPath := range audioFiles {
|
||||
base := strings.TrimSuffix(filepath.Base(audioPath), filepath.Ext(audioPath))
|
||||
if base == "" {
|
||||
return nil, fmt.Errorf("could not derive speaker id from %q", audioPath)
|
||||
}
|
||||
if previous, exists := seenSpeaker[base]; exists {
|
||||
return nil, fmt.Errorf("duplicate speaker/audio basename %q from %q and %q", base, previous, audioPath)
|
||||
}
|
||||
seenSpeaker[base] = audioPath
|
||||
sources = append(sources, audio.Source{Path: audioPath, PreparedName: filepath.Base(audioPath)})
|
||||
}
|
||||
if err := audio.ValidateSpeakerIDs(sources); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, audioPath := range audioFiles {
|
||||
base := audio.SpeakerID(audioPath)
|
||||
jobs = append(jobs, transcribeJob{
|
||||
speakerID: base,
|
||||
audioPath: audioPath,
|
||||
|
||||
Reference in New Issue
Block a user