diff --git a/ShengShengBuXi.ConsoleApp/Models/PhoneBoothConfig.cs b/ShengShengBuXi.ConsoleApp/Models/PhoneBoothConfig.cs
index e64c191..4f6d3dc 100644
--- a/ShengShengBuXi.ConsoleApp/Models/PhoneBoothConfig.cs
+++ b/ShengShengBuXi.ConsoleApp/Models/PhoneBoothConfig.cs
@@ -105,12 +105,12 @@ public class AudioFilesConfig
/// 电话接起音频文件路径
///
public string PhonePickupFile { get; set; } = "电话接起.mp3";
-
+
///
/// 提示用户录音音频文件路径
///
public string PromptUserRecordFile { get; set; } = "提示用户录音.mp3";
-
+
///
/// 滴提示音文件路径
///
@@ -120,7 +120,7 @@ public class AudioFilesConfig
/// 数字按键音频文件模板(0-9)
///
public string DigitToneFileTemplate { get; set; } = "{0}.mp3";
-
+
///
/// 按键音的最小播放时间(毫秒),即使按键释放也会至少播放这么长时间
///
@@ -146,6 +146,11 @@ public class AudioFilesConfig
///
public float PromptAfterBeepVolume { get; set; } = 1.0f;
+ ///
+ /// 滴提示音音量倍数 (正常音量为1.0)
+ ///
+ public float BeepPromptVolume { get; set; } = 1.0f;
+
///
/// 风铃提示音文件名
///
@@ -159,7 +164,7 @@ public class AudioFilesConfig
public string GetFullPath(string fileName)
{
return Path.Combine(
- Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AudioBasePath),
+ Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AudioBasePath),
fileName);
}
@@ -183,12 +188,12 @@ public class DialConfig
/// 拨号所需的最小位数
///
public int MinDigitsToDialOut { get; set; } = 8;
-
+
///
/// 无新按键后自动拨出的等待秒数
///
public int AutoDialOutAfterSeconds { get; set; } = 5;
-
+
///
/// 位数不足时,无操作重置的等待秒数
///
@@ -204,32 +209,32 @@ public class RecordingConfig
/// 录音保存文件夹
///
public string RecordingFolder { get; set; } = "recordings";
-
+
///
/// 录音设备编号
///
public int RecordingDeviceNumber { get; set; } = 0;
-
+
///
/// 录音采样率
///
public int SampleRate { get; set; } = 16000;
-
+
///
/// 录音通道数(1=单声道,2=立体声)
///
public int Channels { get; set; } = 1;
-
+
///
/// 录音缓冲区大小(毫秒)
///
public int BufferMilliseconds { get; set; } = 100;
-
+
///
/// 静音检测阈值
///
public float SilenceThreshold { get; set; } = 0.02f;
-
+
///
/// 无声音自动挂断的时间(秒)
///
@@ -239,22 +244,22 @@ public class RecordingConfig
/// 是否允许用户手动挂断(按回车键)
///
public bool AllowUserHangup { get; set; } = true;
-
+
///
/// 是否上传录音文件到服务器
///
public bool UploadRecordingToServer { get; set; } = false;
-
+
///
/// 是否在录音时播放背景音乐
///
public bool EnableBackgroundMusic { get; set; } = true;
-
+
///
/// 录音背景音乐文件名
///
public string BackgroundMusicFile { get; set; } = "bj.mp3";
-
+
///
/// 背景音乐音量 (0.0-1.0)
///
@@ -263,7 +268,7 @@ public class RecordingConfig
///
/// 无声音播放风铃提示的时间(秒)
///
- public float WindChimePromptSeconds { get; set; } = 7.5f;
+ public float WindChimePromptSeconds { get; set; } = 7f;
///
/// 风铃声淡出的时间(毫秒)
@@ -280,12 +285,12 @@ public class CallFlowConfig
/// 等待接电话音频的最小持续时间(秒)
///
public int WaitForPickupMinSeconds { get; set; } = 3;
-
+
///
/// 等待接电话音频的最大持续时间(秒)
///
public int WaitForPickupMaxSeconds { get; set; } = 6;
-
+
///
/// 播放电话接起音频的概率(0-1之间的小数)
///
@@ -295,4 +300,4 @@ public class CallFlowConfig
/// 用户挂断后是否重置系统,false表示直接退出程序
///
public bool ResetSystemAfterHangup { get; set; } = true;
-}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/ShengShengBuXi.ConsoleApp/README.md b/ShengShengBuXi.ConsoleApp/README.md
index ca0713b..24876f5 100644
--- a/ShengShengBuXi.ConsoleApp/README.md
+++ b/ShengShengBuXi.ConsoleApp/README.md
@@ -33,6 +33,7 @@
"WaitingToneVolume": 1.0, // 待机嘟声音量倍数 (0.0-1.0)
"DialToneVolume": 0.9, // 拨出嘟声音量倍数 (0.0-1.0)
"PromptAfterBeepVolume": 1.0, // 提示留言音量倍数 (0.0-1.0)
+ "BeepPromptVolume": 1.0, // 滴提示音音量倍数 (0.0-1.0)
"WindChimeFile": "风铃.wav" // 风铃提示音文件名
},
"Dial": {
diff --git a/ShengShengBuXi.ConsoleApp/Services/PhoneBoothService.cs b/ShengShengBuXi.ConsoleApp/Services/PhoneBoothService.cs
index eba4e8c..f9a01c8 100644
--- a/ShengShengBuXi.ConsoleApp/Services/PhoneBoothService.cs
+++ b/ShengShengBuXi.ConsoleApp/Services/PhoneBoothService.cs
@@ -956,10 +956,18 @@ public class PhoneBoothService : IPhoneBoothService, IDisposable
{
_lastSpeechTime = DateTime.Now;
- // 如果风铃声正在播放,平滑停止它
+ // 如果风铃声正在播放,先停止风铃声
if (_isWindChimePlaying)
{
+ Console.WriteLine("检测到用户说话,停止风铃声...");
_ = StopWindChime(true); // 平滑淡出
+
+ // 风铃声停止后,重新启动背景音乐
+ if (!_isBackgroundMusicPlaying && _config.Recording.EnableBackgroundMusic)
+ {
+ Console.WriteLine("重新启动背景音乐...");
+ _ = StartPlayingBackgroundMusic(_programCts.Token);
+ }
}
}
@@ -1379,7 +1387,7 @@ public class PhoneBoothService : IPhoneBoothService, IDisposable
else if (audioPath.Contains(_config.AudioFiles.BeepPromptFile))
{
// 滴提示音的音量
- device.Volume = Math.Clamp(_config.AudioFiles.PromptAfterBeepVolume > 0 ? _config.AudioFiles.PromptAfterBeepVolume : 1.0f, 0.0f, 1.0f);
+ device.Volume = Math.Clamp(_config.AudioFiles.BeepPromptVolume > 0 ? _config.AudioFiles.BeepPromptVolume : 1.0f, 0.0f, 1.0f);
}
else if (audioPath.Contains(_config.AudioFiles.WaitingToneFile))
{
@@ -1539,12 +1547,10 @@ public class PhoneBoothService : IPhoneBoothService, IDisposable
{
_backgroundMusicReader.Position = 0;
}
- // 设置音量到设备而非Reader对象,确保独立控制(默认为10%)
- _backgroundMusicDevice.Volume = Math.Clamp(_config.Recording.BackgroundMusicVolume, 0.0f, 1.0f);
+
// 如果没有在播放,则开始播放
if (_backgroundMusicDevice.PlaybackState != PlaybackState.Playing)
{
-
_backgroundMusicDevice.Play();
}
@@ -1632,7 +1638,15 @@ public class PhoneBoothService : IPhoneBoothService, IDisposable
secondsSinceLastSpeech < silenceTimeoutSeconds &&
!_isWindChimePlaying)
{
- Console.WriteLine($"检测到{windChimePromptSeconds}秒无声音,播放风铃提示音...");
+ Console.WriteLine($"检测到{windChimePromptSeconds}秒无声音,先停止背景音乐,再播放风铃提示音...");
+
+ // 先停止背景音乐
+ if (_isBackgroundMusicPlaying)
+ {
+ StopBackgroundMusic();
+ }
+
+ // 然后播放风铃提示音
_ = PlayWindChime();
}
}
@@ -1688,32 +1702,23 @@ public class PhoneBoothService : IPhoneBoothService, IDisposable
// 开始播放
_windChimeDevice.Play();
- // 单独开启一个任务检测是否有声音,如有则淡出停止
+ // 启动循环播放任务
_ = Task.Run(async () =>
{
try
{
while (_isWindChimePlaying && !token.IsCancellationRequested)
{
- // 如果检测到有声音,淡出停止
- if ((DateTime.Now - _lastSpeechTime).TotalSeconds < 1.0)
- {
- Console.WriteLine("检测到用户说话,风铃提示音淡出...");
- await StopWindChime(true); // 平滑淡出
- break;
- }
-
// 如果到达音频文件末尾,循环播放
if (_windChimeReader != null && _windChimeReader.Position >= _windChimeReader.Length)
{
_windChimeReader.Position = 0;
}
- // 确保背景音乐音量不受风铃音量影响
- if (_isBackgroundMusicPlaying && _backgroundMusicDevice != null)
+ // 确保风铃声仍在播放
+ if (_windChimeDevice != null && _windChimeDevice.PlaybackState != PlaybackState.Playing)
{
- // 重新应用背景音乐的原始音量设置
- _backgroundMusicDevice.Volume = Math.Clamp(_config.Recording.BackgroundMusicVolume, 0.0f, 1.0f);
+ _windChimeDevice.Play();
}
await Task.Delay(100, token);
@@ -1725,7 +1730,7 @@ public class PhoneBoothService : IPhoneBoothService, IDisposable
}
catch (Exception ex)
{
- Console.WriteLine($"风铃提示音监控错误: {ex.Message}");
+ Console.WriteLine($"风铃提示音播放循环错误: {ex.Message}");
}
});
}
@@ -1767,20 +1772,14 @@ public class PhoneBoothService : IPhoneBoothService, IDisposable
float ratio = 1.0f - ((float)i / steps);
_windChimeDevice.Volume = startVolume * ratio;
-
- // 确保背景音乐音量不受影响
- if (_isBackgroundMusicPlaying && _backgroundMusicDevice != null)
- {
- _backgroundMusicDevice.Volume = Math.Clamp(_config.Recording.BackgroundMusicVolume, 0.0f, 1.0f);
- }
-
+
await Task.Delay(stepDelay);
}
}
// 正式停止
_windChimeCts?.Cancel();
-
+
if (_windChimeDevice != null)
{
_windChimeDevice.Stop();
@@ -1796,12 +1795,6 @@ public class PhoneBoothService : IPhoneBoothService, IDisposable
_isWindChimePlaying = false;
Console.WriteLine("风铃提示音已停止");
-
- // 再次确保背景音乐音量恢复正常
- if (_isBackgroundMusicPlaying && _backgroundMusicDevice != null)
- {
- _backgroundMusicDevice.Volume = Math.Clamp(_config.Recording.BackgroundMusicVolume, 0.0f, 1.0f);
- }
}
catch (Exception ex)
{
diff --git a/ShengShengBuXi.ConsoleApp/config.json b/ShengShengBuXi.ConsoleApp/config.json
index 31e172c..7d804db 100644
--- a/ShengShengBuXi.ConsoleApp/config.json
+++ b/ShengShengBuXi.ConsoleApp/config.json
@@ -8,10 +8,11 @@
"BeepPromptFile": "\u6EF4\u63D0\u793A\u97F3.wav",
"DigitToneFileTemplate": "{0}.mp3",
"MinKeyTonePlayTimeMs": 200,
- "KeyToneVolume": 1.0,
- "WaitingToneVolume": 1.0,
- "DialToneVolume": 0.9,
- "PromptAfterBeepVolume": 1.0,
+ "KeyToneVolume": 0.7,
+ "WaitingToneVolume": 0.7,
+ "DialToneVolume": 0.7,
+ "PromptAfterBeepVolume": 0.7,
+ "BeepPromptVolume": 0.1,
"WindChimeFile": "\u98CE\u94C3.wav"
},
"Dial": {
@@ -25,14 +26,14 @@
"SampleRate": 16000,
"Channels": 1,
"BufferMilliseconds": 50,
- "SilenceThreshold": 0.1,
- "SilenceTimeoutSeconds": 60,
+ "SilenceThreshold": 0.14,
+ "SilenceTimeoutSeconds": 20,
"AllowUserHangup": true,
"UploadRecordingToServer": false,
"EnableBackgroundMusic": true,
"BackgroundMusicFile": "bj.mp3",
- "BackgroundMusicVolume": 0.15,
- "WindChimePromptSeconds": 7.5,
+ "BackgroundMusicVolume": 0.3,
+ "WindChimePromptSeconds": 10,
"WindChimeFadeOutMs": 3000
},
"CallFlow": {