better modeling
This commit is contained in:
parent
33aa37cf38
commit
6fe5bba155
1 changed files with 53 additions and 16 deletions
69
src/main.zig
69
src/main.zig
|
@ -132,6 +132,7 @@ fn signalHandler(sig: c_int) callconv(.c) void {
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const stdout = std.fs.File.stdout();
|
const stdout = std.fs.File.stdout();
|
||||||
|
const stderr = std.fs.File.stderr();
|
||||||
|
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
defer _ = gpa.deinit();
|
defer _ = gpa.deinit();
|
||||||
|
@ -164,10 +165,55 @@ pub fn main() !void {
|
||||||
.ctx = &demo_handler,
|
.ctx = &demo_handler,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize STT session with existing audio device configuration
|
// Parse command line arguments
|
||||||
// These parameters maintain the existing working behavior
|
const args = try std.process.argsAlloc(allocator);
|
||||||
|
defer std.process.argsFree(allocator, args);
|
||||||
|
|
||||||
|
var model_path: ?[]const u8 = null;
|
||||||
|
|
||||||
|
// Parse --model argument
|
||||||
|
for (args[1..]) |arg| {
|
||||||
|
if (std.mem.startsWith(u8, arg, "--model=")) {
|
||||||
|
model_path = arg[8..]; // Skip "--model="
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no model specified, try default locations
|
||||||
|
const default_paths = [_][]const u8{
|
||||||
|
"vosk-model-small-en-us-0.15",
|
||||||
|
"zig-out/bin/vosk-model-small-en-us-0.15",
|
||||||
|
"/usr/share/vosk/models/vosk-model-small-en-us-0.15",
|
||||||
|
};
|
||||||
|
|
||||||
|
if (model_path == null) {
|
||||||
|
for (default_paths) |path| {
|
||||||
|
std.fs.cwd().access(path, .{}) catch continue;
|
||||||
|
model_path = path;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if model path exists
|
||||||
|
if (model_path == null) {
|
||||||
|
_ = try stderr.writeAll("Error: Vosk model not found.\n\n");
|
||||||
|
_ = try stderr.writeAll("Usage: stt-demo [--model=<path>]\n\n");
|
||||||
|
_ = try stderr.writeAll("Locations searched:\n");
|
||||||
|
inline for (default_paths) |path|
|
||||||
|
_ = try stderr.writeAll("\t" ++ path ++ "\n");
|
||||||
|
_ = try stderr.writeAll("Please download the model. A fine model can be downloaded from:\n");
|
||||||
|
_ = try stderr.writeAll("\thttps://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip\n");
|
||||||
|
std.process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
std.fs.cwd().access(model_path.?, .{}) catch {
|
||||||
|
std.log.err("Model path does not exist: {s}", .{model_path.?});
|
||||||
|
std.process.exit(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialize STT session with resolved model path
|
||||||
const options = stt.SttOptions{
|
const options = stt.SttOptions{
|
||||||
.model_path = "zig-out/bin/vosk-model-small-en-us-0.15",
|
.model_path = model_path.?,
|
||||||
.audio_device = "default", // Use ALSA default device from alsa.conf
|
.audio_device = "default", // Use ALSA default device from alsa.conf
|
||||||
.event_handler = speech_handler,
|
.event_handler = speech_handler,
|
||||||
.sample_rate = 16000, // Standard sample rate for speech recognition
|
.sample_rate = 16000, // Standard sample rate for speech recognition
|
||||||
|
@ -249,20 +295,11 @@ pub fn main() !void {
|
||||||
std.log.info(" Speech detections: {}", .{stats.speech_count});
|
std.log.info(" Speech detections: {}", .{stats.speech_count});
|
||||||
std.log.info(" Fatal errors: {}", .{stats.error_count});
|
std.log.info(" Fatal errors: {}", .{stats.error_count});
|
||||||
std.log.info(" Recoverable errors: {}", .{stats.recoverable_error_count});
|
std.log.info(" Recoverable errors: {}", .{stats.recoverable_error_count});
|
||||||
std.log.info(" Total issues: {}", .{stats.total_issues});
|
std.log.info(" Total issues: {}\n", .{stats.total_issues});
|
||||||
|
|
||||||
if (stats.speech_count > 0) {
|
// Print seperately since ^^ are info calls and vv is an error call
|
||||||
std.log.info("✓ Speech recognition worked successfully!", .{});
|
if (stats.error_count > 0)
|
||||||
if (stats.recoverable_error_count > 0) {
|
std.log.err("✗ {d} fatal errors occurred during speech recognition.", .{stats.error_count});
|
||||||
std.log.info("ℹ System recovered from {} issues during operation.", .{stats.recoverable_error_count});
|
|
||||||
}
|
|
||||||
} else if (stats.error_count > 0) {
|
|
||||||
std.log.info("✗ Fatal errors occurred during speech recognition.", .{});
|
|
||||||
} 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.", .{});
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = stdout.writeAll("Session completed successfully.\n") catch {};
|
_ = stdout.writeAll("Session completed successfully.\n") catch {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue