303 lines
8.0 KiB
C#
303 lines
8.0 KiB
C#
using System.Text.Json;
|
||
using System.Text.Json.Serialization;
|
||
|
||
namespace ShengShengBuXi.ConsoleApp.Models;
|
||
|
||
/// <summary>
|
||
/// 电话亭配置类,包含所有可配置项
|
||
/// </summary>
|
||
public class PhoneBoothConfig
|
||
{
|
||
/// <summary>
|
||
/// 音频文件配置
|
||
/// </summary>
|
||
public AudioFilesConfig AudioFiles { get; set; } = new();
|
||
|
||
/// <summary>
|
||
/// 拨号配置
|
||
/// </summary>
|
||
public DialConfig Dial { get; set; } = new();
|
||
|
||
/// <summary>
|
||
/// 录音配置
|
||
/// </summary>
|
||
public RecordingConfig Recording { get; set; } = new();
|
||
|
||
/// <summary>
|
||
/// 电话流程配置
|
||
/// </summary>
|
||
public CallFlowConfig CallFlow { get; set; } = new();
|
||
|
||
/// <summary>
|
||
/// 从文件加载配置
|
||
/// </summary>
|
||
/// <param name="filePath">配置文件路径</param>
|
||
/// <returns>配置对象</returns>
|
||
public static PhoneBoothConfig LoadFromFile(string filePath)
|
||
{
|
||
if (!File.Exists(filePath))
|
||
{
|
||
return CreateDefaultConfig();
|
||
}
|
||
|
||
try
|
||
{
|
||
string json = File.ReadAllText(filePath);
|
||
var config = JsonSerializer.Deserialize<PhoneBoothConfig>(json) ?? CreateDefaultConfig();
|
||
return config;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"加载配置文件失败: {ex.Message}");
|
||
return CreateDefaultConfig();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存配置到文件
|
||
/// </summary>
|
||
/// <param name="filePath">配置文件路径</param>
|
||
public void SaveToFile(string filePath)
|
||
{
|
||
try
|
||
{
|
||
var options = new JsonSerializerOptions { WriteIndented = true };
|
||
string json = JsonSerializer.Serialize(this, options);
|
||
File.WriteAllText(filePath, json);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine($"保存配置文件失败: {ex.Message}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建默认配置
|
||
/// </summary>
|
||
/// <returns>默认配置对象</returns>
|
||
public static PhoneBoothConfig CreateDefaultConfig()
|
||
{
|
||
return new PhoneBoothConfig();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 音频文件配置
|
||
/// </summary>
|
||
public class AudioFilesConfig
|
||
{
|
||
/// <summary>
|
||
/// 音频文件基础路径
|
||
/// </summary>
|
||
public string AudioBasePath { get; set; } = "mp3";
|
||
|
||
/// <summary>
|
||
/// 等待嘟音文件路径
|
||
/// </summary>
|
||
public string WaitingToneFile { get; set; } = "等待嘟音.wav";
|
||
|
||
/// <summary>
|
||
/// 等待接电话音频文件路径
|
||
/// </summary>
|
||
public string WaitForPickupFile { get; set; } = "等待接电话.mp3";
|
||
|
||
/// <summary>
|
||
/// 电话接起音频文件路径
|
||
/// </summary>
|
||
public string PhonePickupFile { get; set; } = "电话接起.mp3";
|
||
|
||
/// <summary>
|
||
/// 提示用户录音音频文件路径
|
||
/// </summary>
|
||
public string PromptUserRecordFile { get; set; } = "提示用户录音.mp3";
|
||
|
||
/// <summary>
|
||
/// 滴提示音文件路径
|
||
/// </summary>
|
||
public string BeepPromptFile { get; set; } = "滴提示音.wav";
|
||
|
||
/// <summary>
|
||
/// 数字按键音频文件模板(0-9)
|
||
/// </summary>
|
||
public string DigitToneFileTemplate { get; set; } = "{0}.mp3";
|
||
|
||
/// <summary>
|
||
/// 按键音的最小播放时间(毫秒),即使按键释放也会至少播放这么长时间
|
||
/// </summary>
|
||
public int MinKeyTonePlayTimeMs { get; set; } = 200;
|
||
|
||
/// <summary>
|
||
/// 按键音音量倍数 (正常音量为1.0)
|
||
/// </summary>
|
||
public float KeyToneVolume { get; set; } = 1.0f;
|
||
|
||
/// <summary>
|
||
/// 待机嘟声音量倍数 (正常音量为1.0)
|
||
/// </summary>
|
||
public float WaitingToneVolume { get; set; } = 1.0f;
|
||
|
||
/// <summary>
|
||
/// 拨出嘟声音量倍数 (正常音量为1.0)
|
||
/// </summary>
|
||
public float DialToneVolume { get; set; } = 0.9f;
|
||
|
||
/// <summary>
|
||
/// 提示留言音量倍数 (正常音量为1.0)
|
||
/// </summary>
|
||
public float PromptAfterBeepVolume { get; set; } = 1.0f;
|
||
|
||
/// <summary>
|
||
/// 滴提示音音量倍数 (正常音量为1.0)
|
||
/// </summary>
|
||
public float BeepPromptVolume { get; set; } = 1.0f;
|
||
|
||
/// <summary>
|
||
/// 风铃提示音文件名
|
||
/// </summary>
|
||
public string WindChimeFile { get; set; } = "风铃.wav";
|
||
|
||
/// <summary>
|
||
/// 获取完整的音频文件路径
|
||
/// </summary>
|
||
/// <param name="fileName">文件名</param>
|
||
/// <returns>完整路径</returns>
|
||
public string GetFullPath(string fileName)
|
||
{
|
||
return Path.Combine(
|
||
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AudioBasePath),
|
||
fileName);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取数字按键音频文件路径
|
||
/// </summary>
|
||
/// <param name="digit">数字(0-9)</param>
|
||
/// <returns>文件路径</returns>
|
||
public string GetDigitToneFilePath(int digit)
|
||
{
|
||
return GetFullPath(string.Format(DigitToneFileTemplate, digit));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 拨号配置
|
||
/// </summary>
|
||
public class DialConfig
|
||
{
|
||
/// <summary>
|
||
/// 拨号所需的最小位数
|
||
/// </summary>
|
||
public int MinDigitsToDialOut { get; set; } = 8;
|
||
|
||
/// <summary>
|
||
/// 无新按键后自动拨出的等待秒数
|
||
/// </summary>
|
||
public int AutoDialOutAfterSeconds { get; set; } = 5;
|
||
|
||
/// <summary>
|
||
/// 位数不足时,无操作重置的等待秒数
|
||
/// </summary>
|
||
public int ResetTimeoutSeconds { get; set; } = 10;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 录音配置
|
||
/// </summary>
|
||
public class RecordingConfig
|
||
{
|
||
/// <summary>
|
||
/// 录音保存文件夹
|
||
/// </summary>
|
||
public string RecordingFolder { get; set; } = "recordings";
|
||
|
||
/// <summary>
|
||
/// 录音设备编号
|
||
/// </summary>
|
||
public int RecordingDeviceNumber { get; set; } = 0;
|
||
|
||
/// <summary>
|
||
/// 录音采样率
|
||
/// </summary>
|
||
public int SampleRate { get; set; } = 16000;
|
||
|
||
/// <summary>
|
||
/// 录音通道数(1=单声道,2=立体声)
|
||
/// </summary>
|
||
public int Channels { get; set; } = 1;
|
||
|
||
/// <summary>
|
||
/// 录音缓冲区大小(毫秒)
|
||
/// </summary>
|
||
public int BufferMilliseconds { get; set; } = 100;
|
||
|
||
/// <summary>
|
||
/// 静音检测阈值
|
||
/// </summary>
|
||
public float SilenceThreshold { get; set; } = 0.02f;
|
||
|
||
/// <summary>
|
||
/// 无声音自动挂断的时间(秒)
|
||
/// </summary>
|
||
public int SilenceTimeoutSeconds { get; set; } = 30;
|
||
|
||
/// <summary>
|
||
/// 是否允许用户手动挂断(按回车键)
|
||
/// </summary>
|
||
public bool AllowUserHangup { get; set; } = true;
|
||
|
||
/// <summary>
|
||
/// 是否上传录音文件到服务器
|
||
/// </summary>
|
||
public bool UploadRecordingToServer { get; set; } = false;
|
||
|
||
/// <summary>
|
||
/// 是否在录音时播放背景音乐
|
||
/// </summary>
|
||
public bool EnableBackgroundMusic { get; set; } = true;
|
||
|
||
/// <summary>
|
||
/// 录音背景音乐文件名
|
||
/// </summary>
|
||
public string BackgroundMusicFile { get; set; } = "bj.mp3";
|
||
|
||
/// <summary>
|
||
/// 背景音乐音量 (0.0-1.0)
|
||
/// </summary>
|
||
public float BackgroundMusicVolume { get; set; } = 0.1f;
|
||
|
||
/// <summary>
|
||
/// 无声音播放风铃提示的时间(秒)
|
||
/// </summary>
|
||
public float WindChimePromptSeconds { get; set; } = 7f;
|
||
|
||
/// <summary>
|
||
/// 风铃声淡出的时间(毫秒)
|
||
/// </summary>
|
||
public int WindChimeFadeOutMs { get; set; } = 2000;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 电话流程配置
|
||
/// </summary>
|
||
public class CallFlowConfig
|
||
{
|
||
/// <summary>
|
||
/// 等待接电话音频的最小持续时间(秒)
|
||
/// </summary>
|
||
public int WaitForPickupMinSeconds { get; set; } = 3;
|
||
|
||
/// <summary>
|
||
/// 等待接电话音频的最大持续时间(秒)
|
||
/// </summary>
|
||
public int WaitForPickupMaxSeconds { get; set; } = 6;
|
||
|
||
/// <summary>
|
||
/// 播放电话接起音频的概率(0-1之间的小数)
|
||
/// </summary>
|
||
public float PlayPickupProbability { get; set; } = 0.15f;
|
||
|
||
/// <summary>
|
||
/// 用户挂断后是否重置系统,false表示直接退出程序
|
||
/// </summary>
|
||
public bool ResetSystemAfterHangup { get; set; } = true;
|
||
} |