Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage example fails due to incorrect type checks #87

Closed
pfitzseb opened this issue Jan 30, 2023 · 2 comments · Fixed by #89
Closed

Usage example fails due to incorrect type checks #87

pfitzseb opened this issue Jan 30, 2023 · 2 comments · Fixed by #89

Comments

@pfitzseb
Copy link

The example at https://omlins.github.io/JustSayIt.jl/stable/usage/ fails due to the types specified at

_commands = Dict{String, Union{Array, Union{Function, PyKey, NTuple{N,PyKey} where N}}}() # NOTE: specifying the exact Dict type of the commands leads to a crash that appears to be due to erronous compilation.
not including typeof(Key.ctrl) == PyObject.

Ref JuliaCon/proceedings-review#121.

@omlins
Copy link
Owner

omlins commented Feb 12, 2023

@pfitzseb : Thanks for noting that. Could you please point to the exact location of the example that fails? The link you posted goes to the beginning of the section...

@pfitzseb
Copy link
Author

This is super weird -- I can't repro this with the example on that page, but the following REPL session does consistently fail for me:

julia> using JustSayIt

julia> # time: 2023-01-30 12:12:50 CET
       # mode: julia
       using JustSayIt.API       # Import JustSayIt API to write @voicearg functions


julia> # time: 2023-01-30 12:12:52 CET
       # mode: julia
       using DefaultApplication  # To install type: `]` and then `add DefaultApplication`

julia> # time: 2023-01-30 12:12:52 CET
       # mode: julia
       # 1) Define a custom weather forecast search function.
       @doc """
           weather `today` | `tomorrow`

       Find out how the weather is `today` or `tomorrow`.
       """
       weather
weather

julia> # time: 2023-01-30 12:12:53 CET
       # mode: julia
       @enum Day today tomorrow

julia> # time: 2023-01-30 12:12:53 CET
       # mode: julia
       @voiceargs day=>(valid_input_auto=true) function weather(day::Day)
           DefaultApplication.open("https://www.google.com/search?q=weather+$day")
       end
weather (generic function with 2 methods)

julia> # time: 2023-01-30 12:12:55 CET
       # mode: julia
       # 2) Define command name to function mapping, calling custom function
       commands = Dict("help"      => Help.help,
                       "weather"   => weather,
                       );

julia> # time: 2023-01-30 12:12:59 CET
       # mode: julia
       # 3) Start JustSayIt with the custom commands.
       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: help
┌ Info: Command weather
│    =
│      weather `today` | `tomorrow`
│
└      Find out how the weather is today or tomorrow.
^C[ Info: Terminating JustSayIt...
[ Info: Stopped listening for commands.

julia> # time: 2023-01-30 12:18:55 CET
       # mode: julia
       commands = Dict(
         "ma" => Mouse.click_left
       )
Dict{String, typeof(JustSayIt.Mouse.click_left)} with 1 entry:
  "ma" => click_left

julia> # time: 2023-01-30 12:19:08 CET
       # mode: julia
       # 3) Start JustSayIt with the custom commands.
       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
^C[ Info: Terminating JustSayIt...
[ Info: Stopped listening for commands.

julia> # time: 2023-01-30 12:20:05 CET
       # mode: julia
       # 3) Start JustSayIt with the custom commands.
       start(;commands=commands, max_speed_subset=["ma"])
[ 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 (latency: 18 ms)
^C[ Info: Terminating JustSayIt...
[ Info: Stopped listening for commands.

julia> # time: 2023-01-30 12:23:06 CET
       # mode: 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> # time: 2023-01-30 12:23:07 CET
       # mode: julia
       start(commands=commands, max_speed_subset=["ma", "select", "okay", "middle", "right", "double", "triple", "copy", "upwards", "downwards", "take"])
[ 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 ~/.julia/packages/JustSayIt/IefnA/src/init_jsi.jl:64
 [2] start(; default_language::String, type_languages::String, commands::Dict{String, Any}, subset::Nothing, max_speed_subset::Vector{String}, modeldirs::Nothing, noises::Dict{String, Vector{String}}, audio_input_cmd::Nothing)
   @ JustSayIt ~/.julia/packages/JustSayIt/IefnA/src/start.jl:158
 [3] top-level scope
   @ REPL[15]:3

julia> commands["upwards"]
PyObject <Key.page_up: <65365>>

julia> Key.ctrl
PyObject <Key.ctrl: <65507>>

julia> Key.page_up
PyObject <Key.page_up: <65365>>

I can't repro the failure in a fresh session:

julia> using JustSayIt

julia> # time: 2023-01-30 12:23:06 CET
       # mode: 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> # time: 2023-01-30 12:23:07 CET
       # mode: julia
       start(commands=commands, max_speed_subset=["ma", "select", "okay", "middle", "right", "double", "triple", "copy", "upwards", "downwards", "take"])
[ 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: page_up (latency: 79 ms)
[ Info: Starting command: page_down (latency: 19 ms)

Don't currently have time to debug this further though, sorry.

@omlins omlins mentioned this issue Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants