Implement real transcribe stage
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
package whisperx
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var minimalTranscriptJSON = []byte(`{"schema":"speaker_transcript.v1","segments":[]}`)
|
||||
|
||||
// NoopClient is a deterministic no-op WhisperX adapter.
|
||||
type NoopClient struct{}
|
||||
@@ -10,6 +16,9 @@ func (n *NoopClient) Transcribe(ctx context.Context, req TranscribeRequest) (Tra
|
||||
if err := ctx.Err(); err != nil {
|
||||
return TranscribeResult{}, err
|
||||
}
|
||||
if err := writeMinimalJSON(req.OutputRawTranscriptPath); err != nil {
|
||||
return TranscribeResult{}, err
|
||||
}
|
||||
return TranscribeResult{
|
||||
OutputRawTranscriptPath: req.OutputRawTranscriptPath,
|
||||
Attempts: 1,
|
||||
@@ -22,9 +31,10 @@ func (n *NoopClient) Transcribe(ctx context.Context, req TranscribeRequest) (Tra
|
||||
|
||||
// FakeClient captures requests and returns deterministic responses for tests.
|
||||
type FakeClient struct {
|
||||
Requests []TranscribeRequest
|
||||
Err error
|
||||
Result TranscribeResult
|
||||
Requests []TranscribeRequest
|
||||
Err error
|
||||
Result TranscribeResult
|
||||
TranscribeFn func(ctx context.Context, req TranscribeRequest) (TranscribeResult, error)
|
||||
}
|
||||
|
||||
// Transcribe records the request and returns either configured error or result.
|
||||
@@ -33,6 +43,9 @@ func (f *FakeClient) Transcribe(ctx context.Context, req TranscribeRequest) (Tra
|
||||
return TranscribeResult{}, err
|
||||
}
|
||||
f.Requests = append(f.Requests, req)
|
||||
if f.TranscribeFn != nil {
|
||||
return f.TranscribeFn(ctx, req)
|
||||
}
|
||||
if f.Err != nil {
|
||||
return TranscribeResult{}, f.Err
|
||||
}
|
||||
@@ -46,5 +59,18 @@ func (f *FakeClient) Transcribe(ctx context.Context, req TranscribeRequest) (Tra
|
||||
if res.Metadata == nil {
|
||||
res.Metadata = map[string]any{"fake": true}
|
||||
}
|
||||
if err := writeMinimalJSON(res.OutputRawTranscriptPath); err != nil {
|
||||
return TranscribeResult{}, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func writeMinimalJSON(path string) error {
|
||||
if path == "" {
|
||||
return nil
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, minimalTranscriptJSON, 0o644)
|
||||
}
|
||||
|
||||
1
internal/adapters/whisperx/transcripts/raw/alice.json
Normal file
1
internal/adapters/whisperx/transcripts/raw/alice.json
Normal file
@@ -0,0 +1 @@
|
||||
{"schema":"speaker_transcript.v1","segments":[]}
|
||||
Reference in New Issue
Block a user