提交
This commit is contained in:
parent
7cf247a873
commit
f99f4e1b4a
|
|
@ -96,23 +96,23 @@ namespace ShengShengBuXi.Hubs
|
|||
private static Dictionary<string, ClientInfo> _clientsDict = new Dictionary<string, ClientInfo>();
|
||||
// 用于线程安全访问
|
||||
private static object _clientsLock = new object();
|
||||
|
||||
|
||||
// 文本显示队列
|
||||
private static List<DisplayText> _displayTextList = new List<DisplayText>();
|
||||
private static object _displayTextListLock = new object();
|
||||
|
||||
|
||||
// 监控文本列表
|
||||
private static List<MonitorText> _monitorTextList = new List<MonitorText>();
|
||||
private static object _monitorTextListLock = new object();
|
||||
|
||||
|
||||
// 配置信息
|
||||
private static string _displayConfig = "{}";
|
||||
private static object _displayConfigLock = new object();
|
||||
|
||||
|
||||
// 管理员配置保存路径
|
||||
private static readonly string ConfigDirectory = Path.Combine(Directory.GetCurrentDirectory(), "config");
|
||||
private static readonly string DisplayConfigPath = Path.Combine(ConfigDirectory, "display.json");
|
||||
|
||||
|
||||
// 用于初始化配置
|
||||
static AudioHub()
|
||||
{
|
||||
|
|
@ -121,11 +121,11 @@ namespace ShengShengBuXi.Hubs
|
|||
{
|
||||
Directory.CreateDirectory(ConfigDirectory);
|
||||
}
|
||||
|
||||
|
||||
// 加载显示配置
|
||||
LoadDisplayConfig();
|
||||
}
|
||||
|
||||
|
||||
// 加载显示配置
|
||||
private static void LoadDisplayConfig()
|
||||
{
|
||||
|
|
@ -168,12 +168,12 @@ namespace ShengShengBuXi.Hubs
|
|||
}
|
||||
}
|
||||
}";
|
||||
|
||||
|
||||
lock (_displayConfigLock)
|
||||
{
|
||||
_displayConfig = defaultConfig;
|
||||
}
|
||||
|
||||
|
||||
// 保存默认配置
|
||||
File.WriteAllText(DisplayConfigPath, defaultConfig);
|
||||
Console.WriteLine("创建默认显示配置成功");
|
||||
|
|
@ -413,6 +413,8 @@ namespace ShengShengBuXi.Hubs
|
|||
|
||||
_logger.LogInformation($"结束音频流: {Context.ConnectionId}");
|
||||
|
||||
// 结束音频处理
|
||||
await _audioProcessingService.EndAudioStreamAsync(Context.ConnectionId);
|
||||
|
||||
var _speechsession = _speechToTextService.GetSessionStatus(Context.ConnectionId);
|
||||
if (_speechsession.HasSavedText && !_speechsession.IsSentToDisplay)
|
||||
|
|
@ -420,9 +422,9 @@ namespace ShengShengBuXi.Hubs
|
|||
|
||||
AddRecognizedTextToDisplay(_speechsession.FinalText, true, Context.ConnectionId, _speechsession);
|
||||
_speechsession.IsSentToDisplay = true;
|
||||
_logger.LogInformation($"结束音频流: {Context.ConnectionId}");
|
||||
}
|
||||
// 结束音频处理
|
||||
await _audioProcessingService.EndAudioStreamAsync(Context.ConnectionId);
|
||||
|
||||
|
||||
// 结束语音识别会话
|
||||
await _speechToTextService.EndSessionAsync(Context.ConnectionId);
|
||||
|
|
@ -923,19 +925,19 @@ namespace ShengShengBuXi.Hubs
|
|||
|
||||
// 获取当前已显示过的句子集合
|
||||
var recentTexts = _recentlyDisplayedSentences.Select(item => item.Text).ToHashSet();
|
||||
|
||||
|
||||
// 筛选出未最近显示过的句子
|
||||
var availableSentences = _presetSentences.Where(s => !recentTexts.Contains(s)).ToList();
|
||||
|
||||
|
||||
// 如果可用句子为空(全部句子都显示过了),则使用全部句子但优先选择最早显示过的
|
||||
if (availableSentences.Count == 0)
|
||||
{
|
||||
_logger.LogInformation("所有预设句子都已最近显示过,将选择最早显示的句子");
|
||||
// 从队列中获取并移除最早显示的句子
|
||||
var oldestSentence = _recentlyDisplayedSentences.Dequeue().Text;
|
||||
|
||||
|
||||
AddRecognizedTextToDisplay(oldestSentence, false);
|
||||
|
||||
|
||||
// 将这个句子重新添加到队列末尾,记录当前时间
|
||||
_recentlyDisplayedSentences.Enqueue((oldestSentence, DateTime.Now));
|
||||
}
|
||||
|
|
@ -944,17 +946,17 @@ namespace ShengShengBuXi.Hubs
|
|||
// 从未最近显示过的句子中随机选择一条
|
||||
string randomText = availableSentences[new Random().Next(availableSentences.Count)];
|
||||
AddRecognizedTextToDisplay(randomText, false);
|
||||
|
||||
|
||||
// 添加到已显示队列
|
||||
_recentlyDisplayedSentences.Enqueue((randomText, DateTime.Now));
|
||||
|
||||
|
||||
// 如果队列超出限制,移除最早的记录
|
||||
while (_recentlyDisplayedSentences.Count > _sentenceHistoryLimit)
|
||||
{
|
||||
_recentlyDisplayedSentences.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_logger.LogInformation($"当前已显示过的句子数量: {_recentlyDisplayedSentences.Count}/{_sentenceHistoryLimit}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -1433,7 +1435,7 @@ namespace ShengShengBuXi.Hubs
|
|||
return _displayConfig;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存显示配置
|
||||
/// </summary>
|
||||
|
|
@ -1445,19 +1447,19 @@ namespace ShengShengBuXi.Hubs
|
|||
{
|
||||
// 尝试解析JSON以验证格式
|
||||
JsonDocument.Parse(configJson);
|
||||
|
||||
|
||||
// 保存到文件
|
||||
await File.WriteAllTextAsync(DisplayConfigPath, configJson);
|
||||
|
||||
|
||||
// 更新内存中的配置
|
||||
lock (_displayConfigLock)
|
||||
{
|
||||
_displayConfig = configJson;
|
||||
}
|
||||
|
||||
|
||||
// 通知所有显示客户端
|
||||
await NotifyDisplayConfig();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -1466,7 +1468,7 @@ namespace ShengShengBuXi.Hubs
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通知所有显示客户端更新配置
|
||||
/// </summary>
|
||||
|
|
@ -1477,7 +1479,7 @@ namespace ShengShengBuXi.Hubs
|
|||
{
|
||||
configJson = _displayConfig;
|
||||
}
|
||||
|
||||
|
||||
List<string> displayClientIds = new List<string>();
|
||||
lock (_clients)
|
||||
{
|
||||
|
|
@ -1486,7 +1488,7 @@ namespace ShengShengBuXi.Hubs
|
|||
.Select(c => c.Key)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
foreach (var clientId in displayClientIds)
|
||||
{
|
||||
await Clients.Client(clientId).SendAsync("ReceiveDisplayConfig", configJson);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
"needVad": true
|
||||
}
|
||||
},
|
||||
"displayType": 0,
|
||||
"displayType": 1,
|
||||
"minDisplayText": 3,
|
||||
"maxDisplayText": 60
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user