Audio input settings (device picker, VAD/PTT mode, VAD sensitivity, mic gain, PTT key) move from the always-visible bottom panel into Settings > Audio..., matching the macOS/iOS pattern. The device ComboBox now uses DataSource + DisplayMember="Name" instead of Items.Add() with no DisplayMember — this fixes both the display bug (was showing the full DeviceInfo record ToString()) and the NVDA silence on dropdown open (DataSource binding exposes proper MSAA text per item). Changes apply live for immediate feedback; Cancel reverts. VoiceSettings gains InputDeviceId to persist the chosen device across sessions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
57 lines
2.1 KiB
C#
57 lines
2.1 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;
|
||
|
||
/// <summary>Saved device ID from the last session; null means use the system default.</summary>
|
||
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<VoiceSettings>(json) ?? new VoiceSettings();
|
||
}
|
||
catch
|
||
{
|
||
return new VoiceSettings();
|
||
}
|
||
}
|
||
|
||
public void Save()
|
||
{
|
||
Directory.CreateDirectory(AppDataDir);
|
||
File.WriteAllText(FilePath, JsonSerializer.Serialize(this, JsonOptions));
|
||
}
|
||
}
|