summaryrefslogtreecommitdiff
path: root/internal/audio
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-01 14:26:25 +0300
committerPaul Buetow <paul@buetow.org>2026-04-01 14:26:25 +0300
commit2fab4c5f02abf7c2ad7796fb5affffdc374fb59c (patch)
tree2f3100fe7de05d9c7fd97c4c175015b8d1209b15 /internal/audio
parentdb5a777d3c2efafeed86e4b6f561a4ef45dbba22 (diff)
zi: add Gemini audio attribution helper
Diffstat (limited to 'internal/audio')
-rw-r--r--internal/audio/attribution.go14
-rw-r--r--internal/audio/attribution_test.go57
2 files changed, 69 insertions, 2 deletions
diff --git a/internal/audio/attribution.go b/internal/audio/attribution.go
index 80f2bc3..7c3cda2 100644
--- a/internal/audio/attribution.go
+++ b/internal/audio/attribution.go
@@ -7,7 +7,7 @@ import (
"time"
)
-// AttributionParams describes metadata included in OpenAI TTS attribution files.
+// AttributionParams describes metadata included in generated audio attribution files.
type AttributionParams struct {
Word string
Model string
@@ -25,8 +25,18 @@ func AttributionPath(audioFile string) string {
// BuildOpenAIAttribution builds the attribution content for OpenAI-generated audio.
func BuildOpenAIAttribution(params AttributionParams) string {
+ return buildAttribution("Audio generated by OpenAI TTS", params)
+}
+
+// BuildGeminiAttribution builds the attribution content for Gemini-generated audio.
+func BuildGeminiAttribution(params AttributionParams) string {
+ return buildAttribution("Audio generated by Google Gemini TTS", params)
+}
+
+func buildAttribution(header string, params AttributionParams) string {
var b strings.Builder
- b.WriteString("Audio generated by OpenAI TTS\n\n")
+ b.WriteString(header)
+ b.WriteString("\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)
diff --git a/internal/audio/attribution_test.go b/internal/audio/attribution_test.go
new file mode 100644
index 0000000..2e310b4
--- /dev/null
+++ b/internal/audio/attribution_test.go
@@ -0,0 +1,57 @@
+package audio
+
+import (
+ "testing"
+ "time"
+)
+
+func TestBuildAttribution(t *testing.T) {
+ params := AttributionParams{
+ Word: "ябълка",
+ Model: "gpt-4o-mini-tts",
+ Voice: "alloy",
+ Instruction: "Speak clearly.",
+ ProcessedText: "ябълка...",
+ Speed: 1.25,
+ GeneratedAt: time.Date(2026, time.April, 1, 15, 4, 5, 0, time.UTC),
+ }
+
+ tests := []struct {
+ name string
+ got string
+ want string
+ }{
+ {
+ name: "openai",
+ got: BuildOpenAIAttribution(params),
+ want: "Audio generated by OpenAI TTS\n\n" +
+ "Bulgarian word: ябълка\n" +
+ "Model: gpt-4o-mini-tts\n" +
+ "Voice: alloy\n" +
+ "Speed: 1.25\n\n" +
+ "Voice instructions:\nSpeak clearly.\n\n" +
+ "Processed text sent to TTS: ябълка...\n\n" +
+ "Generated at: 2026-04-01 15:04:05\n",
+ },
+ {
+ name: "gemini",
+ got: BuildGeminiAttribution(params),
+ want: "Audio generated by Google Gemini TTS\n\n" +
+ "Bulgarian word: ябълка\n" +
+ "Model: gpt-4o-mini-tts\n" +
+ "Voice: alloy\n" +
+ "Speed: 1.25\n\n" +
+ "Voice instructions:\nSpeak clearly.\n\n" +
+ "Processed text sent to TTS: ябълка...\n\n" +
+ "Generated at: 2026-04-01 15:04:05\n",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if tt.got != tt.want {
+ t.Fatalf("unexpected attribution output\nwant:\n%q\n\ngot:\n%q", tt.want, tt.got)
+ }
+ })
+ }
+}