Skip to content

homophones

The community/core/homophones directory contains files that enable the selection of homophones (words that sound alike but have different spellings and meanings) using Talon. This functionality is triggered by voice commands and displays the options in a GUI.

Here's a breakdown of the key files:

  • homophones.talon: This file contains the Talon commands for interacting with the homophone functionality. It defines the following commands:

    • phones <user.homophones_canonical>: Shows the homophones for a word, using a list of canonical homophones defined in homophones.py.
    • phones that: Shows homophones for the currently selected word or the word under the cursor.
    • phones force <user.homophones_canonical>: Forces the homophone GUI to appear, even if a quick replacement would normally occur.
    • phones force: Forces the homophone GUI to appear for the current selection.
    • phones hide: Hides the homophone GUI.
    • phones word: Selects the current word and shows its homophones.
    • phones [<user.ordinals>] word left: Selects one or more words to the left and shows their homophones.
    • phones [<user.ordinals>] word right: Selects one or more words to the right and shows their homophones.
  • homophones_open.talon: This file defines actions to perform when the homophone GUI is open.

    • choose <user.formatters> <number_small>: Selects a homophone from the open GUI by number and inserts it into the text. This action is triggered by user.choose() (defined elsewhere, commonly in formatters.talon).
  • homophones.csv: This file contains the list of homophones. Each line represents a group of homophones, with words separated by commas. The first word in each line is considered the canonical word, which is used by the <user.homophones_canonical> list.

  • homophones.py: This Python file defines the logic behind the homophone functionality. It does the following:

    • Parses the homophones.csv file and creates a dictionary where keys are words and values are the list of their homophones. It updates this on every change to the file, allowing you to update homophones without restarting Talon.
    • Provides an imgui GUI for displaying homophone choices.
    • Handles the logic for showing and hiding the homophone GUI.
    • Implements quick replacement logic when a word has only one homophone, unless forced.
    • Provides actions for showing and selecting homophones.
    • It utilizes an imgui to generate the user interface.

These files work together to provide a comprehensive homophone selection system. The user triggers the functionality with voice commands from homophones.talon, which then calls functions in homophones.py to present the choices from homophones.csv in a GUI, which is then interacted with by the choose command from homophones_open.talon to make the selection.