1
- # MathCAT add-on: generates speech, braille, and allows exploration of
2
- # expressions written in MathML
3
- # The goal of this add-on is to replicate/improve on the functionality of
4
- # MathPlayer which has been discontinued.
1
+ # MathCAT add-on: generates speech, braille, and allows exploration of expressions written in MathML
2
+ # The goal of this add-on is to replicate/improve on the functionality of MathPlayer which has been discontinued.
5
3
# Author: Neil Soiffer
6
- # Copyright: this file uses whatever GNU copyright that is
7
- # required for NVDA addons
8
- # The code additionally makes use of the MathCAT library (written in Rust)
9
- # which is covered by the MIT license
4
+ # Copyright: this file uses whatever GNU copyright that is required for NVDA addons
5
+ # The code additionally makes use of the MathCAT library (written in Rust) which is covered by the MIT license
10
6
# and also (obviously) requires external speech engines and braille drivers.
11
7
12
8
13
9
import os
10
+ import libmathcat
14
11
15
12
# import shutil
16
13
# if os.path.exists("libmathcat_py.pyd"):
17
14
# os.remove("libmathcat_py.pyd")
18
- # shutil.copy("..\\target\\i686-pc-windows-msvc\\release\\libmathcat_py.dll",
19
- # "libmathcat.pyd")
20
-
21
- import libmathcat
15
+ # shutil.copy("..\\target\\i686-pc-windows-msvc\\release\\libmathcat_py.dll", "libmathcat.pyd")
22
16
23
17
24
18
def SetMathCATPreferences ():
25
19
try :
26
20
libmathcat .SetRulesDir (
27
- # this assumes the Rules dir is in the same dir a the library.
28
- # Modify as needed
21
+ # this assumes the Rules dir is in the same dir a the library. Modify as needed
29
22
os .path .join (os .path .dirname (os .path .abspath (__file__ )), "Rules" )
30
23
)
31
24
except Exception as e :
32
- print (e , "problem with finding the MathCAT rules" )
25
+ print ("problem with finding the MathCAT rules" , e )
33
26
34
27
try :
35
28
libmathcat .SetPreference ("TTS" , "none" )
36
29
libmathcat .SetPreference ("Language" , "en" ) # Also "id" and "vi"
37
- libmathcat .SetPreference ("SpeechStyle" , "SimpleSpeak" ) # Also "ClearSpeak" # noqa
38
- libmathcat .SetPreference ("Verbosity" , "Verbose" ) # also terse "Terse"/"Medium" # noqa
30
+ libmathcat .SetPreference ("SpeechStyle" , "SimpleSpeak" ) # Also "ClearSpeak"
31
+ libmathcat .SetPreference ("Verbosity" , "Verbose" ) # also terse "Terse"/"Medium"
39
32
libmathcat .SetPreference (
40
33
"CapitalLetters_UseWord" , "true"
41
34
) # if "true", X => "cap x"
42
35
except Exception as e :
43
- print (e , "problem with setting a preference" )
36
+ print ("problem with setting a preference" , e )
44
37
45
38
46
39
def SetMathMLForMathCAT (mathml : str ):
47
40
try :
48
41
libmathcat .SetMathML (mathml )
49
42
except Exception as e :
50
- print (e , "problem with SetMathML" )
43
+ print ("problem with SetMathML" , e )
51
44
52
45
53
46
def GetSpeech ():
54
47
try :
55
48
return libmathcat .GetSpokenText ()
56
49
except Exception as e :
57
- return e , "problem with getting speech for MathML"
50
+ return "problem with getting speech for MathML" , e
58
51
59
52
60
53
SetMathCATPreferences () # you only need to this once
54
+
61
55
print ("Using MathCAT version '{}'" .format (libmathcat .GetVersion ()))
62
56
63
57
mathml = "<math><mfrac> <mn>1</mn> <mi>X</mi> </mfrac> </math>"
@@ -72,16 +66,15 @@ def GetSpeech():
72
66
SetMathMLForMathCAT (mathml )
73
67
print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
74
68
75
- mathml = "<math><msup intent='transpose:postfix($x)'> <mi arg='x'>x</mi><mi>T \
76
- </mi> </msup> </math>"
69
+ mathml = "<math><msup intent='transpose:postfix($x)'> <mi arg='x'>x</mi> <mi>T</mi> </msup> </math>"
77
70
SetMathMLForMathCAT (mathml )
78
71
print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
79
72
80
73
mathml = "<math><mrow intent='_(x, $op)'><mo arg='op'>!</mo></mrow></math>"
81
74
SetMathMLForMathCAT (mathml )
82
75
print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
83
76
84
- mathml = "<math intent=':structure'><mrow><mo>(</mo><mfrac linethickness='0'> \
85
- <mn arg='n'>7</mn><mn arg='m'>3</mn></mfrac><mo>)</mo></mrow></math>"
77
+ mathml = "<math intent=':structure'><mrow><mo>\
78
+ (</mo><mfrac linethickness='0'> <mn arg='n'>7</mn><mn arg='m'>3</mn></mfrac><mo>)</mo></mrow></math>"
86
79
SetMathMLForMathCAT (mathml )
87
80
print ("MathML: {}\n Speech (no inference): '{}'" .format (mathml , GetSpeech ()))
0 commit comments