omlins / JustSayIt.jl

Software and high-level API for offline, low latency and secure translation of human speech to computer commands or text on Linux, MacOS and Windows
BSD 3-Clause "New" or "Revised" License
87 stars 12 forks source link

fix type check #89

Closed omlins closed 1 year ago

omlins commented 1 year ago

fixes #87

CC @pfitzseb

omlins commented 1 year ago

MWE:

julia> using JustSayIt
[ Info: Precompiling JustSayIt [d7252348-293e-4f11-8d42-c8418dda4315]

julia> commands = Dict(
                "ma" => Mouse.click_left
              )
Dict{String, typeof(JustSayIt.Mouse.click_left)} with 1 entry:
  "ma" => click_left

julia> start(commands=commands)
[ Info: JustSayIt: I am initializing...
[ Info: Listening for commands in English (United States) (say "sleep JustSayIt" to put me to sleep; press CTRL+c to terminate)...
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
[ Info: Starting command: click_left
^C[ Info: Terminating JustSayIt...
[ Info: Stopped listening for commands.

julia> commands = Dict("help"      => Help.help,
                             "type"      => Keyboard.type,
                             "ma"        => Mouse.click_left,
                             "select"    => Mouse.press_left,
                             "okay"      => Mouse.release_left,
                             "middle"    => Mouse.click_middle,
                             "right"     => Mouse.click_right,
                             "double"    => Mouse.click_double,
                             "triple"    => Mouse.click_triple,
                             "copy"      => (Key.ctrl, 'c'),
                             "cut"       => (Key.ctrl, 'x'),
                             "paste"     => (Key.ctrl, 'v'),
                             "undo"      => (Key.ctrl, 'z'),
                             "redo"      => (Key.ctrl, Key.shift, 'z'),
                             "upwards"   => Key.page_up,
                             "downwards" => Key.page_down,
                             "take"      => [Mouse.click_double, (Key.ctrl, 'c')],
                             "replace"   => [Mouse.click_double, (Key.ctrl, 'v')],
                             );

julia> start(commands=commands)
[ Info: JustSayIt: I am initializing...
ERROR: ArgumentError: the command belonging to commmand name upwards is of an invalid type. Valid are functions (e.g., Keyboard.type), keys (e.g., Key.ctrl or 'f'), tuples of keys (e.g., (Key.ctrl, 'c') ) and arrays containing any combination of the afore noted.
Stacktrace:
 [1] init_jsi(commands::Dict{String, Any}, modeldirs::Dict{String, String}, noises::Dict{String, Vector{String}}; default_language::String, type_languages::Vector{String}, vosk_log_level::Int64)
   @ JustSayIt ~/tmpwdir/revision/JustSayIt.jl/src/init_jsi.jl:64
 [2] start(; default_language::String, type_languages::String, commands::Dict{String, Any}, subset::Nothing, max_speed_subset::Nothing, modeldirs::Nothing, noises::Dict{String, Vector{String}}, audio_input_cmd::Nothing)
   @ JustSayIt ~/tmpwdir/revision/JustSayIt.jl/src/start.jl:158
 [3] top-level scope
   @ REPL[6]:1

julia> _commands                                                                                           = Dict{String, Union{Array, Function}}()
Dict{String, Union{Function, Array}}()

julia> eltype(values(_commands))
Union{Function, Array}

julia> 

After fix:

julia> using JustSayIt
[ Info: Precompiling JustSayIt [d7252348-293e-4f11-8d42-c8418dda4315]

julia> commands = Dict(
                       "ma" => Mouse.click_left
                     )
Dict{String, typeof(JustSayIt.Mouse.click_left)} with 1 entry:
  "ma" => click_left

julia> start(commands=commands)
[ Info: JustSayIt: I am initializing...
[ Info: Listening for commands in English (United States) (say "sleep JustSayIt" to put me to sleep; press CTRL+c to terminate)...
[ Info: Starting command: click_left
[ Info: Starting command: click_left

^C[ Info: Terminating JustSayIt...
[ Info: Stopped listening for commands.
codecov-commenter commented 1 year ago

Codecov Report

Merging #89 (a7a2063) into main (b92dcc2) will decrease coverage by 1.60%. The diff coverage is 100.00%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
- Coverage   72.09%   70.49%   -1.60%     
==========================================
  Files          17       16       -1     
  Lines        1050     1044       -6     
==========================================
- Hits          757      736      -21     
- Misses        293      308      +15     
Impacted Files Coverage Δ
src/init_jsi.jl 64.39% <100.00%> (+0.27%) :arrow_up:

... and 3 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.