From 2fab4c5f02abf7c2ad7796fb5affffdc374fb59c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 1 Apr 2026 14:26:25 +0300 Subject: zi: add Gemini audio attribution helper --- internal/audio/attribution.go | 14 ++++++++-- internal/audio/attribution_test.go | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 internal/audio/attribution_test.go 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) + } + }) + } +} -- cgit v1.2.3