From 2fd5b3fc2f9d0787d89ff4cb652cb467fd2bba08 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 10 Sep 2025 18:02:15 -0700 Subject: [PATCH] remove vosk logs in release builds --- src/main.zig | 47 ++++++++++++++++++++--------------------------- src/stt.zig | 5 +++++ 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/main.zig b/src/main.zig index 87fd97f..3a5c352 100644 --- a/src/main.zig +++ b/src/main.zig @@ -50,12 +50,12 @@ const DemoHandler = struct { } fn logDetail(self: *DemoHandler, error_info: stt.SttErrorInfo) !void { + const log = std.log.scoped(.stt); // Categorize the error for statistics - if (error_info.recoverable) { - self.recoverable_error_count += 1; - } else { + if (error_info.recoverable) + self.recoverable_error_count += 1 + else self.error_count += 1; - } if (builtin.is_test) return; // Suppress output during tests @@ -72,8 +72,13 @@ const DemoHandler = struct { if (error_info.system_error) |sys_err| try writer.print("\n\tSystem Error: {} ({any})", .{ sys_err, error_info.error_code }); - if (error_info.recovery_suggestion) |suggestion| + if (error_info.recovery_suggestion) |suggestion| { + if (std.mem.eql(u8, "Ready to start speech recognition", suggestion)) { + self.recoverable_error_count -= 1; + return; // that's stupid + } try writer.print("\n\tSuggestion: {s}", .{suggestion}); + } if (error_info.recoverable) try writer.print("\n\tStatus: Recoverable - system will attempt to continue", .{}) @@ -85,29 +90,18 @@ const DemoHandler = struct { // Determine and call appropriate log function once switch (error_info.error_code) { stt.SttError.InternalError => if (error_info.recoverable) { - std.log.info("{s}", .{message}); + log.info("{s}", .{message}); } else { - std.log.warn("{s}", .{message}); + log.warn("{s}", .{message}); }, stt.SttError.OutOfMemory, stt.SttError.ModelLoadError, stt.SttError.InitializationFailed, - => { - std.log.err("{s}", .{message}); - }, - stt.SttError.AudioDeviceError, - stt.SttError.AudioDeviceBusy, - stt.SttError.AudioDeviceNotFound, - => if (error_info.recoverable) { - std.log.warn("{s}", .{message}); - } else { - std.log.err("{s}", .{message}); - }, - else => if (error_info.recoverable) { - std.log.warn("{s}", .{message}); - } else { - std.log.err("{s}", .{message}); - }, + => log.err("{s}", .{message}), + else => if (error_info.recoverable) + log.warn("{s}", .{message}) + else + log.err("{s}", .{message}), } } @@ -196,8 +190,7 @@ pub fn main() !void { _ = stdout.writeAll("\n") catch {}; } - std.log.info("✓ STT library initialized successfully", .{}); - std.log.info("Configuration:", .{}); + 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}); std.log.info(" Sample rate: {} Hz", .{options.sample_rate}); @@ -230,7 +223,7 @@ pub fn main() !void { session.stop_listening(); } - std.log.info("✓ Speech recognition started successfully", .{}); + std.log.info("Speech recognition started successfully", .{}); _ = stdout.writeAll("Listening for speech... (Press Ctrl+C to exit)\n") catch {}; _ = stdout.writeAll("Speak into your microphone to see speech recognition results\n") catch {}; _ = stdout.writeAll("------------------------------------------------------------\n") catch {}; @@ -268,7 +261,7 @@ pub fn main() !void { } else if (stats.recoverable_error_count > 0) { std.log.info("⚠ Recoverable issues occurred but system continued operating.", .{}); } else { - std.log.info("ℹ No speech was detected during this session.", .{}); + std.log.info("ℹ No speech was detected during this session.", .{}); } _ = stdout.writeAll("Session completed successfully.\n") catch {}; diff --git a/src/stt.zig b/src/stt.zig index 0f3840d..7844304 100644 --- a/src/stt.zig +++ b/src/stt.zig @@ -673,6 +673,11 @@ pub const SttSession = struct { const model_path_cstr = try self.allocator.dupeZ(u8, self.options.model_path); defer self.allocator.free(model_path_cstr); + // Set Vosk log level - disable logs for non-debug builds + if (@import("builtin").mode != .Debug) { + c.vosk_set_log_level(-1); // Disable all Vosk logging + } + // Load Vosk model self.vosk_model = c.vosk_model_new(model_path_cstr.ptr); if (self.vosk_model == null) {