feat: complete MQ-only dispatcher and OSS upload flow
This commit is contained in:
@@ -62,10 +62,11 @@ type Config struct {
|
||||
}
|
||||
|
||||
type RecordingFact struct {
|
||||
Segment string
|
||||
Path string
|
||||
SHA256 string
|
||||
Bytes int
|
||||
Segment string
|
||||
Path string
|
||||
SHA256 string
|
||||
Bytes int // Complete file size, including the WAV header.
|
||||
DurationMS int64
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
@@ -385,7 +386,11 @@ func persistConversationRecordings(directory, channelID string, flowResult callf
|
||||
if err := writeWAV(path, pcm, 16000); err != nil {
|
||||
return inbound, nil, err
|
||||
}
|
||||
inbound = append(inbound, RecordingFact{Segment: fmt.Sprintf("inbound_turn_%02d", index+1), Path: path, SHA256: fileSHA256(path), Bytes: len(pcm)})
|
||||
digest, size, err := fileDigestAndSize(path)
|
||||
if err != nil {
|
||||
return inbound, nil, fmt.Errorf("hash inbound recording: %w", err)
|
||||
}
|
||||
inbound = append(inbound, RecordingFact{Segment: fmt.Sprintf("inbound_turn_%02d", index+1), Path: path, SHA256: digest, Bytes: size, DurationMS: int64(len(pcm)) * 1000 / 32000})
|
||||
}
|
||||
outbound := make([]RecordingFact, 0, len(flowResult.OutboundTurns))
|
||||
for index, pcm := range flowResult.OutboundTurns {
|
||||
@@ -393,7 +398,11 @@ func persistConversationRecordings(directory, channelID string, flowResult callf
|
||||
if err := writeWAV(path, pcm, 16000); err != nil {
|
||||
return inbound, outbound, err
|
||||
}
|
||||
outbound = append(outbound, RecordingFact{Segment: fmt.Sprintf("outbound_segment_%02d", index), Path: path, SHA256: fileSHA256(path), Bytes: len(pcm)})
|
||||
digest, size, err := fileDigestAndSize(path)
|
||||
if err != nil {
|
||||
return inbound, outbound, fmt.Errorf("hash outbound recording: %w", err)
|
||||
}
|
||||
outbound = append(outbound, RecordingFact{Segment: fmt.Sprintf("outbound_segment_%02d", index), Path: path, SHA256: digest, Bytes: size, DurationMS: int64(len(pcm)) * 1000 / 32000})
|
||||
}
|
||||
return inbound, outbound, nil
|
||||
}
|
||||
@@ -423,11 +432,11 @@ func writeWAV(path string, pcm []byte, sampleRate int) error {
|
||||
return os.WriteFile(path, buf, 0o600)
|
||||
}
|
||||
|
||||
func fileSHA256(path string) string {
|
||||
func fileDigestAndSize(path string) (string, int, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
return "", 0, err
|
||||
}
|
||||
sum := sha256.Sum256(data)
|
||||
return hex.EncodeToString(sum[:])
|
||||
return hex.EncodeToString(sum[:]), len(data), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user