SttOptions -> Options
This commit is contained in:
parent
3bb4b45dde
commit
f81d2369f6
3 changed files with 13 additions and 13 deletions
|
@ -396,7 +396,7 @@ pub fn main() !void {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize STT session with resolved model path
|
// Initialize STT session with resolved model path
|
||||||
const options = stt.SttOptions{
|
const options = stt.Options{
|
||||||
.model_path = model_path.?,
|
.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,
|
||||||
|
|
20
src/stt.zig
20
src/stt.zig
|
@ -520,7 +520,7 @@ pub const AlsaCapture = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Configuration options for STT session initialization
|
/// Configuration options for STT session initialization
|
||||||
pub const SttOptions = struct {
|
pub const Options = struct {
|
||||||
/// Path to the Vosk model directory
|
/// Path to the Vosk model directory
|
||||||
model_path: []const u8,
|
model_path: []const u8,
|
||||||
/// ALSA audio device name (e.g., "hw:3,0")
|
/// ALSA audio device name (e.g., "hw:3,0")
|
||||||
|
@ -545,7 +545,7 @@ pub const SttSession = struct {
|
||||||
/// Memory allocator
|
/// Memory allocator
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
/// Configuration options
|
/// Configuration options
|
||||||
options: SttOptions,
|
options: Options,
|
||||||
/// Initialization state
|
/// Initialization state
|
||||||
initialized: bool = false,
|
initialized: bool = false,
|
||||||
/// Listening state
|
/// Listening state
|
||||||
|
@ -576,7 +576,7 @@ pub const SttSession = struct {
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// - SttSession instance on success
|
/// - SttSession instance on success
|
||||||
/// - SttError on failure
|
/// - SttError on failure
|
||||||
pub fn init(allocator: std.mem.Allocator, options: SttOptions) SttError!SttSession {
|
pub fn init(allocator: std.mem.Allocator, options: Options) SttError!SttSession {
|
||||||
// Validate options first with detailed error reporting
|
// Validate options first with detailed error reporting
|
||||||
validateOptions(options) catch |err| {
|
validateOptions(options) catch |err| {
|
||||||
const error_info = switch (err) {
|
const error_info = switch (err) {
|
||||||
|
@ -1121,7 +1121,7 @@ pub const SttSession = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Validate session options before initialization
|
/// Validate session options before initialization
|
||||||
fn validateOptions(options: SttOptions) SttError!void {
|
fn validateOptions(options: Options) SttError!void {
|
||||||
if (options.model_path.len == 0) {
|
if (options.model_path.len == 0) {
|
||||||
return SttError.InvalidParameter;
|
return SttError.InvalidParameter;
|
||||||
}
|
}
|
||||||
|
@ -1329,7 +1329,7 @@ pub const SttSession = struct {
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// - SttSession instance on success
|
/// - SttSession instance on success
|
||||||
/// - SttError on failure
|
/// - SttError on failure
|
||||||
pub fn init(allocator: std.mem.Allocator, options: SttOptions) SttError!SttSession {
|
pub fn init(allocator: std.mem.Allocator, options: Options) SttError!SttSession {
|
||||||
return SttSession.init(allocator, options);
|
return SttSession.init(allocator, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1401,7 +1401,7 @@ test "SttError enum" {
|
||||||
try testing.expect(err1 == SttError.InitializationFailed);
|
try testing.expect(err1 == SttError.InitializationFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "SttOptions validation" {
|
test "Options validation" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
|
|
||||||
// Test valid options
|
// Test valid options
|
||||||
|
@ -1421,7 +1421,7 @@ test "SttOptions validation" {
|
||||||
};
|
};
|
||||||
|
|
||||||
var dummy_ctx: u8 = 0;
|
var dummy_ctx: u8 = 0;
|
||||||
const valid_options = SttOptions{
|
const valid_options = Options{
|
||||||
.model_path = "/path/to/model",
|
.model_path = "/path/to/model",
|
||||||
.audio_device = "hw:0,0",
|
.audio_device = "hw:0,0",
|
||||||
.event_handler = SpeechEventHandler{
|
.event_handler = SpeechEventHandler{
|
||||||
|
@ -1458,7 +1458,7 @@ test "SttSession state management" {
|
||||||
};
|
};
|
||||||
|
|
||||||
var dummy_ctx: u8 = 0;
|
var dummy_ctx: u8 = 0;
|
||||||
const options = SttOptions{
|
const options = Options{
|
||||||
.model_path = "/path/to/model",
|
.model_path = "/path/to/model",
|
||||||
.audio_device = "hw:0,0",
|
.audio_device = "hw:0,0",
|
||||||
.event_handler = SpeechEventHandler{
|
.event_handler = SpeechEventHandler{
|
||||||
|
@ -1687,7 +1687,7 @@ test "SttSession session management API" {
|
||||||
};
|
};
|
||||||
|
|
||||||
var handler = TestHandler{};
|
var handler = TestHandler{};
|
||||||
const options = SttOptions{
|
const options = Options{
|
||||||
.model_path = "/invalid/path", // Will fail, but that's expected
|
.model_path = "/invalid/path", // Will fail, but that's expected
|
||||||
.audio_device = "hw:0,0",
|
.audio_device = "hw:0,0",
|
||||||
.event_handler = SpeechEventHandler{
|
.event_handler = SpeechEventHandler{
|
||||||
|
@ -1705,7 +1705,7 @@ test "SttSession session management API" {
|
||||||
try testing.expect(options.buffer_size == 256);
|
try testing.expect(options.buffer_size == 256);
|
||||||
|
|
||||||
// Test options validation
|
// Test options validation
|
||||||
const invalid_options = SttOptions{
|
const invalid_options = Options{
|
||||||
.model_path = "", // Invalid empty path
|
.model_path = "", // Invalid empty path
|
||||||
.audio_device = "hw:0,0",
|
.audio_device = "hw:0,0",
|
||||||
.event_handler = options.event_handler,
|
.event_handler = options.event_handler,
|
||||||
|
|
|
@ -260,7 +260,7 @@ test "SttSession initialization error handling" {
|
||||||
const speech_handler = test_handler.getSpeechEventHandler();
|
const speech_handler = test_handler.getSpeechEventHandler();
|
||||||
|
|
||||||
// Test with invalid model path - but don't actually call init to avoid segfault
|
// Test with invalid model path - but don't actually call init to avoid segfault
|
||||||
const invalid_options = stt.SttOptions{
|
const invalid_options = stt.Options{
|
||||||
.model_path = "/nonexistent/path",
|
.model_path = "/nonexistent/path",
|
||||||
.audio_device = "hw:999,0", // Non-existent device
|
.audio_device = "hw:999,0", // Non-existent device
|
||||||
.event_handler = speech_handler,
|
.event_handler = speech_handler,
|
||||||
|
@ -284,7 +284,7 @@ test "SttSession mock initialization and cleanup" {
|
||||||
const speech_handler = test_handler.getSpeechEventHandler();
|
const speech_handler = test_handler.getSpeechEventHandler();
|
||||||
|
|
||||||
// Test options validation
|
// Test options validation
|
||||||
const valid_options = stt.SttOptions{
|
const valid_options = stt.Options{
|
||||||
.model_path = "test/model/path",
|
.model_path = "test/model/path",
|
||||||
.audio_device = "hw:0,0",
|
.audio_device = "hw:0,0",
|
||||||
.event_handler = speech_handler,
|
.event_handler = speech_handler,
|
||||||
|
|
Loading…
Add table
Reference in a new issue