Lets a user transmit a second hardware input device (e.g. line-in / aux) alongside the mic, with its own device picker and volume, from Audio Settings. No core/ABI/proto changes: the aux is a VC_STREAM_AUX_DEVICE stream started with external_feed=1 and fed via vc_stream_feed_pcm (the same external-feed pipeline screen-audio uses). Per-kind local_streams_ already allows mic + screen + one aux to coexist; volume is a client-side gain multiply (the core's vc_set_input_gain is mic-only/global). Aux is always-on (core never gates AUX_DEVICE on VAD/PTT) and is tied to the voice session. Windows: new Audio/InputDeviceCapture.cs (WASAPI shared-mode capture from a real input endpoint + capture-endpoint enumeration); aux section in AudioSettingsForm.cs; lifecycle in MainForm.cs; persistence in VoiceSettings.cs. macOS: new Audio/InputDeviceCapture.swift (AVAudioEngine input-node tap pinned to the chosen Core Audio device + device enumeration by stable UID); aux section in SettingsWindowController.swift; lifecycle + UserDefaults persistence in MainWindowController.swift; file registered in project.pbxproj. Windows verified (C# solution builds clean; aux confirmed working). macOS build + E2E pending a Mac. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
3.1 KiB
C#
72 lines
3.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;
|
||
|
||
/// <summary>Whether the secondary "aux" outgoing stream is enabled. The aux stream is a
|
||
/// second hardware input device the client captures itself and feeds to the core via
|
||
/// vc_stream_feed_pcm (kind = AUX_DEVICE, external_feed). Lets a user transmit e.g. mic +
|
||
/// a line-in at once.</summary>
|
||
public bool AuxEnabled { get; set; } = false;
|
||
|
||
/// <summary>WASAPI endpoint id of the aux capture device; null = system default capture
|
||
/// device. NOTE: this is a WASAPI device id (from <see cref="Audio.InputDeviceEnumerator"/>),
|
||
/// NOT a core/miniaudio id — the aux device is opened client-side, so the two id spaces differ.</summary>
|
||
public string? AuxDeviceId { get; set; } = null;
|
||
|
||
/// <summary>Aux input volume slider position, 0–300 percent (100 = unity). Applied client-side
|
||
/// to the captured PCM before feeding (the core's input gain is mic-only and global).</summary>
|
||
public int AuxGain { get; set; } = 100;
|
||
|
||
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));
|
||
}
|
||
}
|