KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Dictating number written out and in numerals
Topic Summary: Trick or macro for dictating a number written out, following by numeral in parens?
Created On: 04/15/2022 01:18 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Dictating number written out and in numerals   - G.J. Premo - 04/15/2022 01:18 PM  
 Dictating number written out and in numerals   - ax - 04/15/2022 01:55 PM  
 Dictating number written out and in numerals   - Alan Cantor - 04/15/2022 02:36 PM  
 Dictating number written out and in numerals   - G.J. Premo - 04/15/2022 09:57 PM  
 Dictating number written out and in numerals   - Alan Cantor - 04/15/2022 11:03 PM  
 Dictating number written out and in numerals   - ax - 04/15/2022 11:46 PM  
 Dictating number written out and in numerals   - Matt_Chambers - 04/16/2022 07:57 AM  
 Dictating number written out and in numerals   - ax - 04/17/2022 12:25 AM  
 Dictating number written out and in numerals   - ax - 04/17/2022 12:40 AM  
 Dictating number written out and in numerals   - Edgar - 04/17/2022 09:34 AM  
 Dictating number written out and in numerals   - ax - 04/17/2022 10:57 AM  
 Dictating number written out and in numerals   - PG LTU - 04/17/2022 04:05 PM  
 Dictating number written out and in numerals   - Alan Cantor - 04/17/2022 07:27 PM  
Keyword
 04/15/2022 01:18 PM
User is offline View Users Profile Print this message


G.J. Premo
Top-Tier Member

Posts: 826
Joined: 05/12/2007

Is there any trick or macro for dictating a number written out, following by numeral in parenthesis?

E.g:

Ten (10) days.

Could be either a DPI, Vocola or Autohotkey macro.

And if you've set DPI to dictate 1-9 written out, and over 9 as numerals, and don't want to change the default for over 9, is there a way to dictate numbers over 9 as written out in a particular case?

 

 04/15/2022 01:55 PM
User is offline View Users Profile Print this message

Author Icon
ax
Top-Tier Member

Posts: 397
Joined: 03/22/2012

 

I'm sure there are multiple ways to tackle this. But as the honchos have said over the years, the easiest, quickest, and most flexible method to accomplish this without creating untoward side effects elsewhere, is just to use the ubiquitous "spoken form".


I don't even have desktop Dragon.  I use the "super-cloud" embedded Dragon (more "cloud" than DMO/DPA ... essentially "all-cloud").  And I have access to "spoken form/written form" disguised under some other terminology.

If I want to say "query {sumthin}", by default embedded dragon will type out "?{sumthin}", which looks suboptimal to my eyes.  Therefore I've added a spoken form under "query with question mark {sumthin}", whereby the embedded dragon would spit out the written form "query (?) {sumthin}".

 

You could say something along the line of "Ten with ten" as spoken form, with "Ten (10)" as written form.  100% sure you could do that with DPI with super ease, even though I've never used DPI.



 04/15/2022 02:36 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4313
Joined: 12/08/2007

Try something like this. I've named this command "convert to words." Although I've made no effort to make it bulletproof, the script mostly works. There may be nasty side effects if the window you're dictating into, or the Recognition History window, loses focus while the macro is running.

How to use it:

1. Say a number.
2. After it hits the page, say the name of the command, e.g., "convert to words."

Say "450" --> 450
Say "convert to words" --> 450 (four hundred and fifty)

Sub Main
Dim engine As New DgnEngineControl, n As Long
engine.DlgShow(dgndlgRecognitionHistory, n,, 0)
Wait 0.5
SendSystemKeys "{Up}"
SendSystemKeys "{Alt+u}"
SendSystemKeys "{Ctrl+c}"
SendSystemKeys "{Esc}"
Let x = Clipboard
Let x = " (" & x & ")"
Wait 1.0
SendDragonKeys x

End Sub
 04/15/2022 09:57 PM
User is offline View Users Profile Print this message


G.J. Premo
Top-Tier Member

Posts: 826
Joined: 05/12/2007

Thank you, Alan.
Works so far.
Why does it show recognition history?
Is that necessary?
 04/15/2022 11:03 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4313
Joined: 12/08/2007

In the recognition history, numbers are always displayed in their written-out formats. So if you dictate the number "45", the recognition history window will show it as "forty five" -- regardless of what Dragon eventually outputs to the screen.

The macro opens the recognition history window so the last utterance, in its written-out form, can be copied to the clipboard.

A few months ago, I posed a question to this forum about the possibility of grabbing the most recent utterance programmatically, without the need to manipulate the user interface of the recognition history window. Doing it that way would be cleaner and more reliable. Nobody volunteered the answer. So perhaps the written-out form cannot be accessed directly, which means we are stuck with a slightly kludgy approach.
 04/15/2022 11:46 PM
User is offline View Users Profile Print this message

Author Icon
ax
Top-Tier Member

Posts: 397
Joined: 03/22/2012

Pardon me for being dippy in projecting my own work flow onto your question, G.J.  In my line of work, be it lesions, moles, lymph nodes, polyps ... I seldom deal with any integers greater than teens (other than lab values, which are always expressed in Arabic numerals).  For more arbitrary numeral-to-text conversion, written/spoken forms clearly can't be the ticket.

Out of curiosity Alan: when I dictate numbers such as "1450", I tend to speak either "one four five zero" or more likely "fourteen fifty".  Less often would I dictate the more formal-sounding "fourteen hundred and fifty".  Almost never the mouthful "one thousand four hundred and fifty".  If one dictates "fourteen fifty" under DPI, would it then record "fourteen hundred and fifty" in recognition history?  Or would it record "fourteen fifty" as has been spoken?



 04/16/2022 07:57 AM
User is offline View Users Profile Print this message

Author Icon
Matt_Chambers
Top-Tier Member

Posts: 569
Joined: 08/09/2018

PG LTU posted a great command to convert numbers into written out format. You could use that. It's here:

https://www.knowbrainer.com/forums/forum/messageview.cfm?catid=4&threadid=21365&highlight_key=y&keyword1=utilityprovider



 04/17/2022 12:25 AM
User is offline View Users Profile Print this message

Author Icon
ax
Top-Tier Member

Posts: 397
Joined: 03/22/2012

Good stuff, Matt!  It would hardly surprise anyone that PG the class valedictorian of Dragon School had turned in the home work back in 2015!

I also came across this VBA function "SpellNumber" from Microsoft.

However, might as well reinvent the wheel, for the following reasons:

1. Herr Professor Wilke won't let us graduate if we keep on cribbing off of the lead pupil.


2. Above routine handles up to millions.  Inflation has long busted through that ceiling.

3. I had a bit of time on my hands this afternoon riding the train.  Not really into sudoku (with or without a cigar).  Didn't feel like watching "shows".  The nerd in me chose homework!

4. Trying a different approach, I gave it a go with "sequential regular expressions".  Believe it or not, in this case RegEx is highly intuitive and scalable.  It can easily go to "Undecillion" (10E36) and up, although I don't think AHK can handle such integers.  Anyway, I stopped at 1 quintillion minus 1.

 

As PG would say, this is strictly for "entertainment", as it has zero utility in my own line of work.  Might have one-off use for accountants etc.

 

Following is a "spell number" AHK script primarily using RegEx.  Anything broken let me know.



 04/17/2022 12:40 AM
User is offline View Users Profile Print this message

Author Icon
ax
Top-Tier Member

Posts: 397
Joined: 03/22/2012

Num_string := " 999 999,990,909, 133,080 "


; ********** consolidate digits **********
Num_string := StrReplace(Num_string, ",", "")
Number := StrReplace(Num_string, A_space, "")


; ********** spell out "denominations" in logs of 3 **********
Num_text := Number // 10**15 . " quadrillion" . " " . mod(Number, 10**15)//10**12 . " trillion" . " " . mod(Number, 10**12)//10**9 . " billion" . " " . mod(Number, 10**9)//10**6 . " million" . " " . mod(Number, 10**6)//10**3 . " thousand" . " " . mod(Number, 10**3)


; ********** spell out hundreds **********
Num_text := RegExReplace(Num_text, "([1-9])([0])([0])", "$1 hundred")
Num_text := RegExReplace(Num_text, "([1-9])([0])([1-9])", "$1 hundred and $3")
Num_text := RegExReplace(Num_text, "([1-9])([1-9])([0-9])", "$1 hundred $2$3")


; ********** spell out double digits (down to tweens) **********
Num_text := RegExReplace(Num_text, "([9])([0-9])", "ninety-$2")
Num_text := RegExReplace(Num_text, "([8])([0-9])", "eighty-$2")
Num_text := RegExReplace(Num_text, "([7])([0-9])", "seventy-$2")
Num_text := RegExReplace(Num_text, "([6])([0-9])", "sixty-$2")
Num_text := RegExReplace(Num_text, "([5])([0-9])", "fifty-$2")
Num_text := RegExReplace(Num_text, "([4])([0-9])", "forty-$2")
Num_text := RegExReplace(Num_text, "([3])([0-9])", "thirty-$2")
Num_text := RegExReplace(Num_text, "([2])([0-9])", "twenty-$2")


; ********** spell out teens and single digits **********
Num_text := StrReplace(Num_text, "19", "nineteen")
Num_text := StrReplace(Num_text, "18", "eighteen")
Num_text := StrReplace(Num_text, "17", "seventeen")
Num_text := StrReplace(Num_text, "16", "sixteen")
Num_text := StrReplace(Num_text, "15", "fifteen")
Num_text := StrReplace(Num_text, "14", "fourteen")
Num_text := StrReplace(Num_text, "13", "thirteen")
Num_text := StrReplace(Num_text, "12", "twelve")
Num_text := StrReplace(Num_text, "11", "eleven")
Num_text := StrReplace(Num_text, "10", "ten")
Num_text := StrReplace(Num_text, "9", "nine")
Num_text := StrReplace(Num_text, "8", "eight")
Num_text := StrReplace(Num_text, "7", "seven")
Num_text := StrReplace(Num_text, "6", "six")
Num_text := StrReplace(Num_text, "5", "five")
Num_text := StrReplace(Num_text, "4", "four")
Num_text := StrReplace(Num_text, "3", "three")
Num_text := StrReplace(Num_text, "2", "two")
Num_text := StrReplace(Num_text, "1", "one")


; ********** clean up zeros and spaces **********
Num_text := StrReplace(Num_text, "-0", "")
Num_text := RegExReplace(Num_text, "([0] )(\w+\b)", "")
Num_text := trim(StrReplace(Num_text, "0", ""))
Num_text := RegExReplace(Num_text, "(\w*)([[:blank:]]+)(\w*)", "$1 $3")


MsgBox, %Num_text%



 04/17/2022 09:34 AM
User is offline View Users Profile Print this message

Author Icon
Edgar
Top-Tier Member

Posts: 1265
Joined: 04/03/2009

While I don't speak AutoHotKey, it looks like only a tiny modification would be necessary to accommodate negative numbers: look at first character to see if it is a hyphen, if so, strip it off and set a Boolean as true, else false; add one more statement just before the message box - conditionally prepend "negative " based on the Boolean.

-------------------------

-Edgar
DPI 15.3, 64-bit Windows 10 Pro, OpenOffice & Office 365, Norton Security, Shure X2U XLR to USB mic adapter with Audio Technica DB135 vocal mic, Asus X299-Deluxe Prime, Intel Core i9-7940X (14 core, 4.3 GHz overclocked to 4.9 GHz), G.SKILL TridentZ Series 64GB (4 x 16GB) DDR4 3333 (PC4 26600) F4-3333C16Q-64GTZ, NVIDIA GIGABYTE GeForce GTX 1060 GV-N1060G1 GAMING-6GD REV 2.0 6GB graphics card with 3 1920x1080 monitors

 04/17/2022 10:57 AM
User is offline View Users Profile Print this message

Author Icon
ax
Top-Tier Member

Posts: 397
Joined: 03/22/2012

Indeed Edgar, one advantage of PCRE style RegEx is that it is familiar to all programmers.  So it is in a way eminently "portable" on its own.  I am guessing it could be fairly straightforward to port the sequence to other languages that accommodate the PCRE style.

The other advantage of using RegEx, as you mentioned, is that it becomes trivial to customize certain things, such as negative signs, currency signs, or even decimals (in a textual sense).

 

I am fairly certain AHK (V1 or V2) still uses the older PCRE library, and not the newer PCRE2.  But for the dead simple sequential string formatting in the above example, I don't know if there'd be any difference.

One thing that's still controversial, I suppose, in numeral-to-text conversion is how and whether to use the conjunctive "and".  Americans (these days) are taught not to use it at all, I believe.  Not yet so in the UK.  I personally agree with striking a middle ground, being in Canada, by adding "and" when it's a "One Hundred and One Dalmatians" type of situation ...



 04/17/2022 04:05 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2202
Joined: 03/21/2007

+1 ax, move to the head of the class. Mine was a mere toy in comparison.

Btw, using vbs shell scripting to access RegEx, as I've shown can be done easily, one could easily turn that into a native Dragon Advanced Scripting (DAS) or possibly even a Dragon Voice Command (DVC) and open up this possibility to those who don't need to install AHK.



-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 04/17/2022 07:27 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4313
Joined: 12/08/2007

An impressive script, ax! Sometimes "reinventing the wheel" is a very useful and educational way to pass time.



Statistics
32305 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 0 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 474 guests browsing this forum, which makes a total of 474 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.