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:
@@ -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).");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
19
Program.cs
19
Program.cs
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user