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.
53# 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
106# and also (obviously) requires external speech engines and braille drivers.
117
128
139import os
10+ import libmathcat
1411
1512# import shutil
1613# if os.path.exists("libmathcat_py.pyd"):
1714# 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")
2216
2317
2418def SetMathCATPreferences ():
2519 try :
2620 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
2922 os .path .join (os .path .dirname (os .path .abspath (__file__ )), "Rules" )
3023 )
3124 except Exception as e :
32- print (e , "problem with finding the MathCAT rules" )
25+ print ("problem with finding the MathCAT rules" , e )
3326
3427 try :
3528 libmathcat .SetPreference ("TTS" , "none" )
3629 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"
3932 libmathcat .SetPreference (
4033 "CapitalLetters_UseWord" , "true"
4134 ) # if "true", X => "cap x"
4235 except Exception as e :
43- print (e , "problem with setting a preference" )
36+ print ("problem with setting a preference" , e )
4437
4538
4639def SetMathMLForMathCAT (mathml : str ):
4740 try :
4841 libmathcat .SetMathML (mathml )
4942 except Exception as e :
50- print (e , "problem with SetMathML" )
43+ print ("problem with SetMathML" , e )
5144
5245
5346def GetSpeech ():
5447 try :
5548 return libmathcat .GetSpokenText ()
5649 except Exception as e :
57- return e , "problem with getting speech for MathML"
50+ return "problem with getting speech for MathML" , e
5851
5952
6053SetMathCATPreferences () # you only need to this once
54+
6155print ("Using MathCAT version '{}'" .format (libmathcat .GetVersion ()))
6256
6357mathml = "<math><mfrac> <mn>1</mn> <mi>X</mi> </mfrac> </math>"
@@ -72,16 +66,15 @@ def GetSpeech():
7266SetMathMLForMathCAT (mathml )
7367print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
7468
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>"
7770SetMathMLForMathCAT (mathml )
7871print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
7972
8073mathml = "<math><mrow intent='_(x, $op)'><mo arg='op'>!</mo></mrow></math>"
8174SetMathMLForMathCAT (mathml )
8275print ("MathML: {}\n Speech: '{}'" .format (mathml , GetSpeech ()))
8376
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>"
8679SetMathMLForMathCAT (mathml )
8780print ("MathML: {}\n Speech (no inference): '{}'" .format (mathml , GetSpeech ()))
0 commit comments