summaryrefslogtreecommitdiff
path: root/codespeak
blob: 5d5c6c7b11d092e9675864789ef7b1671c195e37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3

import argparse
import subprocess
import sys

old_names = {
    "ace": " ",
    "gal": "<",
    "pel": "(",
    "bar": "|",
    "gap": "\n",
    "gap": "\t",
    "gap": "  ",
    "per": ")",
    "bas": "\\",
    "gar": ">",
    "sel": "[",
    "buc": "$",
    "hax": "#",
    "sem": ";",
    "cab": "_",
    "hep": "-",
    "ser": "]",
    "cen": "%",
    "kel": "{",
    "soq": "'",
    "col": ":",
    "ker": "}",
    "tar": "*",
    "com": ",",
    "ket": "^",
    "tec": "`",
    "doq": "\"",
    "lus": "+",
    "tis": "=",
    "dot": ".",
    "pam": "&",
    "wut": "?",
    "fas": "/",
    "pat": "@",
    "sig": "~",
    "zap": "!",
}

old_syms = {v: k for k, v in old_names.items()}

new_names = {
  'ace': ' ',
  'ban': '>',
  'bar': '|',
  'bat': '\\',
  'bus': '$',
  'cab': '_',
  'cen': '%',
  'col': ':',
  'com': ',',
  'dot': '.',
  'gap': '\n',
  'gap': '  ',
  'gap': '\t',
  'hax': '#',
  'hep': '-',
  'ket': '^',
  'lac': '[',
  'led': '<',
  'lit': '(',
  'lob': '{',
  'lus': '+',
  'mic': ';',
  'net': '/',
  'pad': '&',
  'pat': '@',
  'rac': ']',
  'rit': ')',
  'rob': '}',
  'say': '\'',
  'sig': '~',
  'tar': '*',
  'tec': '\`',
  'tis': '=',
  'wut': '?',
  'yel': '"',
  'zap': '!',
  }

# reverse the above key/vals
new_syms = {v: k for k, v in new_names.items()}

if sys.platform != 'darwin':
    print("sorry, only works on mac")
    sys.exit(1)

def translate(table, string):
    words = []
    for i, c in enumerate(string):
        if c == ' ' and string[i+1] == ' ':
            # we're looking at two spaces, a gap
            words.append('gap')
            continue
        elif c == ' ' and string[i-1] == ' ':
            # we just saw a gap, keep going
            pass
        elif c in table:
            words.append(table[c])
        else:
            words.append(c)
    return ' '.join(words)



parser = argparse.ArgumentParser()
parser.add_argument('-t', '--table', default='new',
        help="table of symbols to use, either 'old' or 'new'")
parser.add_argument('-f', '--file', help="file to read", default=None)
parser.add_argument('-c', '--code', default=None,
    help='string of hoon code in lieu of --file')

args = parser.parse_args()

if args.table == 'old':
    selected_table = old_syms
else:
    selected_table = new_syms

if args.code is None:
    with open(args.file) as f:
        content = f.read()
        words = translate(selected_table, content)
        subprocess.run(["say", words])
else:
    words = translate(selected_table, args.code)
    subprocess.run(["say", words])