From d443a36f7a62f1c7ff294d414dfb1fec73c09b0c Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Thu, 11 Sep 2025 09:32:44 -0700 Subject: [PATCH] optional process to exec. Spawn without wait, not sure how legit --- src/main.zig | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main.zig b/src/main.zig index 8f12195..b04a114 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,6 +9,7 @@ var should_exit = std.atomic.Value(bool).init(false); /// Demo implementation of speech event handler with comprehensive error handling const SpeechHandler = struct { + allocator: std.mem.Allocator, speech_count: u32 = 0, error_count: u32 = 0, warning_count: u32 = 0, @@ -24,13 +25,19 @@ const SpeechHandler = struct { // Print with timestamp for better experience const timestamp = std.time.timestamp(); - std.debug.print("[{}] Speech #{}: {s}\n", .{ timestamp, self.speech_count, text }); + std.log.debug("[{}] Speech {}->{?s}: {s}", .{ + timestamp, + self.speech_count, + self.exec_program, + text, + }); // Execute program if specified if (self.exec_program) |program| { - var child = std.process.Child.init(&[_][]const u8{ program, text }, std.heap.page_allocator); - _ = child.spawn() catch |err| { + var child = std.process.Child.init(&[_][]const u8{ program, text }, self.allocator); + child.spawn() catch |err| { std.log.err("Failed to execute program '{s}': {}", .{ program, err }); + return; }; } } @@ -179,7 +186,10 @@ pub fn main() !void { } // Create handler with statistics tracking - var handler = SpeechHandler{ .exec_program = exec_program }; + var handler = SpeechHandler{ + .allocator = allocator, + .exec_program = exec_program, + }; const speech_handler = stt.SpeechEventHandler{ .onSpeechFn = SpeechHandler.onSpeech, .onErrorFn = SpeechHandler.onError, @@ -244,6 +254,7 @@ pub fn main() !void { _ = stdout.writeAll("\n") catch {}; } + std.log.info("Program to execute on speech detection: {?s}", .{exec_program}); std.log.info("STT library initialized successfully with configuration:", .{}); std.log.info(" Model path: {s}", .{options.model_path}); std.log.info(" Audio device: {s}", .{options.audio_device}); @@ -316,7 +327,7 @@ pub fn main() !void { test "handler functionality" { const testing = std.testing; - var handler = SpeechHandler{}; + var handler = SpeechHandler{ .allocator = std.testing.allocator }; const speech_handler = stt.SpeechEventHandler{ .onSpeechFn = SpeechHandler.onSpeech, .onErrorFn = SpeechHandler.onError,