Jump to content

Image to Speech


Yorn
 Share

Recommended Posts

(This is a repost in the correct forum, sorry my last post was not in the correct forum)

Very short code, all I did was combined two efforts of other individuals on here to make this. The resulting EXE if you compile can have a BMP file dragged over it and it will "read aloud" the text in that BMP file using the computer's default voice.

I would encourage you to do a search on the function names (I haven't changed either of them) and look at what the author originally designed and modify from there.

I've been considering using this to develop a small application that can take an image of a paper/form from a Webcam and read the text of it for a blind person. Also, this requires either Office XP, 2003, or 2007.

#RequireAdmin
$BMP = $cmdline[1]
$String = _Img2Txt($BMP)
MsgBox(0,"OCR Text to Read",$String)
_TalkOBJ($string)
Exit

Func _Img2Txt($F, $S = "")
; needs at least MS Word XP for "MODI.Document" object
    ObjEvent("AutoIt.Error", "_CoMErrFunc")
    $O = ObjCreate("MODI.Document")
    $O.Create($F)
    $O.Ocr(9);english=9 german=7 spanisch=10
    For $W In $O.Images(0).Layout.Words
        $S &= $W.text & " "
    Next
    Return $S
EndFunc;==>_Img2Txt

Func _TalkOBJ($s_text)
    Dim $oSp = ObjCreate("SAPI.SpVoice")
    $oSp.Speak($s_text)
EndFunc;==>_TalkOBJ

Attached is a binary.

EDIT: Fixed code and binary to #requireadmin

OCR.zip

Edited by Yorn
Link to comment
Share on other sites

Can't create MODI.Document object. I have Office 2007 though.

$BMP = FileOpenDialog("BMP", @AutoItExe,"All (*.*)")
If @error Then Exit
$String = _Img2Txt($BMP)
If Not @error Then
    MsgBox(0,"OCR Text to Read",$String)
    _TalkOBJ($string)
Else
    MsgBox(0, "Error","Could not read text")
EndIf

Exit

Func _Img2Txt($F, $S = "")
; needs at least MS Word XP for "MODI.Document" object
    ObjEvent("AutoIt.Error", "_CoMErrFunc")
    $O = ObjCreate("MODI.Document")
    If @error OR Not IsObj($O) Then
        Return SetError(1,0,0)
    EndIf
    $O.Create($F)
    $O.Ocr(9);english=9 german=7 spanisch=10
    For $W In $O.Images(0).Layout.Words
        $S &= $W.text & " "
    Next
    Return $S
EndFunc;==>_Img2Txt

Func _TalkOBJ($s_text)
    Dim $oSp = ObjCreate("SAPI.SpVoice")
    $oSp.Speak($s_text)
EndFunc;==>_TalkOBJ
Link to comment
Share on other sites

Can't create MODI.Document object. I have Office 2007 though.

$BMP = FileOpenDialog("BMP", @AutoItExe,"All (*.*)")
If @error Then Exit
$String = _Img2Txt($BMP)
If Not @error Then
    MsgBox(0,"OCR Text to Read",$String)
    _TalkOBJ($string)
Else
    MsgBox(0, "Error","Could not read text")
EndIf

Exit

Func _Img2Txt($F, $S = "")
; needs at least MS Word XP for "MODI.Document" object
    ObjEvent("AutoIt.Error", "_CoMErrFunc")
    $O = ObjCreate("MODI.Document")
    If @error OR Not IsObj($O) Then
        Return SetError(1,0,0)
    EndIf
    $O.Create($F)
    $O.Ocr(9);english=9 german=7 spanisch=10
    For $W In $O.Images(0).Layout.Words
        $S &= $W.text & " "
    Next
    Return $S
EndFunc;==>_Img2Txt

Func _TalkOBJ($s_text)
    Dim $oSp = ObjCreate("SAPI.SpVoice")
    $oSp.Speak($s_text)
EndFunc;==>_TalkOBJ
Same. I have Office XP Though.
Link to comment
Share on other sites

@Manadar / KentonBomb

Maybe this can you going MODI

Regards

ptrex

Also fails after installing that package.

Still fails after I uninstalled Office XP and dug up my Office 2003 CD. This does not seem to want to work :P

EDIT: The problem is that it fails to initialize the object.

Edited by KentonBomb
Link to comment
Share on other sites

It wasn't working, so I figured I'd try this and see what happens. I don't have a Vista computer available at the moment to test with but the old version worked perfectly fine with my implementation of Vista/Office 2007 at work as well as someone else's who I showed it to. Lastly, it also worked on an Office 2003/XP combo at work and the new one works on the same here at home.

Alternatively it doesn't require admin and it is likely that you did not install the MODI library with your Office (you did a minimal or otherwise stripped down installation). Maybe it would be best to try a full install (at least to test?).

Edited by Yorn
Link to comment
Share on other sites

EDIT: The problem is that it fails to initialize the object.

Just a guess, but if the error is in creating the object, your text to speech may not be installed or setup correctly.

EDIT: Sorry, you did say the error was in creating the MODI object and not the voice. my bad.

Edited by XnT
Link to comment
Share on other sites

  • 2 months later...

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...