// Required namespaces for working with NAudio, OpenAI, and Whisper libraries
using NAudio.Wave;
using OpenAI_API;
using OpenAI_API.Chat;
using OpenAI_API.Models;
using Whisper;

// Create a new instance of NAudioClass to handle audio recording
var recorder = new NAudioClass(deviceNumber: 2, outputFilePath: "recordedAudio.wav");
recorder.StartRecording(); // Start recording audio
Console.WriteLine("Recording... Press Enter to stop and save the file.");
Console.ReadLine(); // Wait for the user to press Enter to stop recording
recorder.StopRecording(); // Stop the recording and save the file

// Create a new instance of OpenAiService with your API key
var openAiService = new OpenAiService("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"); // Replace with your actual API key

// Translate the recorded audio to text
string translatedText = await openAiService.TranslateAudioAsync("recordedAudio.wav");

// Output the translated text
Console.WriteLine("Translated Text: " + translatedText);

// Ask the user if they want to use the translated text to ask ChatGPT
Console.WriteLine("Czy chcesz sie zapytać o to Chata?");
Console.WriteLine("1-Tak");
Console.WriteLine("1-Nie");
var response = Console.ReadLine();

if (response == "1")
{
    // Create a new conversation using OpenAiService
    var chat = openAiService.CreateConversation();
    chat.Model = Model.ChatGPTTurbo; // Set the model to ChatGPTTurbo
    chat.RequestParameters.Temperature = 0; // Set temperature parameter for response generation
    chat.AppendUserInput(translatedText); // Append the translated text as user input

    // Stream the response from ChatGPT and output it
    await chat.StreamResponseFromChatbotAsync(res =>
    {
        Console.Write(res); // Write each response part to the console
    });
}

