look for models in a better directory
This commit is contained in:
parent
0262ca6659
commit
186651dce0
2 changed files with 16 additions and 8 deletions
|
@ -23,7 +23,7 @@ pub fn build(b: *std.Build) void {
|
|||
// Install the model to the output directory
|
||||
const install_model = b.addInstallDirectory(.{
|
||||
.source_dir = model_step.getOutputPath(),
|
||||
.install_dir = .bin,
|
||||
.install_dir = .{ .custom = "share/vosk/models" },
|
||||
.install_subdir = "vosk-model-small-en-us-0.15",
|
||||
});
|
||||
install_model.step.dependOn(&model_step.step);
|
||||
|
|
22
src/main.zig
22
src/main.zig
|
@ -337,12 +337,11 @@ pub fn main() !void {
|
|||
_ = try stdout.writeAll(" --help, -h Show this help message\n\n");
|
||||
_ = try stdout.writeAll("EXAMPLES:\n");
|
||||
_ = try stdout.writeAll(" stt\n");
|
||||
_ = try stdout.writeAll(" stt --model=vosk-model-small-en-us-0.15\n");
|
||||
_ = try stdout.writeAll(" stt --model=../share/vosk/models/vosk-model-small-en-us-0.15\n");
|
||||
_ = try stdout.writeAll(" stt --exec=echo\n\n");
|
||||
_ = try stdout.writeAll("The application will search for models in these locations:\n");
|
||||
_ = try stdout.writeAll(" vosk-model-small-en-us-0.15\n");
|
||||
_ = try stdout.writeAll(" zig-out/bin/vosk-model-small-en-us-0.15\n");
|
||||
_ = try stdout.writeAll(" /usr/share/vosk/models/vosk-model-small-en-us-0.15\n");
|
||||
_ = try stdout.writeAll(" <binary_dir>/../share/vosk/models/vosk-model-small-en-us-0.15\n");
|
||||
return;
|
||||
} else if (std.mem.startsWith(u8, arg, "--model=")) {
|
||||
model_path = arg[8..]; // Skip "--model="
|
||||
|
@ -365,10 +364,16 @@ pub fn main() !void {
|
|||
};
|
||||
|
||||
// If no model specified, try default locations
|
||||
var exe_path_buf: [std.fs.max_path_bytes]u8 = undefined;
|
||||
const exe_path = std.fs.selfExePath(&exe_path_buf) catch "stt";
|
||||
const exe_dir = std.fs.path.dirname(exe_path) orelse ".";
|
||||
|
||||
const xdg_model_path = try std.fmt.allocPrint(allocator, "{s}/../share/vosk/models/vosk-model-small-en-us-0.15", .{exe_dir});
|
||||
defer allocator.free(xdg_model_path);
|
||||
|
||||
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",
|
||||
xdg_model_path,
|
||||
};
|
||||
|
||||
if (model_path == null) {
|
||||
|
@ -384,8 +389,11 @@ pub fn main() !void {
|
|||
_ = try stderr.writeAll("Error: Vosk model not found.\n\n");
|
||||
_ = try stderr.writeAll("Usage: stt [--model=<path>] [--exec=<program>]\n\n");
|
||||
_ = try stderr.writeAll("Locations searched:\n");
|
||||
inline for (default_paths) |path|
|
||||
_ = try stderr.writeAll("\t" ++ path ++ "\n");
|
||||
for (default_paths) |path| {
|
||||
_ = try stderr.writeAll("\t");
|
||||
_ = try stderr.writeAll(path);
|
||||
_ = try stderr.writeAll("\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);
|
||||
|
|
Loading…
Add table
Reference in a new issue