Jump to content

AutoIt Dictation!


cdkid
 Share

Recommended Posts

It uses the microsoft speech recognition SDK which can be downloaded

http://download.microsoft.com/download/spe...speechsdk51.exe <--- there

If it isnt already trained then train it and start this :geek:

Well, here it is, not the best but i thought it was fun ;)

#cs
Commands:
Question mark
        Sends a question mark
        Example: "Hello Question Mark"
New Paragraph
        sends ENTER - TAB
Period
        Starts a new sentence
Quote
        Sends a quotation mark
Delete That
        Deletes the last message (Saves the last 11 messages)
Quit
        Shuts down Scribe
Space
        Sends a space
BackSpace
        Sends a backspace
Comma
        Sends a comma
Note: Some of these will probably only work if they are alone in a command so
"Hello new paragraph" is not the same as "hello" "new paragraph", i belive period, comma, quote, and question mark will work in with other words.
#ce
Global $recog = "";SET GLOBAL
Global $buffer[12]
global $cmds[10], $do, $i, $nf
$cmds[0] = "quit"
$cmds[2] = "backspace"
$cmds[4] = "delete that"
$cmds[5] = "comma"
$cmds[6] = "new paragraph"
$cmds[7] = "quote"
$cmds[8] = "space"
$cmds[9] = "period"
$do = 1
$z = 1
$nf = 0
$RecoContext=ObjCreate("SAPI.SpSharedRecoContext")
if @error then
    Msgbox(0,"","ERROR")
    exit
endif
$SinkObject=ObjEvent($RecoContext,"MYEvent_")
  $SPRS_INACTIVE    = 0
  $SPRS_ACTIVE  = 1
  $SGDSActive=$SPRS_ACTIVE
  $SGDSInactive=$SPRS_INACTIVE

  $Grammar = $RecoContext.CreateGrammar(1)
  $Grammar.Dictationload
  $Grammar.DictationSetState($SGDSActive);LISTEN
while 1
    
    Sleep(100)
if $recog <> "" Then
    for $i = 0 to ubound($cmds, 1) - 1
        if $recog = $cmds[$i] OR stringleft($recog, 10) = "backspace " Then
            $do = 0
        EndIf
    Next
    if $do = 1 Then
        if $nf = 0 Then
            send($recog)
            if $z = 10 then
                $z = 0
            EndIf
                $z = $z + 1
            $buffer[$z] = $recog
            $nf = 1
        Else
        send("{SPACE}" & $recog)
        if $z = 10 Then
            $z = 0
        EndIf
    $z = $z + 1
    $buffer[$z] = " " & $recog
EndIf
    EndIf
Select
case stringleft($recog, 10) = "backspace "
    $recog = stringreplace($recog, "one","1")
    $recog = stringreplace($recog, "to", "2")
    $recog = stringreplace($recog, "two", "2")
    $recog = stringreplace($recog, "three", "3")
    $recog = stringreplace($recog, "for", "4")
    $recog = stringreplace($recog, "four", "4")
    $recog = stringreplace($recog, "five", "5")
    $recog = stringreplace($recog, "six", "6")
    $recog = stringreplace($recog, "seven", "7")
    $recog = stringreplace($recog, "ate", "8")
    $recog = stringreplace($recog, "eight", "8")
    $recog = stringreplace($recog, "nine", "9")
    $recog = stringreplace($recog, "backspace ", "")
                $recog = stringreplace($recog, " ", "")
    send("{BS " & $recog & "}")
case $recog = "period"
    send(".")
    if $z = 10 Then
        $z = 0
    EndIf
        $z = $z + 1
    $buffer[$z] = "."
case $recog = "space"
    send("{SPACE}")
    if $z = 10 Then
        $z = 0
    EndIf
    $z = $z + 1
    $buffer[$z] = " "
case $recog = "new paragraph"
    send("{ENTER}")
    send("{TAB}")
    if $z = 10 Then
        $z = 0
    EndIf
    $z = $z + 1
    $buffer[$z] = "  "
case $recog = "delete that"
    if $z = 0 Then $z = 10
    $l = StringLen($buffer[$z])
    $buffer[$z] = ""
    $z = $z - 1
    send("{backspace " & $l & "}")
case $recog = "backspace"
    send ("{BACKSPACE}")
Case $recog = "quit"
    exit;HEAR EXIT
EndSelect
;_talkOBJ($recog, 3); TALKS AFTER IT HEARS SOMETHING, The mic hears the pc and affects the recognition
    _talkOBJ($recog, 3, "dont talk"); JUST POP-UPt
    $recog = "";SET TO NULL FOR REPEATED COMMANDS
    $do = 1;So it will continue typing after a command
EndIf
WEnd
;$Grammar.DictationSetState($SGDSInactive);STOP LITENING
  

Func MYEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)
          $recog = $Result.PhraseInfo.GetText;SET $recog VAR
EndFunc
Func _TalkOBJ($s_text, $s_voice = 3, $s_dont = "")
Local $quite = 0
    Local $o_speech = ObjCreate ("SAPI.SpVoice")
    Select
        Case $s_voice == 1
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)
            TrayTip("Female Reader",$s_text,1)
        Case $s_voice == 2
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)
            TrayTip("Male Reader",$s_text,1)
        Case $s_voice == 3
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)
            TrayTip("OldMan Reader",$s_text,1)
    EndSelect
if $s_dont <> "dont talk" then
    $o_speech.Speak ($s_text)
    $o_speech = ""
ENDif
    Sleep(1000)
    TrayTip("","",1)
EndFunc;==>_TalkOBJ

Tell me what'cha think :o

~cdkid

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

Hey nice idea. Just one question, do you have the same problem as I do with the script, it just stops listening after about a minute? I can't figure it out. The project I am working on is a voice commander program, it should be nice this is what I have so far:

JUST THE UNFINISHED GUI

CODE
; ----------------------------------------------------------------------------

;

; AutoIt Version: 3.1.1.109 (beta)

; Author: zerocool60544 <jsammarco@gmail.com>

;

; Script Function:

;

;

; ----------------------------------------------------------------------------

;

$hwnd = GUICreate ( "Voice Commander", 640, 480 )

#include "GUIConstants.au3"

$treeview=GUICtrlCreateTreeView( 10, 10, 200 , 460, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)

$generalitem = GUICtrlCreateTreeViewitem("General", $treeview)

$displayitem = GUICtrlCreateTreeViewitem("Display", $treeview)

$aboutitem = GUICtrlCreateTreeViewitem("About", $generalitem)

$compitem = GUICtrlCreateTreeViewitem("Computer", $generalitem)

$useritem = GUICtrlCreateTreeViewitem("User", $generalitem)

$resitem = GUICtrlCreateTreeViewitem("Resolution", $displayitem)

$otheritem = GUICtrlCreateTreeViewitem("Other", $displayitem)

GUICtrlCreateGroup ("Initiate Command", 220, 400, 410, 70)

$initcheckbox = GUICtrlCreateCheckbox ( "word to listen for before hearing commands:", 240, 430, 220, 22)

$initcommand = GUICtrlCreateInput ( "Computer", 480, 430 , 130)

$buttonadd = GUICtrlCreateButton ( "Add", 230, 320, 110)

$buttondel = GUICtrlCreateButton ( "Delete", 370, 320, 110)

$buttonsave = GUICtrlCreateButton ( "Save", 510, 320, 110)

$buttonlisten = GUICtrlCreateButton ( "Start Listening", 370, 370, 110)

$buttonSR = GUICtrlCreateButton ( "Speech Recognition", 510, 370, 110)

GUICtrlCreateGroup ("Edit Command", 220, 10, 410, 300)

$namelabel = GUICtrlCreateLabel ( "Command Name:", 230, 50, 120)

$commandname = GUICtrlCreateInput ( "", 320, 45, 90)

$commandlabel = GUICtrlCreateLabel ( "Command Word:", 440, 50, 120)

$commandword = GUICtrlCreateInput ( "", 530, 45, 90)

$commandtype = GUICtrlCreateList ( "", 230, 80, 100, 120 )

GUICtrlSetData($commandtype,"Run Program|Run Command|Play Media|Close Window|Shutdown|Send Keys", "Run Program")

Global $temp1,$temp2,$temp3,$temp4,$temp5,$temp6,$temp7, $msg

;DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hwnd, "int", 2000, "long", 0x00040010);explode

GUISetState ()

$lasttype = ""

While 1

$msg = GUIGetMsg()

if $msg = $GUI_EVENT_CLOSE Then ExitLoop

if GUICtrlRead ( $commandtype ) <> $lasttype Then

Select

Case GUICtrlRead ( $commandtype ) = "Close Window"

$lasttype = "Close Window"

deltempctrl()

$temp1 = GUICtrlCreateInput ( "Program Manager", 340, 120, 270)

Case GUICtrlRead ( $commandtype ) = "Run Command"

$lasttype = "Run Command"

deltempctrl()

$temp1 = GUICtrlCreateInput ( "msgbox(0,'hello','Hi')", 340, 120, 270)

Case GUICtrlRead ( $commandtype ) = "Run Program"

$lasttype = "Run Program"

deltempctrl()

$temp1 = GUICtrlCreateButton ( "Browse", 350, 120, 80)

$temp2 = GUICtrlCreateInput ( "", 440, 120, 170)

Case GUICtrlRead ( $commandtype ) = "Send Keys"

$lasttype = "Send Keys"

deltempctrl()

$temp1 = GUICtrlCreateInput ( "", 340, 120, 270)

$temp2 = GUICtrlCreateLabel ( "Key list" & @CRLF & "{RCTRL}", 340, 230, 230)

Case GUICtrlRead ( $commandtype ) = "Shutdown"

$lasttype = "Shutdown"

deltempctrl()

Case GUICtrlRead ( $commandtype ) = "Play Media"

$lasttype = "Play Media"

deltempctrl()

EndSelect

EndIf

gettempgui()

WEnd

Func gettempgui()

Select

Case $lasttype = "Close Window"

$window = GUICtrlRead ( $temp1 )

Case $lasttype = "Run Command"

$command = GUICtrlRead ( $temp1 )

Case $lasttype = "Run Program"

if $msg = $temp1 then

$program = FileOpenDialog ( "Select Program", @ScriptDir, "Programs (*.exe;*.bat)", 1 )

If @error Then

MsgBox(4096,"","No File(s) chosen")

Else

;$var = StringReplace($var, "|", @CRLF)

GUICtrlSetData ( $temp2, $program )

EndIf

EndIf

Case $lasttype = "Send Keys"

Case $lasttype = "Shutdown"

Case $lasttype = "Play Media"

EndSelect

EndFunc

Func deltempctrl()

GUICtrlDelete($temp1)

GUICtrlDelete($temp2)

GUICtrlDelete($temp3)

GUICtrlDelete($temp4)

GUICtrlDelete($temp5)

GUICtrlDelete($temp6)

GUICtrlDelete($temp7)

EndFunc

Edited by zerocool60544

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Hmm, no i haven't had that problem, but i just thought i'd let everyone know, i updated with BACKSPACE <number>, so for backspace 25 say

"backspace two five"

**edit**

hmm, i have had taht problem a few times now, but i just restart it and it works fine...

***edit2**

Could some sort of recursion limit be being reached with the While 1....WEnd loop?

Thus causing it to ignore everything?

Edited by cdkid
AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

I don't know why it just stops listening, I tried a lot of different things, this script all the commands are in the recog func, You can change the voices by saying their names

$RecoContext=ObjCreate("SAPI.SpSharedRecoContext")
if @error then
    Msgbox(0,"","Error opening $RecoContext: " & @error)
    exit
endif
$SinkObject=ObjEvent($RecoContext,"MYEvent_")
  $SPRS_INACTIVE    = 0
  $SPRS_ACTIVE  = 1
  $SGDSActive=$SPRS_ACTIVE
  $SGDSInactive=$SPRS_INACTIVE
  $Grammar = $RecoContext.CreateGrammar(1)
  $Grammar.Dictationload
  $Grammar.DictationSetState($SGDSActive)
    Global $recog, $s_voice = 3
While 1
Sleep(1000)

WEnd

Func MYEvent_Recognition($StreamNumber,$StreamPosition,$RecognitionType,$Result)
    $recog = $Result.PhraseInfo.GetText
    Select
    Case $Result.PhraseInfo.GetText = "exit"
        exit
    Case $Result.PhraseInfo.GetText = "Mary"
                $s_voice = 1
        _TalkOBJ("Hello, Mary here", $s_voice)
    Case $Result.PhraseInfo.GetText = "Mike"
                $s_voice = 2
        _TalkOBJ("Hello, Mike here", $s_voice)
    Case $Result.PhraseInfo.GetText = "Sam"
                $s_voice = 3
        _TalkOBJ("Hello, Sam here", $s_voice)
    Case else 
            _TalkOBJ($Result.PhraseInfo.GetText, $s_voice)
    EndSelect
  EndFunc
  
Func _TalkOBJ($s_text, $s_voice = 3)
          $Grammar.DictationSetState($SGDSInactive)
Local $quite = 0
    Local $o_speech = ObjCreate ("SAPI.SpVoice")
    Select
        Case $s_voice == 0
            Return
        Case $s_voice == 1
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)
            TrayTip("MARY",$s_text,1)
        Case $s_voice == 2
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)
            TrayTip("MIKE",$s_text,1)
        Case $s_voice == 3
            $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)
            TrayTip("SAM",$s_text,1)
    EndSelect
    $o_speech.Speak ($s_text)
    $o_speech = ""
    Sleep(1000)
    TrayTip("","",1)
          $Grammar.DictationSetState($SGDSActive)
EndFunc ;==>_TalkOBJ

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...