Fractions

Forum for TextAloud version 3

Moderator: Jim Bretti

Post Reply
andergraph
Posts: 1
Joined: Fri Apr 10, 2015 7:49 pm
Contact:

Fractions

Post by andergraph »

I have everything pretty much set up for what I need. Can you provide a Regular Expression code for allowing TA to read fractions correctly? Such as 7/8, 1/2, 5/8.
Thanks
Jim Bretti
Posts: 1558
Joined: Wed Oct 29, 2003 11:07 am
Contact:

Re: Fractions

Post by Jim Bretti »

To really pronounce the fractions correctly I think you're going to need several regular expressions. Maybe someone else will have some better ideas, but here is what I'm thinking.

1/2, 1/3 and 2/3 would probably work best with one dictionary entry for each fraction. So for these you could use regular expressions or simple text matches, but here are regular expression:

\b1/2\b
one half

\b1/3\b
one third

\b2/3\b
two thirds

Now add another expression, after the above expressions, to handle all fractions of the form 1/n. Should be able to pronounce these as 1 nth, like this:

\b1/(\d{1,2})\b
1 $1th

At this point, if the numerator is > 1, the extra 's' makes things tricky. (2 5ths, 3 7ths, etc). In general I could not get a string like 2 5ths to be pronounced correctly. So I needed individual expressions to substitute the words fourths, fifths, sixths, and so on, like this:

\b([2-9])/4\b
$1 fourths

\b([2-9])/5\b
$1 fifths

So maybe start off with these, and experiment some. You may be able find a way to consolidate the fourths / fifths / sixths expressions. It may depend on the voice you're using as well.
Jim Bretti
NextUp.com
Quantum
Posts: 29
Joined: Tue Apr 07, 2015 2:05 pm
Contact:

Re: Fractions

Post by Quantum »

I normally pronounce fractions like n1/n2 as "n1 over n2"
For this a simple regex suffices :

regular expression (\d+)[/](\d+)
pronounce as $1 over $2

Hope this helps!

Quantum aka DaveH
Quantum aka DaveH
Post Reply