2026-08-10 12:32:07 +00:00
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Robovoice.App;
|
|
|
|
|
|
|
|
|
|
public sealed class AppConfig
|
|
|
|
|
{
|
|
|
|
|
public string Voice { get; set; } = string.Empty;
|
|
|
|
|
public int PttKey { get; set; } = (int)Keys.F8;
|
|
|
|
|
public string OutputDevice { get; set; } = string.Empty;
|
|
|
|
|
public int NoiseScale { get; set; } = 667;
|
|
|
|
|
public int LengthScale { get; set; } = 100;
|
|
|
|
|
public int NoiseWScale { get; set; } = 800;
|
|
|
|
|
public bool MinimizeToTray { get; set; } = true;
|
2026-08-13 09:58:33 +00:00
|
|
|
public string SttEndpoint { get; set; } = "127.0.0.1:6996";
|
2026-08-10 12:32:07 +00:00
|
|
|
|
|
|
|
|
public static string AppDataDir => Path.Combine(
|
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
|
|
|
|
"Hackmaster", "Robovoice");
|
|
|
|
|
|
|
|
|
|
public static string ConfigPath => Path.Combine(AppDataDir, "config.json");
|
|
|
|
|
public static string VoicesDir => Path.Combine(AppDataDir, "Piper-voices");
|
|
|
|
|
|
|
|
|
|
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
|
|
|
{
|
|
|
|
|
WriteIndented = true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static AppConfig Load()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(ConfigPath))
|
|
|
|
|
{
|
|
|
|
|
using var stream = File.OpenRead(ConfigPath);
|
|
|
|
|
return JsonSerializer.Deserialize<AppConfig>(stream) ?? new AppConfig();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
return new AppConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(AppDataDir);
|
|
|
|
|
using var stream = File.Create(ConfigPath);
|
|
|
|
|
JsonSerializer.Serialize(stream, this, JsonOptions);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|