1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package audio
import (
"fmt"
"path/filepath"
"strings"
"time"
)
// AttributionParams describes metadata included in OpenAI TTS attribution files.
type AttributionParams struct {
Word string
Model string
Voice string
Instruction string
ProcessedText string
Speed float64
GeneratedAt time.Time
}
// AttributionPath returns the sidecar attribution file path for a generated audio file.
func AttributionPath(audioFile string) string {
return strings.TrimSuffix(audioFile, filepath.Ext(audioFile)) + "_attribution.txt"
}
// BuildOpenAIAttribution builds the attribution content for OpenAI-generated audio.
func BuildOpenAIAttribution(params AttributionParams) string {
var b strings.Builder
b.WriteString("Audio generated by OpenAI TTS\n\n")
fmt.Fprintf(&b, "Bulgarian word: %s\n", params.Word)
fmt.Fprintf(&b, "Model: %s\n", params.Model)
fmt.Fprintf(&b, "Voice: %s\n", params.Voice)
fmt.Fprintf(&b, "Speed: %.2f\n", params.Speed)
if params.Instruction != "" {
fmt.Fprintf(&b, "\nVoice instructions:\n%s\n", params.Instruction)
}
if params.ProcessedText != "" {
fmt.Fprintf(&b, "\nProcessed text sent to TTS: %s\n", params.ProcessedText)
}
generatedAt := params.GeneratedAt
if generatedAt.IsZero() {
generatedAt = time.Now()
}
fmt.Fprintf(&b, "\nGenerated at: %s\n", generatedAt.Format("2006-01-02 15:04:05"))
return b.String()
}
|