321
This commit is contained in:
parent
185c9b6739
commit
b7ab90865c
|
|
@ -146,6 +146,11 @@ public class AudioFilesConfig
|
|||
/// </summary>
|
||||
public float PromptAfterBeepVolume { get; set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// 滴提示音音量倍数 (正常音量为1.0)
|
||||
/// </summary>
|
||||
public float BeepPromptVolume { get; set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// 风铃提示音文件名
|
||||
/// </summary>
|
||||
|
|
@ -263,7 +268,7 @@ public class RecordingConfig
|
|||
/// <summary>
|
||||
/// 无声音播放风铃提示的时间(秒)
|
||||
/// </summary>
|
||||
public float WindChimePromptSeconds { get; set; } = 7.5f;
|
||||
public float WindChimePromptSeconds { get; set; } = 7f;
|
||||
|
||||
/// <summary>
|
||||
/// 风铃声淡出的时间(毫秒)
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1768,12 +1773,6 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user