Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Aider chat conversation: USER: Add a new option to configuration form - default language. It should accept text as an input. Value from that option should be sent as language in AudioTranscriptionRequest. ASSISTANT: To add a new option for the default language in the configuration form and ensure that the value is used in the `AudioTranscriptionRequest`, we need to modify the following files: 1. `whisperer/ConfigForm.cs` - To add the new UI elements for the default language option and handle loading and saving of this setting. 2. `whisperer/ConfigurationManager.cs` - To add methods for reading and saving the default language setting. 3. `whisperer/Program.cs` - To modify the `TranscribeAudio` method to use the default language setting when creating the `AudioTranscriptionRequest`. Let's start with the `ConfigForm.cs` file to add the UI elements and logic for the default language setting. ```csharp whisperer/ConfigForm.cs <<<<<<< SEARCH private TableLayoutPanel tableLayoutPanel; ======= private TableLayoutPanel tableLayoutPanel; private TextBox defaultLanguageTextBox; private Label defaultLanguageLabel; >>>>>>> REPLACE ... <<<<<<< SEARCH private void InitializeFormControls() { InitializeTableLayoutPanel(); InitializeApiKeyControls(); InitializeHotkeyControls(); InitializeSaveButton(); InitializeCopyrightInformation(); } ======= private void InitializeFormControls() { InitializeTableLayoutPanel(); InitializeApiKeyControls(); InitializeHotkeyControls(); InitializeDefaultLanguageControls(); // Add this line InitializeSaveButton(); InitializeCopyrightInformation(); } private void InitializeDefaultLanguageControls() { defaultLanguageLabel = new Label { Text = "Default Language:" }; tableLayoutPanel.Controls.Add(defaultLanguageLabel, 0, 2); defaultLanguageTextBox = new TextBox { Width = 300 }; tableLayoutPanel.Controls.Add(defaultLanguageTextBox, 1, 2); LoadDefaultLanguage(); // Add this line } private void LoadDefaultLanguage() { defaultLanguageTextBox.Text = ConfigurationManager.ReadDefaultLanguage(); } >>>>>>> REPLACE ... <<<<<<< SEARCH private void saveButton_Click(object? sender, EventArgs e) { ConfigurationManager.SaveApiKey(apiKeyTextBox.Text); ConfigurationManager.SaveHotkey(currentHotkey); MessageBox.Show("Settings saved securely."); } ======= private void saveButton_Click(object? sender, EventArgs e) { ConfigurationManager.SaveApiKey(apiKeyTextBox.Text); ConfigurationManager.SaveHotkey(currentHotkey); ConfigurationManager.SaveDefaultLanguage(defaultLanguageTextBox.Text); // Add this line MessageBox.Show("Settings saved securely."); } >>>>>>> REPLACE ``` Next, we'll update the `ConfigurationManager.cs` file to include methods for reading and saving the default language setting. ```csharp whisperer/ConfigurationManager.cs <<<<<<< SEARCH private static readonly string HotkeyFileName = Path.Combine(AppDataFolder, "hotkey.dat"); ======= private static readonly string HotkeyFileName = Path.Combine(AppDataFolder, "hotkey.dat"); private static readonly string DefaultLanguageFileName = Path.Combine(AppDataFolder, "defaultLanguage.dat"); // Add this line >>>>>>> REPLACE ... <<<<<<< SEARCH public static void SaveHotkey(Keys hotkey) ======= public static string ReadDefaultLanguage() { try { if (File.Exists(DefaultLanguageFileName)) { byte[] encryptedLanguage = File.ReadAllBytes(DefaultLanguageFileName); byte[] languageBytes = ProtectedData.Unprotect(encryptedLanguage, null, DataProtectionScope.CurrentUser); return Encoding.UTF8.GetString(languageBytes); } } catch (Exception ex) { MessageBox.Show($"Error reading default language: {ex.Message}"); } return "en"; // Return a default value } public static void SaveDefaultLanguage(string language) { try { byte[] languageBytes = Encoding.UTF8.GetBytes(language); byte[] encryptedLanguage = ProtectedData.Protect(languageBytes, null, DataProtectionScope.CurrentUser); File.WriteAllBytes(DefaultLanguageFileName, encryptedLanguage); SettingsSaved?.Invoke(null, EventArgs.Empty); } catch (Exception ex) { MessageBox.Show($"Error saving default language: {ex.Message}"); } } public static void SaveHotkey(Keys hotkey) >>>>>>> REPLACE ``` Finally, we need to modify the `Program.cs` file to use the default language setting when creating the `AudioTranscriptionRequest`. ```csharp whisperer/Program.cs <<<<<<< SEARCH var request = new AudioTranscriptionRequest(apiStream, null, language: "en"); ======= string defaultLanguage = ConfigurationManager.ReadDefaultLanguage(); var request = new AudioTranscriptionRequest(apiStream, null, language: defaultLanguage); >>>>>>> REPLACE ``` These changes will add a new text box to the configuration form for the default language, save the setting, and use it when transcribing audio.
- Loading branch information