54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
|
|
using System.Text.Json;
|
|||
|
|
|
|||
|
|
namespace VoiceCat.App.Models;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 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
|
|||
|
|
/// <see cref="ServerListStore"/> 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.
|
|||
|
|
/// </summary>
|
|||
|
|
public sealed class VoiceSettings
|
|||
|
|
{
|
|||
|
|
/// <summary>Transmission mode: 0 = voice activation, 1 = push-to-talk, 2 = always on
|
|||
|
|
/// (matches Interop's VcInputMode).</summary>
|
|||
|
|
public int InputMode { get; set; } = 0;
|
|||
|
|
|
|||
|
|
/// <summary>VAD sensitivity slider position, 1–100 (default mirrors the designer's 76).</summary>
|
|||
|
|
public int VadThresholdSlider { get; set; } = 76;
|
|||
|
|
|
|||
|
|
/// <summary>Microphone input gain slider position, 0–300 percent (100 = unity).</summary>
|
|||
|
|
public int MicGain { get; set; } = 100;
|
|||
|
|
|
|||
|
|
/// <summary>Push-to-talk key, stored as the integer value of System.Windows.Forms.Keys.</summary>
|
|||
|
|
public int PttKey { get; set; } = (int)Keys.F8;
|
|||
|
|
|
|||
|
|
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<VoiceSettings>(json) ?? new VoiceSettings();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
return new VoiceSettings();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Save()
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(AppDataDir);
|
|||
|
|
File.WriteAllText(FilePath, JsonSerializer.Serialize(this, JsonOptions));
|
|||
|
|
}
|
|||
|
|
}
|