Skip to content

Commit 8723945

Browse files
committed
fix voice load
1 parent a4440ed commit 8723945

18 files changed

Lines changed: 656 additions & 64 deletions

AddTaskWindow.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ public static DraftSmartSuggestion AnalyzeDraftInput(string rawText, DateTime no
435435
{
436436
var recognizer = new IntentRecognizer();
437437
var parser = new VoiceReminderTimeParser();
438+
var taskAnalysis = TaskTextQualityHelper.AnalyzeVoiceTaskCandidate(rawText);
438439
string normalized = string.IsNullOrWhiteSpace(rawText) ? string.Empty : rawText.Trim();
439440
string extracted = recognizer.ExtractTaskDescription(normalized);
440441
if (!string.IsNullOrWhiteSpace(extracted))
@@ -446,7 +447,7 @@ public static DraftSmartSuggestion AnalyzeDraftInput(string rawText, DateTime no
446447
{
447448
NormalizedDescription = normalized,
448449
TaskLikelihoodScore = recognizer.ScoreTaskLikelihood(rawText),
449-
IsPotentialTask = recognizer.IsPotentialTask(rawText)
450+
IsPotentialTask = taskAnalysis.IsMeaningfulTask && recognizer.IsPotentialTask(rawText)
450451
};
451452

452453
if (!string.IsNullOrWhiteSpace(normalized))

App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
1010
</startup>
1111
<appSettings>
12-
<add key="OpenAIApiKey" value="56e671a3357824fa1abea6df8e20e696.kreWntpK6LDGbAyR" />
12+
<add key="OpenAIApiKey" value="" />
1313
<add key="LlmProvider" value="zhipu" />
1414
<add key="LlmApiBaseUrl" value="https://open.bigmodel.cn/api/paas/v4/" />
1515
<!-- For OpenAI, empty means use library default. For other providers, this will be crucial. -->

ConversationRecorder.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,17 @@ private void ExtractTasksFromConversation()
299299
if (intentRecognizer.IsPotentialTask(segment.RecognizedText))
300300
{
301301
var taskDesc = intentRecognizer.ExtractTaskDescription(segment.RecognizedText);
302-
if (!string.IsNullOrWhiteSpace(taskDesc))
302+
if (!string.IsNullOrWhiteSpace(taskDesc) && TaskTextQualityHelper.IsMeaningfulTaskText(taskDesc))
303303
{
304304
extractedTasks.Add(taskDesc);
305305
}
306306
}
307307
}
308308

309-
_currentSession.ExtractedTasks = extractedTasks.Distinct().ToList();
309+
_currentSession.ExtractedTasks = extractedTasks
310+
.Distinct(StringComparer.OrdinalIgnoreCase)
311+
.Take(5)
312+
.ToList();
310313
}
311314

312315
public List<ConversationSession> GetSessions(ConversationType? type = null, DateTime? startDate = null, DateTime? endDate = null)

DecisionEngine.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ public void SetOptions(DecisionEngineOptions options)
5353
public List<TaskDecisionScore> RankTasks(List<ItemGrid> tasks, LifeProfileSnapshot lifeProfile, string activeGoalId, DateTime now)
5454
{
5555
tasks ??= new List<ItemGrid>();
56-
var activeTasks = tasks.Where(t => t != null && t.IsActive).ToList();
56+
var activeTasks = tasks
57+
.Where(t => t != null && t.IsActive && TaskTextQualityHelper.IsMeaningfulTaskText(t.Task))
58+
.ToList();
59+
if (!activeTasks.Any())
60+
{
61+
activeTasks = tasks.Where(t => t != null && t.IsActive).ToList();
62+
}
5763
lifeProfile ??= new LifeProfileSnapshot();
5864

5965
var ranked = activeTasks

EnhancedAudioCaptureService.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ private TaskDraft ProcessPotentialTask(string text, float confidence)
437437
{
438438
try
439439
{
440+
var taskAnalysis = TaskTextQualityHelper.AnalyzeVoiceTaskCandidate(text);
441+
if (!taskAnalysis.IsMeaningfulTask)
442+
{
443+
return null;
444+
}
445+
440446
// 提取任务描述
441447
string cleanedText = _intentRecognizer.ExtractTaskDescription(text);
442448
if (string.IsNullOrWhiteSpace(cleanedText))
@@ -464,7 +470,8 @@ private TaskDraft ProcessPotentialTask(string text, float confidence)
464470
Importance = importance,
465471
Urgency = urgency,
466472
EstimatedQuadrant = quadrant,
467-
Source = "voice"
473+
Source = "voice",
474+
Confidence = Math.Max(confidence, (float)taskAnalysis.StructureScore)
468475
};
469476

470477
_draftManager.AddDraft(draft);
@@ -954,6 +961,7 @@ private double ScoreAlt(string text, float confidence)
954961
double score = ClampConfidence(confidence);
955962
score += (_intentRecognizer?.ScoreTaskLikelihood(normalized) ?? 0) * 0.25;
956963
score += ScoreHintMatch(normalized);
964+
score += TaskTextQualityHelper.AnalyzeVoiceTaskCandidate(normalized).StructureScore * 0.2;
957965

958966
if (Regex.IsMatch(normalized, @"^(嗯+|啊+|额+|哦+|那个|就是)$", RegexOptions.IgnoreCase))
959967
{
@@ -1028,8 +1036,9 @@ private void HandleRecognizedText(string rawText, float confidence, string sourc
10281036
});
10291037

10301038
bool isSystemFallback = _classicFallbackEnabled && string.Equals(source, "system-speech", StringComparison.OrdinalIgnoreCase);
1039+
var taskAnalysis = TaskTextQualityHelper.AnalyzeVoiceTaskCandidate(text);
10311040
double taskLikelihood = _intentRecognizer.ScoreTaskLikelihood(text);
1032-
bool reminderLike = _intentRecognizer.IsReminderLike(text);
1041+
bool reminderLike = _intentRecognizer.IsReminderLike(text) || taskAnalysis.IsReminderCandidate;
10331042
float minConfidence = isSystemFallback
10341043
? Math.Max(0.05f, _confidenceThreshold * 0.12f)
10351044
: _confidenceThreshold * 0.45f;
@@ -1039,10 +1048,10 @@ private void HandleRecognizedText(string rawText, float confidence, string sourc
10391048
minConfidence = Math.Max(0.15f, minConfidence * 0.6f);
10401049
}
10411050

1042-
if (confidence < minConfidence && taskLikelihood < 0.45 && !reminderLike)
1051+
if (confidence < minConfidence && taskLikelihood < 0.45 && taskAnalysis.StructureScore < 0.35 && !reminderLike)
10431052
return;
10441053

1045-
if (_intentRecognizer.IsPotentialTask(text) || reminderLike)
1054+
if (taskAnalysis.IsMeaningfulTask && (_intentRecognizer.IsPotentialTask(text) || reminderLike || taskAnalysis.StructureScore >= 0.45))
10461055
{
10471056
TotalPotentialTasks++;
10481057
var draft = ProcessPotentialTask(text, confidence);
@@ -1060,7 +1069,7 @@ private void HandleRecognizedText(string rawText, float confidence, string sourc
10601069
}
10611070
else
10621071
{
1063-
VoiceRuntimeLog.Info($"Skip draft: not task-like. text={text}");
1072+
VoiceRuntimeLog.Info($"Skip draft: not task-like. text={text}, structure={taskAnalysis.StructureScore:F2}");
10641073
}
10651074

10661075
BufferConversation(text);

IntentRecognizer.cs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public class IntentRecognizer
5555

5656
public bool IsPotentialTask(string text)
5757
{
58+
var analysis = TaskTextQualityHelper.AnalyzeVoiceTaskCandidate(text);
59+
if (!analysis.IsMeaningfulTask)
60+
return false;
61+
5862
if (ScoreTaskLikelihood(text) >= 0.45)
5963
return true;
6064

@@ -69,7 +73,8 @@ public double ScoreTaskLikelihood(string text)
6973
if (string.IsNullOrWhiteSpace(text))
7074
return 0;
7175

72-
string normalized = NormalizeText(text);
76+
var analysis = TaskTextQualityHelper.AnalyzeVoiceTaskCandidate(text);
77+
string normalized = analysis.SanitizedText;
7378
if (normalized.Length < 4)
7479
return 0;
7580

@@ -101,10 +106,30 @@ public double ScoreTaskLikelihood(string text)
101106
score -= 4;
102107
}
103108

109+
if (!analysis.IsMeaningfulTask)
110+
{
111+
score -= 6;
112+
}
113+
114+
if (analysis.IsQuestionLike)
115+
{
116+
score -= 2;
117+
}
118+
119+
if (analysis.IsLongFreeformSpeech)
120+
{
121+
score -= 3;
122+
}
123+
104124
if (Regex.IsMatch(normalized, @"^(好的|是的|嗯|哦|啊|呀|哈哈|收到)$"))
105125
score -= 5;
106126

107-
if (normalized.Length > 40)
127+
if (normalized.Length > 24 && !ContainsAny(normalized, ActionWords))
128+
{
129+
score -= 2;
130+
}
131+
132+
if (normalized.Length > 40 && ContainsAny(normalized, ActionWords))
108133
{
109134
score += 1;
110135
}
@@ -121,18 +146,13 @@ public string ExtractTaskDescription(string text)
121146
if (string.IsNullOrWhiteSpace(text))
122147
return null;
123148

124-
string normalized = NormalizeText(text);
125-
normalized = Regex.Replace(normalized, @"^(请)?\s*(提醒我|帮我|记得)\s*", "", RegexOptions.IgnoreCase);
126-
normalized = Regex.Replace(normalized, @"^(麻烦你|请|那个|就是|然后|我想|我需要)\s*", "", RegexOptions.IgnoreCase);
127-
normalized = Regex.Replace(normalized, @"^(要|需要|必须|应该|得)\s*", "", RegexOptions.IgnoreCase);
128-
normalized = Regex.Replace(normalized, @"(啊|呀|吧|呢|哦|啦|嘛)$", "", RegexOptions.IgnoreCase);
129-
normalized = Regex.Replace(normalized, @"\s+", " ").Trim();
149+
string normalized = TaskTextQualityHelper.SanitizeTaskText(text);
130150

131151
var matchWords = ChineseOrEnglishWordRegex.Matches(normalized).Cast<Match>().Select(m => m.Value).ToList();
132152
if (matchWords.Count < 2 && normalized.Length < 5)
133153
return null;
134154

135-
return normalized.Length >= 3 ? normalized : null;
155+
return TaskTextQualityHelper.IsMeaningfulTaskText(normalized) ? normalized : null;
136156
}
137157

138158
/// <summary>
@@ -204,10 +224,7 @@ private static bool ContainsAny(string text, IEnumerable<string> words)
204224

205225
private static string NormalizeText(string text)
206226
{
207-
string normalized = text.Trim();
208-
normalized = Regex.Replace(normalized, @"[,。!?,.!?;;]+", " ");
209-
normalized = Regex.Replace(normalized, @"\s+", " ");
210-
return normalized.Trim();
227+
return TaskTextQualityHelper.Normalize(text);
211228
}
212229
}
213230
}

LifeProfileEngine.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ private static LifeProfileSnapshot BuildSnapshot(UserProfileSnapshot behaviorSna
7979
tasks ??= new List<ItemGrid>();
8080

8181
var activeTasks = tasks.Where(t => t != null && t.IsActive).ToList();
82+
var qualityTasks = activeTasks
83+
.Where(t => TaskTextQualityHelper.IsMeaningfulTaskText(t.Task))
84+
.ToList();
85+
if (!qualityTasks.Any())
86+
{
87+
qualityTasks = activeTasks;
88+
}
8289
int totalReminderResponses = Math.Max(1,
8390
behaviorSnapshot.ReminderCompletedCount +
8491
behaviorSnapshot.ReminderUpdatedCount +
@@ -98,29 +105,34 @@ private static LifeProfileSnapshot BuildSnapshot(UserProfileSnapshot behaviorSna
98105
.ToList();
99106

100107
var topTopics = (behaviorSnapshot.TaskKeywordHistogram ?? new Dictionary<string, int>())
108+
.Where(kv => !string.IsNullOrWhiteSpace(kv.Key))
109+
.Where(kv => !string.Equals(kv.Key, "High", StringComparison.OrdinalIgnoreCase))
110+
.Where(kv => !string.Equals(kv.Key, "Medium", StringComparison.OrdinalIgnoreCase))
111+
.Where(kv => !string.Equals(kv.Key, "Low", StringComparison.OrdinalIgnoreCase))
112+
.Where(kv => !string.Equals(kv.Key, "Unknown", StringComparison.OrdinalIgnoreCase))
101113
.OrderByDescending(kv => kv.Value)
102114
.ThenBy(kv => kv.Key, StringComparer.OrdinalIgnoreCase)
103115
.Take(8)
104116
.Select(kv => kv.Key)
105117
.ToList();
106118

107-
int highHighCount = activeTasks.Count(t =>
119+
int highHighCount = qualityTasks.Count(t =>
108120
string.Equals(t.Importance, "High", StringComparison.OrdinalIgnoreCase) &&
109121
string.Equals(t.Urgency, "High", StringComparison.OrdinalIgnoreCase));
110122

111-
int stuckTaskCount = activeTasks.Count(t => t.LastProgressDate < now.AddDays(-3));
112-
int goalLinkedCount = activeTasks.Count(t => !string.IsNullOrWhiteSpace(t.LongTermGoalId));
123+
int stuckTaskCount = qualityTasks.Count(t => t.LastProgressDate < now.AddDays(-3));
124+
int goalLinkedCount = qualityTasks.Count(t => !string.IsNullOrWhiteSpace(t.LongTermGoalId));
113125

114126
var strengths = new List<string>();
115127
if (executionReliability >= 0.65) strengths.Add("consistent_executor");
116-
if (goalLinkedCount >= Math.Max(2, activeTasks.Count / 3)) strengths.Add("goal_oriented");
117-
if (highHighCount <= Math.Max(1, activeTasks.Count / 4)) strengths.Add("prioritization_control");
128+
if (goalLinkedCount >= Math.Max(2, qualityTasks.Count / 3)) strengths.Add("goal_oriented");
129+
if (highHighCount <= Math.Max(1, qualityTasks.Count / 4)) strengths.Add("prioritization_control");
118130
if (peakHours.Any()) strengths.Add("predictable_energy_rhythm");
119131

120132
var risks = new List<string>();
121133
if (interruptionSensitivity >= 0.55) risks.Add("high_interruption_cost");
122-
if (stuckTaskCount >= Math.Max(2, activeTasks.Count / 3)) risks.Add("stuck_backlog");
123-
if (highHighCount >= Math.Max(3, activeTasks.Count / 2)) risks.Add("urgency_overload");
134+
if (stuckTaskCount >= Math.Max(2, qualityTasks.Count / 3)) risks.Add("stuck_backlog");
135+
if (highHighCount >= Math.Max(3, qualityTasks.Count / 2)) risks.Add("urgency_overload");
124136

125137
string style = "balanced";
126138
if (executionReliability >= 0.7 && interruptionSensitivity <= 0.3)
@@ -145,7 +157,7 @@ private static LifeProfileSnapshot BuildSnapshot(UserProfileSnapshot behaviorSna
145157
PeakHours = peakHours,
146158
ExecutionReliability = executionReliability,
147159
InterruptionSensitivity = interruptionSensitivity,
148-
ActiveTaskCount = activeTasks.Count,
160+
ActiveTaskCount = qualityTasks.Count,
149161
StuckTaskCount = stuckTaskCount,
150162
GoalLinkedTaskCount = goalLinkedCount
151163
};

MainWindow.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ public sealed class SystemSkillNodeSnapshot
416416
private LifeProfileEngine _lifeProfileEngine;
417417
private DecisionEngine _decisionEngine;
418418
private WeeklyReviewEngine _weeklyReviewEngine;
419+
private VoiceRecognitionQualityEngine _voiceRecognitionQualityEngine;
419420
private GoalHierarchyEngine _goalHierarchyEngine;
420421
private System.Windows.Threading.DispatcherTimer _smartSystemTimer;
421422
private System.Windows.Threading.DispatcherTimer _conversationIdleTimer;
@@ -1184,6 +1185,7 @@ private void InitializeSmartSystems()
11841185
_lifeProfileEngine = new LifeProfileEngine(dataPath);
11851186
_decisionEngine = new DecisionEngine(dataPath, _decisionOptions);
11861187
_weeklyReviewEngine = new WeeklyReviewEngine(dataPath);
1188+
_voiceRecognitionQualityEngine = new VoiceRecognitionQualityEngine(dataPath);
11871189
_goalHierarchyEngine = new GoalHierarchyEngine(dataPath);
11881190

11891191
_smartGuidanceManager.ScenarioTriggered += SmartGuidanceManager_ScenarioTriggered;
@@ -1246,6 +1248,7 @@ private void RunStrategicNavigationCycle(bool force)
12461248
_goalHierarchyEngine?.BuildAndPersist(activeGoals, allTasks, now);
12471249
var ranked = _decisionEngine?.RankTasks(allTasks, lifeProfile, _activeLongTermGoal?.Id, now) ?? new List<TaskDecisionScore>();
12481250
_decisionEngine?.PersistSnapshot(ranked, now);
1251+
_voiceRecognitionQualityEngine?.BuildAndPersist(allTasks, now);
12491252

12501253
WeeklyReviewReport weeklyReport = null;
12511254
bool shouldRunWeekly = force || now.DayOfWeek == _weeklyReviewPublishDay;
@@ -1885,6 +1888,11 @@ private void AddConversationTasks(List<string> tasks)
18851888
{
18861889
foreach (var taskText in tasks.Take(5))
18871890
{
1891+
if (!TaskTextQualityHelper.IsMeaningfulTaskText(taskText))
1892+
{
1893+
continue;
1894+
}
1895+
18881896
var intentRecognizer = new IntentRecognizer();
18891897
var (importance, urgency) = intentRecognizer.EstimatePriority(taskText);
18901898
var quadrant = intentRecognizer.EstimateQuadrant(importance, urgency);

0 commit comments

Comments
 (0)