2026-09-19 19:33:10 +02:00
|
|
|
using Foundation;
|
|
|
|
|
using VoiceCat.Audio;
|
|
|
|
|
|
|
|
|
|
namespace VoiceCat.iOS;
|
|
|
|
|
|
|
|
|
|
internal sealed class IosSettings
|
|
|
|
|
{
|
|
|
|
|
private readonly NSUserDefaults values = NSUserDefaults.StandardUserDefaults;
|
|
|
|
|
|
|
|
|
|
internal AudioInputMode InputMode { get; set; } = AudioInputMode.VoiceActivation;
|
|
|
|
|
internal float VadThreshold { get; set; } = 0.025f;
|
|
|
|
|
internal float InputGain { get; set; } = 1f;
|
|
|
|
|
internal float OutputGain { get; set; } = 1f;
|
|
|
|
|
internal bool InputNoiseReduction { get; set; }
|
|
|
|
|
internal bool EventSounds { get; set; } = true;
|
|
|
|
|
internal bool SpokenEvents { get; set; }
|
|
|
|
|
internal float EventVolume { get; set; } = 1f;
|
|
|
|
|
internal bool SelfTalkSounds { get; set; }
|
|
|
|
|
internal bool PushToTalkSound { get; set; }
|
2026-09-20 16:25:30 +02:00
|
|
|
internal int AudioBufferMilliseconds { get; set; } = 40;
|
2026-09-19 19:33:10 +02:00
|
|
|
|
|
|
|
|
internal void Load()
|
|
|
|
|
{
|
|
|
|
|
NSString[] keys = [(NSString)"voice.inputMode", (NSString)"voice.vadThreshold", (NSString)"voice.inputGain",
|
2026-09-20 16:25:30 +02:00
|
|
|
(NSString)"voice.outputGain", (NSString)"voice.audioBufferMs", (NSString)"feedback.sounds", (NSString)"feedback.volume"];
|
2026-09-19 19:33:10 +02:00
|
|
|
NSObject[] defaults = [NSNumber.FromInt32((int)AudioInputMode.VoiceActivation), NSNumber.FromFloat(0.025f),
|
2026-09-20 16:25:30 +02:00
|
|
|
NSNumber.FromFloat(1f), NSNumber.FromFloat(1f), NSNumber.FromInt32(40), NSNumber.FromBoolean(true), NSNumber.FromFloat(1f)];
|
2026-09-19 19:33:10 +02:00
|
|
|
values.RegisterDefaults(new NSDictionary<NSString, NSObject>(keys, defaults));
|
|
|
|
|
int inputMode = checked((int)values.IntForKey("voice.inputMode"));
|
|
|
|
|
InputMode = Enum.IsDefined(typeof(AudioInputMode), inputMode) ? (AudioInputMode)inputMode : AudioInputMode.VoiceActivation;
|
|
|
|
|
VadThreshold = Math.Clamp(values.FloatForKey("voice.vadThreshold"), 0.001f, 0.1f);
|
|
|
|
|
InputGain = Math.Clamp(values.FloatForKey("voice.inputGain"), 0f, 4f);
|
|
|
|
|
OutputGain = Math.Clamp(values.FloatForKey("voice.outputGain"), 0f, 1f);
|
|
|
|
|
InputNoiseReduction = values.BoolForKey("voice.inputNoiseReduction");
|
2026-09-20 16:25:30 +02:00
|
|
|
int audioBuffer = checked((int)values.IntForKey("voice.audioBufferMs")); AudioBufferMilliseconds = audioBuffer is 20 or 40 or 60 ? audioBuffer : 40;
|
2026-09-19 19:33:10 +02:00
|
|
|
EventSounds = values.BoolForKey("feedback.sounds");
|
|
|
|
|
SpokenEvents = values.BoolForKey("feedback.speech");
|
|
|
|
|
EventVolume = Math.Clamp(values.FloatForKey("feedback.volume"), 0f, 1f);
|
|
|
|
|
SelfTalkSounds = values.BoolForKey("feedback.selfTalk");
|
|
|
|
|
PushToTalkSound = values.BoolForKey("feedback.ptt");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void Save()
|
|
|
|
|
{
|
|
|
|
|
values.SetInt((int)InputMode, "voice.inputMode"); values.SetFloat(VadThreshold, "voice.vadThreshold");
|
|
|
|
|
values.SetFloat(InputGain, "voice.inputGain"); values.SetFloat(OutputGain, "voice.outputGain");
|
2026-09-20 16:25:30 +02:00
|
|
|
values.SetInt(AudioBufferMilliseconds, "voice.audioBufferMs");
|
2026-09-19 19:33:10 +02:00
|
|
|
values.SetBool(InputNoiseReduction, "voice.inputNoiseReduction"); values.SetBool(EventSounds, "feedback.sounds");
|
|
|
|
|
values.SetBool(SpokenEvents, "feedback.speech"); values.SetFloat(EventVolume, "feedback.volume");
|
|
|
|
|
values.SetBool(SelfTalkSounds, "feedback.selfTalk"); values.SetBool(PushToTalkSound, "feedback.ptt"); values.Synchronize();
|
|
|
|
|
}
|
|
|
|
|
}
|