using System.Text.Json; namespace VoiceCat.App.Models; /// /// User's send-side voice input preferences — transmission mode, VAD sensitivity, mic input /// gain, and the push-to-talk key. Persisted to %AppData%\VoiceCat\voice.json, same pattern as /// and FeedbackSettings: a missing or corrupt file yields defaults /// rather than throwing. Slider-position values are stored as-is so MainForm can restore the /// TrackBars directly. /// public sealed class VoiceSettings { /// Transmission mode: 0 = voice activation, 1 = push-to-talk, 2 = always on /// (matches Interop's VcInputMode). public int InputMode { get; set; } = 0; /// VAD sensitivity slider position, 1–100 (default mirrors the designer's 76). public int VadThresholdSlider { get; set; } = 76; /// Microphone input gain slider position, 0–300 percent (100 = unity). public int MicGain { get; set; } = 100; /// Push-to-talk key, stored as the integer value of System.Windows.Forms.Keys. public int PttKey { get; set; } = (int)Keys.F8; /// Saved device ID from the last session; null means use the system default. public string? InputDeviceId { get; set; } = null; private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true }; private static string AppDataDir => Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VoiceCat"); private static string FilePath => Path.Combine(AppDataDir, "voice.json"); public static VoiceSettings Load() { try { if (!File.Exists(FilePath)) return new VoiceSettings(); string json = File.ReadAllText(FilePath); return JsonSerializer.Deserialize(json) ?? new VoiceSettings(); } catch { return new VoiceSettings(); } } public void Save() { Directory.CreateDirectory(AppDataDir); File.WriteAllText(FilePath, JsonSerializer.Serialize(this, JsonOptions)); } }