NSoiffer / MathCATForPython

A Python Interface and NVDA plugin to MathCAT
MIT License
7 stars 7 forks source link

Looking for an example #37

Closed tteodorescu0 closed 1 year ago

tteodorescu0 commented 2 years ago

Is there an example of how to use MathCAT in a Python program to convert a MathML expression to a speech string? I am looking for something I can adapt to test a large number of MathML expressions.

NSoiffer commented 2 years ago

First, set up your Rust environment if you haven't already. Look on the web for instructions.

Look at build-nvda-addon.sh to see how to grab the Rust library and how to rename it for python. It is set to build for 32 bit python for windows. If you want 64 bit and you are running on a 64 machine, just drop "--target ..." and it will be built for your local machine.

You can look at NVDA-addon/addon/globalPlugins/MathCAT/MathCAT.py for how it is used. The import is at the top of the file.

In particular, look at the class MathCAT towards the end. The init function has the SetRulesDir call which is required. It also has an example of how to set a preference, something you likely want to do. getSpeechForMathMl() shows how to get speech [I just saw I never removed 'mathcontent' which isn't really used anymore].

I hope that helps,

Neil

On Fri, May 13, 2022 at 1:33 PM tteodorescu0 @.***> wrote:

Is there an example of how to use MathCAT in a Python program to convert a MathML expression to a speech string? I am looking for something I can adapt to test a large number of MathML expressions.

— Reply to this email directly, view it on GitHub https://github.com/NSoiffer/MathCATForPython/issues/37, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALZM3DD5L6MKWMZNHJZCWTVJ24BDANCNFSM5V4NMQRQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

tteodorescu0 commented 2 years ago

Thank you for the instructions! How do I change the speech options? For example, to output regular text (no SSML); to apply the Fraction=FracOver preference; or to apply more than one preference in ClearSpeak? Here's what I have so far.

import libmathcat rules_dir = "C:\mathcat-python\Rules" libmathcat.SetRulesDir(rules_dir) libmathcat.SetPreference("TTS", "SSML") mathml ="x2" libmathcat.SetMathML(mathml) print(libmathcat.GetSpokenText()) ## prints "<say-as interpret-as='characters'>x over 2"

NSoiffer commented 2 years ago

Since you don't want SSML, libmathcat.SetPreference("TTS", "None")

Take a look at https://nsoiffer.github.io/MathCAT/users.html for user facing option settings. The ClearSpeak ones use an "_" to join the parts. E.g, "ClearSpeak_Fraction". At the moment, the interface only supports setting one option at a time (it remembers them, so you only need to do it during setup). I started to write a function that takes an array of values, but decided that it could get messy converting between various computer language interfaces, so I'm sticking to basic types for now.

See https://nsoiffer.github.io/MathCAT/callers.html for those options aimed at developers (e.g, TTS).

The MathML needs to be valid MathML. I assume "x2" isn't really the value you sent in. One of these days, I'll support ASCIIMath and some form of TeX as there are Rust implementations of these that produce MathML. Hopefully they work well...

Neil

On Fri, May 13, 2022 at 5:26 PM tteodorescu0 @.***> wrote:

Thank you for the instructions! How do I change the speech options? For example, to output regular text (no SSML); to apply the Fraction=FracOver preference; or to apply more than one preference in ClearSpeak? Here's what I have so far.

import libmathcat rules_dir = "C:\mathcat-python\Rules" libmathcat.SetRulesDir(rules_dir) libmathcat.SetPreference("TTS", "SSML") mathml ="x2" libmathcat.SetMathML(mathml) print(libmathcat.GetSpokenText()) ## prints "<say-as interpret-as='characters'>x over 2"

— Reply to this email directly, view it on GitHub https://github.com/NSoiffer/MathCATForPython/issues/37#issuecomment-1126591566, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALZM3DD7FC6TT3BSFPVLS3VJ3XKZANCNFSM5V4NMQRQ . You are receiving this because you commented.Message ID: @.***>

tteodorescu0 commented 2 years ago

Thank you. I was able to change the speech options. I'll run more tests next week. I am looking forward to your presentation on Tuesday at ETS.

NSoiffer commented 1 year ago

Closing since no activity in a long time.