KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Script to convert numbers into their written form
Topic Summary:
Created On: 11/10/2021 05:14 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 Script to convert numbers into their written form   - Alan Cantor - 11/10/2021 05:14 PM  
 Script to convert numbers into their written form   - PG LTU - 11/11/2021 10:50 AM  
 Script to convert numbers into their written form   - Alan Cantor - 11/11/2021 01:08 PM  
 Script to convert numbers into their written form   - kkkwj - 11/13/2021 01:44 AM  
 Script to convert numbers into their written form   - Alan Cantor - 11/14/2021 11:13 AM  
Keyword
 11/10/2021 05:14 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4280
Joined: 12/08/2007

I'm working with somebody who needs to express dollar amounts both as numbers, and as the words spelled out. For example:

 

$123,456 (one hundred and twenty three thousand four hundred fifty six dollars)

 

I've written a script that works by retrieving the spelled out version from the Recognition History. So to make it work, you say the dollar amount, pause, and then invoke the following command. The command calls up the Recognition History, navigates to the list of utterances, copies the value to the clipboard, closes the recognition history dialog, does some string manipulation, and then outputs the spelled out version.

 

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.3
    SendDragonKeys x

End Sub

Does anybody know of a way to directly retrieve the value of the last utterance without invoking the Recognition History dialog box, navigating from field to field, using the clipboard, and so on?

 11/11/2021 10:50 AM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2197
Joined: 03/21/2007

This keeps coming up . . .
At any rate, using the Recognition History to pull the last utterance has been done and dusted a few times here on this forum (including by you, Alan, haha!) and for numbers spelled out as words, the result is sort of incomplete. Look at here e.g.



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




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.



 11/11/2021 01:08 PM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4280
Joined: 12/08/2007

Thanks for unearthing that ancient thread, Philip. Indeed, interest in the question is longstanding, and so far, there does not appear to be a bulletproof solution.

I was hoping someone may know a programmatic way to get the information without invoking the Recognition History, and especially, without using the clipboard. Scripting clipboard operations under Windows 10 is not overly reliable. Peppering a script with long pauses helps, but not always.

Here's the latest version, which I'm finding more intuitive to use.

"Convert <dictation>"


Sub Main
' "Convert <dictation>"

' Takes a price as input, e.g., "$450", and outputs it thus:

' $450 (four hundred and fifty dollars)

Dim ConvertedValue As String
Dim engine As New DgnEngineControl, n As Long

engine.DlgShow(dgndlgRecognitionHistory, n,, 0)
Wait 0.5

SendSystemKeys "{Alt+u}"
SendSystemKeys "{Ctrl+c}"
Wait 0.5 ' Delay needed: clipboard operations are slow in Win 10!
SendSystemKeys "{Esc}"

Let ConvertedValue = Clipboard
Wait 0.5 ' Delay needed: clipboard operations are slow in Win 10!

Let ConvertedValue = Replace(ConvertedValue, "Convert ", "")
Let ConvertedValue = " (" & ConvertedValue & ")"

SendDragonKeys " " & ListVar1 & ConvertedValue

End Sub



 11/13/2021 01:44 AM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 865
Joined: 11/05/2015

This may or may not help, but there are MUCH longer and more complex scripts that convert numbers to words and words to numbers on the net. I don't recall ever seeing one in Basic, though. And it's probably much more work than it's worth to get it running and debugged when you have scripts like the ones above that work most of the time. Just a thought.

 

I take it back about never having seen a big script in Basic - PG just posted a link to his version from long ago!



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

Win10/11/x64, AMD Ryzen 7 3700X/3950X, 64/128GB RAM, Dragon 15.3, SP 7 Standard, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Amazon YUWAKAYI headset, Klim and JUKSTG earbuds with microphones, 3 BenQ 2560x1440 monitors, Microsoft Sculpt Keyboard and fat mouse



 11/14/2021 11:13 AM
User is offline View Users Profile Print this message


Alan Cantor
Top-Tier Member

Posts: 4280
Joined: 12/08/2007


And it's probably much more work than it's worth to get it running and debugged when you have scripts like the ones above that work most of the time. Just a thought.


A very good thought! Although none of the scripts are perfect, they usually work well enough.

On the other hand, I can see myself putting in the time, as Philip has done, to craft a home-brew digit-to-word translator. A fun project for a rainy day.

Here is the latest version of my script, which runs a little faster and is less "flashy."

Sub Main
' "Convert <dictation>"

' This script takes a price as input, e.g., "$450", and outputs it thus:
' $450 (four hundred and fifty dollars)

Dim engine As New DgnEngineControl, n As Long
engine.DlgShow(dgndlgRecognitionHistory, n,, 0) ' Invoke "Recognition History" dialog

Wait 0.25 ' Wait for "Recognition History" to gain focus

SendSystemKeys "{Alt+u}{Ctrl+c}{Esc}" ' Copy utterance, close window

Wait 0.5 ' Clipboard operations are slow in Win 10!

Clipboard " " & ListVar1 & " (" & Replace(Clipboard, "Convert ", "") & ")"

SendSystemKeys "{Ctrl+v}"

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

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