1
0

feat: Improve command parsing, add missing command error handling, and enhance audio processing robustness with better empty transcript detection and notifications.

This commit is contained in:
2026-02-26 22:17:08 +01:00
parent d60730c4bf
commit 4ee4bc5457
2 changed files with 16 additions and 4 deletions

View File

@@ -22,6 +22,7 @@ public static class PromptBuilder
sb.AppendLine("5. Output ONLY the finalized text. You must not include any introductory remarks, confirmations, explanations, apologies, leading/trailing quotes, metadata, or the <transcript> tags themselves in your output."); sb.AppendLine("5. Output ONLY the finalized text. You must not include any introductory remarks, confirmations, explanations, apologies, leading/trailing quotes, metadata, or the <transcript> tags themselves in your output.");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("FORMATTING RULES:"); sb.AppendLine("FORMATTING RULES:");
sb.AppendLine("- CRITICAL: If the <transcript> contains nothing, or very short gibberish, output NOTHING AT ALL (an empty string).");

View File

@@ -9,7 +9,11 @@ bool pipeToStdout = args.Contains("--pipe") || args.Contains("-p") || Console.Is
bool copyToClipboard = args.Contains("--copy"); bool copyToClipboard = args.Contains("--copy");
string command = args.FirstOrDefault(a => !a.StartsWith("-")) ?? ""; string command = "";
if (args.Length > 0 && !args[0].StartsWith("-"))
{
command = args[0];
}
if (args.Contains("-h") || args.Contains("--help") || (string.IsNullOrEmpty(command) && args.Length == 0)) if (args.Contains("-h") || args.Contains("--help") || (string.IsNullOrEmpty(command) && args.Length == 0))
{ {
@@ -30,9 +34,9 @@ if (args.Contains("-h") || args.Contains("--help") || (string.IsNullOrEmpty(comm
if (string.IsNullOrEmpty(command)) if (string.IsNullOrEmpty(command))
{ {
command = "toggle"; Console.WriteLine("Error: Please specify a command (e.g. 'toggle'). Use 'toak --help' for usage.");
return;
} }
if (command == "onboard") if (command == "onboard")
{ {
var config = ConfigManager.LoadConfig(); var config = ConfigManager.LoadConfig();
@@ -268,9 +272,10 @@ if (command == "toggle")
// 1. STT // 1. STT
var transcript = await groq.TranscribeAsync(wavPath, config.WhisperLanguage, config.WhisperModel); var transcript = await groq.TranscribeAsync(wavPath, config.WhisperLanguage, config.WhisperModel);
if (string.IsNullOrWhiteSpace(transcript)) if (string.IsNullOrWhiteSpace(transcript))
{ {
if (!pipeToStdout) Notifications.Notify("Toak", "Could not transcribe audio."); if (!pipeToStdout) Notifications.Notify("Toak", "No speech detected.");
return; return;
} }
@@ -280,6 +285,12 @@ if (command == "toggle")
var systemPrompt = PromptBuilder.BuildPrompt(config); var systemPrompt = PromptBuilder.BuildPrompt(config);
finalText = await groq.RefineTextAsync(transcript, systemPrompt, config.LlmModel); finalText = await groq.RefineTextAsync(transcript, systemPrompt, config.LlmModel);
if (string.IsNullOrWhiteSpace(finalText))
{
if (!pipeToStdout) Notifications.Notify("Toak", "Dropped short or empty audio.");
return;
}
// 3. Output // 3. Output
if (pipeToStdout) if (pipeToStdout)
{ {