/*
 * Copyright 2025 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// [START googlegenaisdk_textgen_transcript_with_gcs_audio]

using Google.GenAI;
using Google.GenAI.Types;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

public class TextGenTranscriptWithGcsAudio
{
    public async Task<string> GenerateContent(
        string projectId = "your-project-id",
        string location = "global",
        string model = "gemini-2.5-flash")
    {
        await using var client = new Client(
            project: projectId,
            location: location,
            vertexAI: true);

        var prompt = @"
            Transcribe the interview, in the format of timecode, speaker, caption.
            Use speaker A, speaker B, etc. to identify speakers.";

        var contents = new List<Content>
        {
            new Content
            {
                Role = "user",
                Parts = new List<Part>
                {
                    new Part
                    {
                        FileData = new FileData
                        {
                            FileUri = "gs://cloud-samples-data/generative-ai/audio/pixel.mp3",
                            MimeType = "audio/mpeg"
                        }
                    },
                    new Part { Text = prompt }
                }
            }
        };

        GenerateContentResponse response = await client.Models.GenerateContentAsync(
            model: model,
            contents: contents,
            // Required to enable timestamp understanding for audio-only files
            config: new GenerateContentConfig { AudioTimestamp = true });

        string responseText = response.Candidates[0].Content.Parts[0].Text;
        Console.WriteLine(responseText);
        // Example response:
        // [00:00:00] Speaker A: your devices are getting better over time...
        // [00:00:14] Speaker B: Welcome to the Made by Google podcast...
        // ...
        // [10:18:24] Speaker B: Thank you for listening to the Made by Google podcast...
        return responseText;
    }
}
// [END googlegenaisdk_textgen_transcript_with_gcs_audio]
