KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: Sharing 1st version of a voice timer for measuring duration of daily tasks
Topic Summary:
Created On: 09/07/2020 05:53 AM
Status: Post and Reply
Linear : Threading : Single : Branch
Keyword
 09/07/2020 05:53 AM
User is offline View Users Profile Print this message

Author Icon
dicdoc
Top-Tier Member

Posts: 268
Joined: 07/31/2014

Lately, I wanted to be able to measur how much time took me certains complex set of actions at work, since I 've been operationalising certain taks with macro. SO I came out with this 1st version of a voice timer. 

-> "Chrono début" starts timer

you can do whatever you need to do

-> "Chrono fin" ends timer and displays duration in a message box

I might try to include a "pause" command in the future, for instance if I got an interruption during the task, but I dont need it urgently, so I'll wait. If anyone has an idea, he/she can complete or develop the following :

========= chrono <ChronDebPsReprFin>

<ChronDebPsReprFin>:

début

pause

reprise

fin

========== macro
    Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
    Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long

Public Const tempDir = "C:\Temp\"
Public Const TempTimerFile = "TempTimer.csv"

Sub Main
    Dim curFrequency As Currency
    Dim curStartPerformanceCounter As Currency
    Dim curEndPerformanceCounter As Currency

    Dim AdjustedcurStartPerformanceCounter As Currency
    Dim AdjustedcurEndPerformanceCounter As Currency
    Dim lgResult As Long
    Dim Step as Integer
    Dim duration_in_seconds, heures, minutes, secondes as Double

'======================= Prep work with Timer on temp file
Dim oFileMode As Object
Dim fsm As Object

'======================= End work with Timer on temp file

'======================= frequency
    curFrequency = QueryPerformanceFrequency(curFrequency)

    'MsgBox("Frequency: " & QueryPerformanceFrequency(curFrequency))

    'obtain no: of counts per second
    lgResult = QueryPerformanceFrequency(curFrequency) ' (curFrequency)

    If lgResult > 0 Then
'        MsgBox("Frequency: " & curFrequency)
    End If
'=========================




'======================== curStartPerformanceCounter
If ListVar1 = "début" then
    'measure start count

    lgResult = QueryPerformanceCounter(curStartPerformanceCounter)
    AdjustedcurStartPerformanceCounter = curStartPerformanceCounter/curFrequency

    If lgResult > 0 Then

    TimoutSeconds = 1.6
    Title = "Ce message de " & TimoutSeconds & " secondes n'influence pas la durée du chrono"
    Message = "Le chrono a débuté. Dites 'chrono fin' pour l'arrêter"
    res = TimedOutMsgBox(Title, Message, TimoutSeconds)

'        MsgBox ("Start Count: " & curStartPerformanceCounter & "; " & AdjustedcurStartPerformanceCounter)

    '======================= Start record timer start value on temp file
        Set fsm = CreateObject("Scripting.FileSystemObject")
        Set oFileMode = fsm.CreateTextFile(tempDir & TempTimerFile)

        oFileMode.WriteLine "Timer_Value"
        oFileMode.WriteLine AdjustedcurStartPerformanceCounter
        oFileMode.Close
    '======================= End timer start value on temp file
    End If
End If
'==========================



'========================== curEndPerformanceCounter
If ListVar1 = "fin" then
    'measure end count

    lgResult = QueryPerformanceCounter(curEndPerformanceCounter)
    AdjustedcurEndPerformanceCounter = curEndPerformanceCounter/curFrequency

    If lgResult > 0 Then
'        MsgBox( "End Count: " & curEndPerformanceCounter & "; " & AdjustedcurEndPerformanceCounter)
    End If
   '======================= Start read windows mode on temp file
       Set fsm = CreateObject("Scripting.FileSystemObject")
       Set oFileMode = fsm.OpenTextFile(tempDir & TempTimerFile)

       'ignore the first line
       oFileMode.ReadLine
       AdjustedcurStartPerformanceCounter  = CCur(oFileMode.ReadLine)
'       MsgBox("" & AdjustedcurStartPerformanceCounter & "")
       oFileMode.Close
   '======================= End read windows mode on temp file

duration_in_seconds = AdjustedcurEndPerformanceCounter - AdjustedcurStartPerformanceCounter
If duration_in_seconds < 1 then
 duration_in_seconds = duration_in_seconds*1000
 MsgBox("Durée du chrono : " & duration & " ms")

ElseIf duration_in_seconds < 60 Then
 MsgBox("Durée du chrono : " & duration_in_seconds & " sec")

ElseIf duration_in_seconds < 3600 Then
 minutes = Round (duration_in_seconds/60,0)
 secondes = Round(((duration_in_seconds/60)- minutes)*60,0)
 MsgBox("Durée du chrono : " & minutes & " min " & secondes & " sec")

Else
 heures = Round (duration_in_seconds/3600,0)
 minutes = Round (((duration_in_seconds/3600)-heures)*60,0)
 secondes = Round(((duration_in_seconds/60)- minutes)*60,0)
 MsgBox("Durée du chrono : " & heures & " h "  & minutes & " min " & secondes & " sec")

End If

    'measure elapsed time
    'MsgBox( "Durée du chrono : " & 1000*(AdjustedcurEndPerformanceCounter - AdjustedcurStartPerformanceCounter) & " (ms) / " & (AdjustedcurEndPerformanceCounter - AdjustedcurStartPerformanceCounter) & " (s)")
'    MsgBox( "Elapsed time (s): " & )
End If
'============================

End Sub

Function TimedOutMsgBox(title As String, message As String, timeout 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 &"""""," & timeout & ",""""" & 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 = "NO BUTTON"
    End Select

End Function


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

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

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 881 guests browsing this forum, which makes a total of 882 users using this forum.

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