remove vosk logs in release builds
This commit is contained in:
parent
b6cfeea62f
commit
2fd5b3fc2f
2 changed files with 25 additions and 27 deletions
47
src/main.zig
47
src/main.zig
|
@ -50,12 +50,12 @@ const DemoHandler = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn logDetail(self: *DemoHandler, error_info: stt.SttErrorInfo) !void {
|
fn logDetail(self: *DemoHandler, error_info: stt.SttErrorInfo) !void {
|
||||||
|
const log = std.log.scoped(.stt);
|
||||||
// Categorize the error for statistics
|
// Categorize the error for statistics
|
||||||
if (error_info.recoverable) {
|
if (error_info.recoverable)
|
||||||
self.recoverable_error_count += 1;
|
self.recoverable_error_count += 1
|
||||||
} else {
|
else
|
||||||
self.error_count += 1;
|
self.error_count += 1;
|
||||||
}
|
|
||||||
|
|
||||||
if (builtin.is_test) return; // Suppress output during tests
|
if (builtin.is_test) return; // Suppress output during tests
|
||||||
|
|
||||||
|
@ -72,8 +72,13 @@ const DemoHandler = struct {
|
||||||
if (error_info.system_error) |sys_err|
|
if (error_info.system_error) |sys_err|
|
||||||
try writer.print("\n\tSystem Error: {} ({any})", .{ sys_err, error_info.error_code });
|
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});
|
try writer.print("\n\tSuggestion: {s}", .{suggestion});
|
||||||
|
}
|
||||||
|
|
||||||
if (error_info.recoverable)
|
if (error_info.recoverable)
|
||||||
try writer.print("\n\tStatus: Recoverable - system will attempt to continue", .{})
|
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
|
// Determine and call appropriate log function once
|
||||||
switch (error_info.error_code) {
|
switch (error_info.error_code) {
|
||||||
stt.SttError.InternalError => if (error_info.recoverable) {
|
stt.SttError.InternalError => if (error_info.recoverable) {
|
||||||
std.log.info("{s}", .{message});
|
log.info("{s}", .{message});
|
||||||
} else {
|
} else {
|
||||||
std.log.warn("{s}", .{message});
|
log.warn("{s}", .{message});
|
||||||
},
|
},
|
||||||
stt.SttError.OutOfMemory,
|
stt.SttError.OutOfMemory,
|
||||||
stt.SttError.ModelLoadError,
|
stt.SttError.ModelLoadError,
|
||||||
stt.SttError.InitializationFailed,
|
stt.SttError.InitializationFailed,
|
||||||
=> {
|
=> log.err("{s}", .{message}),
|
||||||
std.log.err("{s}", .{message});
|
else => if (error_info.recoverable)
|
||||||
},
|
log.warn("{s}", .{message})
|
||||||
stt.SttError.AudioDeviceError,
|
else
|
||||||
stt.SttError.AudioDeviceBusy,
|
log.err("{s}", .{message}),
|
||||||
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});
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,8 +190,7 @@ pub fn main() !void {
|
||||||
_ = stdout.writeAll("\n") catch {};
|
_ = stdout.writeAll("\n") catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std.log.info("✓ STT library initialized successfully", .{});
|
std.log.info("STT library initialized successfully with configuration:", .{});
|
||||||
std.log.info("Configuration:", .{});
|
|
||||||
std.log.info(" Model path: {s}", .{options.model_path});
|
std.log.info(" Model path: {s}", .{options.model_path});
|
||||||
std.log.info(" Audio device: {s}", .{options.audio_device});
|
std.log.info(" Audio device: {s}", .{options.audio_device});
|
||||||
std.log.info(" Sample rate: {} Hz", .{options.sample_rate});
|
std.log.info(" Sample rate: {} Hz", .{options.sample_rate});
|
||||||
|
@ -230,7 +223,7 @@ pub fn main() !void {
|
||||||
session.stop_listening();
|
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("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("Speak into your microphone to see speech recognition results\n") catch {};
|
||||||
_ = stdout.writeAll("------------------------------------------------------------\n") catch {};
|
_ = stdout.writeAll("------------------------------------------------------------\n") catch {};
|
||||||
|
@ -268,7 +261,7 @@ pub fn main() !void {
|
||||||
} else if (stats.recoverable_error_count > 0) {
|
} else if (stats.recoverable_error_count > 0) {
|
||||||
std.log.info("⚠ Recoverable issues occurred but system continued operating.", .{});
|
std.log.info("⚠ Recoverable issues occurred but system continued operating.", .{});
|
||||||
} else {
|
} 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 {};
|
_ = stdout.writeAll("Session completed successfully.\n") catch {};
|
||||||
|
|
|
@ -673,6 +673,11 @@ pub const SttSession = struct {
|
||||||
const model_path_cstr = try self.allocator.dupeZ(u8, self.options.model_path);
|
const model_path_cstr = try self.allocator.dupeZ(u8, self.options.model_path);
|
||||||
defer self.allocator.free(model_path_cstr);
|
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
|
// Load Vosk model
|
||||||
self.vosk_model = c.vosk_model_new(model_path_cstr.ptr);
|
self.vosk_model = c.vosk_model_new(model_path_cstr.ptr);
|
||||||
if (self.vosk_model == null) {
|
if (self.vosk_model == null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue