KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: sharing a macro to add a new word from correction dialog
Topic Summary:
Created On: 09/01/2020 10:15 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 sharing a macro to add a new word from correction dialog   - dicdoc - 09/01/2020 10:15 PM  
 sharing a macro to add a new word from correction dialog   - kkkwj - 09/02/2020 04:55 PM  
 sharing a macro to add a new word from correction dialog   - dicdoc - 09/02/2020 05:37 PM  
 sharing a macro to add a new word from correction dialog   - glennizen - 09/30/2020 05:11 PM  
 sharing a macro to add a new word from correction dialog   - nerdfrastanz - 09/03/2020 09:03 AM  
 sharing a macro to add a new word from correction dialog   - PG LTU - 10/01/2020 12:53 AM  
 sharing a macro to add a new word from correction dialog   - kkkwj - 10/01/2020 12:57 AM  
Keyword
 09/01/2020 10:15 PM
User is offline View Users Profile Print this message

Author Icon
dicdoc
Top-Tier Member

Posts: 268
Joined: 07/31/2014

Sometimes, "correct this" provides only a partially correct choice. When correct choice or expression, manually corrected is not in vocabulary, I find it usefull to validate correction in text from correction dialog and add the new expression, via 1 voice command. The one above adds the possibility to cancel the automatic addition to new word dialog during a parametrable time frame (TimoutSeconds  :

===

Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long

 

Function ActiveWindowTitle() As String

' based on a script from the KnowBrainer Forum by Fmen

   Dim titleLength As Integer

   Dim title As String * 300

   Dim foregroundWindow As Long

   foregroundWindow = GetForegroundWindow()

   titleLength = GetWindowText (foregroundWindow, title, Len(title))

   title = Left(title, titleLength)

   title = Trim (title)

   ActiveWindowTitle = title

End Function

 

Function WaitForDialog()

' based on a script from the KnowBrainer Forum by monkey8 (Lindsay)

   Dim handle As Long

   handle = GetForegroundWindow 'gets the window handle of the current window

   Do While GetForegroundwindow = handle

      Wait 0.05 'the wait command frees up the CPU to do other work, must be present

      'when the word document loads foreground window handle will change and the loop will exit

   Loop

End Function

 

Function CustomMsgBox(title As String, message As String, TimoutSeconds As double) As String

 

    ' SET OPTION FOR DIALOG BOX

    Dim opt As Integer

    opt = 0

    opt = opt + 64 'to display information icon

    opt = opt + 1 'To have OK and Cancel button

    'more option: https://docs.microsoft.com/en-us/previous-versions/tn-archive/ee156593(v=technet.10)?redirectedfrom=MSDN

 

    ' LAUNCH DIALOG BOX

    Dim objShell

    Set objShell = CreateObject("WScript.Shell")

 

    Dim proc

    Dim cmdLine As String

    cmdLine= "CreateObject(""""WScript.Shell"""").Popup(""""" & message &"""""," & TimoutSeconds & ",""""" & title & """""," & opt & ")"

    Set proc = objShell.Exec("mshta.exe vbscript:Execute(""Dim i: i=" & cmdLine & ": CreateObject(""""Scripting.FileSystemObject"""").GetStandardStream(1).WriteLine i:window.close "")")

    iRetVal=proc.StdOut.ReadAll()

 

    ' RETURN INFO ON CLICKED BUTTON

 

    'OK => 1, Cancel => 2, No Action => -1

    Select Case iRetVal

        Case Is = 1

            CustomMsgBox = "OK"

        Case Is = 2

            CustomMsgBox = "ESC"

        Case Else

            ' No button clicked => go by defaut

            CustomMsgBox = "OK"

    End Select

 

End Function

Sub Main

 ' This macro adds selection to vocabulary

 ' the word or phrase must be selected before invoking this command

 ' Needs Ref Dragon Naturally Speaking Active X control

 ' it differentiates spelling windows and other windows

 

Dim n as Integer, Clip, ClipTemp as string

Dim res, Title, message as String, TimoutSeconds as Double

Dim engine As New DgnEngineControl

Dim mic As New DgnMicBtn

 

ClipTemp = Clipboard

 

 

 

mic.Register

mic.MicState = dgnmicSleeping

mic.UnRegister

 

'MsgBox (CSTR(ActiveWindowTitle))

'Stop

 

If InStr (CSTR(ActiveWindowTitle), "Fenêtre d'épellation") Then ' spelling window

  '

  '

  SendKeys "^a^c{Enter}", 1

 

  'Is the engine is ready to show the dialog ?

  ' AddWordDialog

  engine.Register

  If engine.DlgStatusGet(DgnDialogConstants.dgndlgAddWord) = DgnDlgStatusConstants.dgndlgstatusOK Then

      engine.DlgShow(DgnDialogConstants.dgndlgAddWord, n, , 0)'

  End If

  WaitForDialog

  SendKeys "^v", 1

 

 

  GoTo FinCommune:

End If

 

If NOT InStr (CSTR(ActiveWindowTitle), "Fenêtre d'épellation") Then

 SendKeys "^c", 1 ' Copy to clipboard

 Wait 0.3

 

 Clip = Clipboard

 ' Clean up selected text...

 Clip = Replace(Clip, Chr$(9), "") ' Delete "Tab"

 Clip = Replace(Clip, Chr$(10), "") ' Delete "Enter" vbLf Chr(10) Linefeed character

 Clip = Replace(Clip, Chr$(11), "") ' Delete vbVerticalTab Chr(11) Word VBA Manual - manual line break (Shift + Enter)

 Clip = Replace(Clip, Chr$(13), "") ' Delete vbCr Chr(13) Carriage return character

 Clip = Replace(Clip, "  ", " ") ' Replace double space with single space

 Clip = Trim (Clip) ' Get rid of leading and trailing white spaces

 

 

 ' Clean up selected text...

 

 If Len(Clip) = 0 Then ' If no teClipt is selected, start "Add Word" dialog and stop

  engine.Register

  If engine.DlgStatusGet(DgnDialogConstants.dgndlgAddWord) = DgnDlgStatusConstants.dgndlgstatusOK Then

      engine.DlgShow(DgnDialogConstants.dgndlgAddWord, n, , 0)'

  End If

 ElseIf Len(Clip) <> 0 Then

  SendKeys "{Right}", 1 ' Deselect the word or phrase

  engine.Register

  If engine.DlgStatusGet(DgnDialogConstants.dgndlgAddWord) = DgnDlgStatusConstants.dgndlgstatusOK Then

      engine.DlgShow(DgnDialogConstants.dgndlgAddWord, n, , 0)'

  End If

  Clipboard Clip

  Wait .3

   WaitForDialog

  SendKeys "^v", True

 End If

 

End If

 

FinCommune:

 

TimoutSeconds = 1.4

Title = "Cette boite disparaîtra dans " & TimoutSeconds & " secondes"

Message = "Appuyez sur 'esc' si vous voulez modifier le nouveau mot"

res = CustomMsgBox(Title, Message, TimoutSeconds)

 

If res = "OK" Then

 SendKeys "{enter}", 1

 wait .1

 SendKeys "{esc}", 1

 

 GoTo TouteFin

Else

 

End If

 

TouteFin:

engine.UnRegister(False)

Set engine = Nothing

 

mic.Register

mic.MicState = dgnmicOn

mic.UnRegister

 

Clipboard ClipTemp

 

End Sub



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

Memory: 16GB Microphone Brand and Model: LFH 4000 & Flexy Mike  Operating System: win 10, latest update; Surface Book 2, Processor (CPU) Type & Speed: I7 8650 Soundcard Brand and Model: none Speech Software: Dragon Medical Practice Edition, french version: 4.2 Using KnowBrainer?:Yes

 09/02/2020 04:55 PM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 497
Joined: 11/05/2015

Thank you for the script, but it's long enough to be not understandable. Just a thought, but maybe posting a short video on how to use it would probably be helpful to people. (I know it all takes more time... :-))

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

Win10/x64, AMD Ryzen 7 3700X, 64GB RAM, Dragon 15.3, SP 6 PRO, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Klim and JUKSTG earbuds with microphones

 09/02/2020 05:37 PM
User is offline View Users Profile Print this message

Author Icon
dicdoc
Top-Tier Member

Posts: 268
Joined: 07/31/2014

Like this ? https://www.youtube.com/watch?v=KVAjWIjzcO4

 

The selection of word "décès" was made using the other macro I shared.

WHen the final correction was made (décès ==> essai), the macro aplied the correction to the text and used the new expression in the vocabulary dialog, recorded it automatically with a time out window leting press escape in case the new word had to be modified before being added to the vocabulary



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

Memory: 16GB Microphone Brand and Model: LFH 4000 & Flexy Mike  Operating System: win 10, latest update; Surface Book 2, Processor (CPU) Type & Speed: I7 8650 Soundcard Brand and Model: none Speech Software: Dragon Medical Practice Edition, french version: 4.2 Using KnowBrainer?:Yes



 09/30/2020 05:11 PM
User is offline View Users Profile Print this message

Author Icon
glennizen
Power Member

Posts: 59
Joined: 12/16/2014

Well done. Thank you



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

Clinical software support professional

 09/03/2020 09:03 AM
User is offline View Users Profile Print this message

Author Icon
nerdfrastanz
New Member

Posts: 7
Joined: 09/03/2020

Thanks for the video. It wasn't easy to figure everything out, especially since your pc is in french, but i think in the end i got it hahaah
 10/01/2020 12:53 AM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2077
Joined: 03/21/2007

+1 thx

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




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.

 10/01/2020 12:57 AM
User is offline View Users Profile Print this message

Author Icon
kkkwj
Top-Tier Member

Posts: 497
Joined: 11/05/2015

Yes, thank you for posting all your work. I thought the WaitForDialog script was clever!

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

Win10/x64, AMD Ryzen 7 3700X, 64GB RAM, Dragon 15.3, SP 6 PRO, SpeechStart, Office 365, KB 2017, Dragon Capture, Samson Meteor USB Desk Mic, Klim and JUKSTG earbuds with microphones

Statistics
31795 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 567 guests browsing this forum, which makes a total of 568 users using this forum.

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