Skip to content

Instantly share code, notes, and snippets.

@tararoys
Last active July 25, 2021 22:57

Revisions

  1. tararoys revised this gist Jul 25, 2021. 1 changed file with 80 additions and 21 deletions.
    101 changes: 80 additions & 21 deletions morse_code.py
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,27 @@
    from talon import Module, actions, noise
    from talon import Module, actions, noise, imgui, skia, canvas, cron
    from talon.types import Point2d

    import time

    noise_module = Module()

    #C:\\Users\\TalonBeginner\\AppData\\Roaming\\talon\\
    morse_tree_guide = skia.Image.from_file("user\\TarasMasterTalonRepo\\morse code keyboard\\1599px-Morse-code-tree.png")


    morse_canvas = None


    global last_activity_at
    global history

    hiss_start_time = 0
    hiss_end_time = 0

    max_dot_time = 0.3

    history = []

    morse = {
    "dot": "e",
    "dot dot": "i",
    @@ -46,48 +62,75 @@

    }

    def maybe_insert():
    global history
    letter = history

    print( "last activity" + str(time.monotonic() - last_activity_at))
    if(time.monotonic() - last_activity_at) >= 2:


    hiss_start_time = 0
    hiss_end_time = 0

    max_dot_time = 0.3

    history = []

    @noise_module.action_class
    class NoiseActions:
    def noise_pop():
    """Invoked when the user does the pop noise."""
    global history
    letter = history
    history = []
    print(history)
    try:
    letter=morse[" ".join(letter)]
    print(letter)
    actions.insert(letter)
    history = []
    except:
    print("no letter")
    return "no letter"
    history = []
    #return "no letter"
    else:
    print("no letter")
    return "no letter"
    history= []
    #return "no letter"

    def morse_canvas_draw(canvas):

    canvas.draw_image(morse_tree_guide, 500, 0)
    canvas.draw_points(canvas.PointMode.POLYGON,
    [Point2d(0, 0),
    Point2d(10, 10),
    Point2d(-10, -10),
    Point2d(10, -10),
    Point2d(-10, 10)])





    @imgui.open(y=0)
    def gui(gui: imgui.GUI):
    global history
    gui.text("Morse History")
    gui.line()
    try:
    gui.text(morse[" ".join(history)])
    except:
    gui.text("not a letter")

    gui.text(" ".join(history))



    @noise_module.action_class
    class NoiseActions:
    def noise_pop():
    """Invoked when the user does the pop noise."""
    print("I'm a pop star.")


    def noise_hiss_start():
    """Invoked when the user starts hissing (potentially while speaking)"""
    global hiss_start_time
    hiss_start_time = time.time()
    hiss_start_time = time.monotonic()
    pass

    def noise_hiss_stop():
    """Invoked when the user finishes hissing (potentially while speaking)"""
    global hiss_start_time
    global hiss_end_time
    hiss_end_time = time.time()
    hiss_end_time = time.monotonic()
    global last_activity_at
    last_activity_at= time.monotonic()

    hiss_length_in_seconds = hiss_end_time - hiss_start_time
    print (hiss_length_in_seconds.__class__)
    @@ -98,8 +141,24 @@ def noise_hiss_stop():
    else:
    history.append("dash")
    print(history)
    cron.after("2000ms", maybe_insert)
    pass

    def morse_history_toggle():
    """Toggles viewing the morse_history"""
    global morse_canvas
    if morse_canvas is None:
    morse_canvas = canvas.Canvas(500, 0, 1599, 1000)

    if gui.showing:
    morse_canvas.unregister("draw", morse_canvas_draw)
    morse_canvas.hide()
    gui.hide()
    else:
    morse_canvas.register("draw", morse_canvas_draw)
    morse_canvas.show()
    gui.show()


    def pop_handler(blah):
    actions.user.noise_pop()
  2. tararoys revised this gist Jul 25, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions morse.talon
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # short hiss to make a dot, long hiss to make a dash, pop to interpret the latest sequence of dots and dashes and type it as a letter.

    morse history: user.morse_history_toggle()
  3. tararoys renamed this gist Jul 25, 2021. 1 changed file with 0 additions and 0 deletions.
  4. tararoys renamed this gist Jul 25, 2021. 1 changed file with 0 additions and 0 deletions.
  5. tararoys revised this gist Jul 25, 2021. 1 changed file with 5682 additions and 0 deletions.
    5,682 changes: 5,682 additions & 0 deletions 1599px-Morse-code-tree.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  6. tararoys created this gist Mar 28, 2021.
    114 changes: 114 additions & 0 deletions morse_code.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,114 @@
    from talon import Module, actions, noise

    import time

    noise_module = Module()

    global history

    morse = {
    "dot": "e",
    "dot dot": "i",
    "dot dot dot": "s",
    "dot dot dot dot": "h",
    "dot dot dot dot dot": "5",
    "dot dot dot dot dash": "4",
    "dot dot dot dash":"v",
    "dot dot dot dash dash":"3",
    "dot dot dash:":"u",
    "dot dot dash dot": "f",
    "dot dot dash dash dash": "2",
    "dot dash": "a",
    "dot dash dot":"r",
    "dot dash dot dot": "l",
    "dot dash dash": "w",
    "dot dash dash dot": "p",
    "dot dash dash dash": "j",
    "dot dash dash dash dash": "1",
    "dash": "t",
    "dash dot": "n",
    "dash dot dot": "d",
    "dash dot dot dot": "b",
    "dash dot dot dot dot": ".",
    "dash dot dot dot dash": "=",
    "dash dot dot dash": "x",
    "dash dot dash": "k",
    "dash dot dash dot": "c",
    "dash dot dash dash": "y",
    "dash dash": "m",
    "dash dash dot": "g",
    "dash dash dot dot": "z",
    "dash dash dot dash": "q",
    "dash dash dash": "o",
    "dash dash dash dot dot": "8",
    "dash dash das dash dot": "9",
    "dash dash dash dash dash": "0"

    }




    hiss_start_time = 0
    hiss_end_time = 0

    max_dot_time = 0.3

    history = []

    @noise_module.action_class
    class NoiseActions:
    def noise_pop():
    """Invoked when the user does the pop noise."""
    global history
    letter = history
    history = []
    print(history)
    try:
    letter=morse[" ".join(letter)]
    print(letter)
    actions.insert(letter)
    except:
    print("no letter")
    return "no letter"
    else:
    print("no letter")
    return "no letter"



    def noise_hiss_start():
    """Invoked when the user starts hissing (potentially while speaking)"""
    global hiss_start_time
    hiss_start_time = time.time()
    pass

    def noise_hiss_stop():
    """Invoked when the user finishes hissing (potentially while speaking)"""
    global hiss_start_time
    global hiss_end_time
    hiss_end_time = time.time()

    hiss_length_in_seconds = hiss_end_time - hiss_start_time
    print (hiss_length_in_seconds.__class__)
    print("- sssss length of hiss:" + str(hiss_length_in_seconds))

    if hiss_length_in_seconds < max_dot_time:
    history.append("dot")
    else:
    history.append("dash")
    print(history)
    pass


    def pop_handler(blah):
    actions.user.noise_pop()

    def hiss_handler(active):
    if active:
    actions.user.noise_hiss_start()
    else:
    actions.user.noise_hiss_stop()

    noise.register("pop", pop_handler)
    noise.register("hiss", hiss_handler)