Jump to content

Creating wav files using text or any text file.


i386
 Share

Recommended Posts

I created a simple Text2Wav and File2Wav script using lod3n's<{POST_SNAPBACK}> UDF for SAPI

Please let me know what you all think and if you have any problems or suggestions please let me know by posting them here. Thanks!

CODE
; Include files
#include <GUIConstants.au3>

;Constants setup
Const $SSFMCreateForWrite = 3

;String setup
$strFName = @scriptdir&'\AudioOutputStream.wav'
$FileRead = ''


;Creates the Main Form GUI
$SpFS = GUICreate('SAPI.SpFileStream    Coded by: terrabyte', 384, 470, 351, 228)

$Group1 = GUICtrlCreateGroup('File2Wav', 8, 16, 361, 113)
    $InfoLabel = GUICtrlCreateLabel('Convert File', 24, 40, 60, 17)
    $FileLoc = GUICtrlCreateInput('File Location...', 24, 64, 225, 22)
        GUICtrlSetFont(-1, 8, 400, 2, 'Times New Roman')
        GUICtrlSetColor(-1, 0x808080)
    $FLBrowse = GUICtrlCreateButton('&Browse...', 264, 61, 75, 25, 0)
    $FileStream = GUICtrlCreateButton('Convert &File...', 148, 96, 75, 25, 0)
GUICtrlCreateGroup('', -99, -99, 1, 1)

$Group2 = GUICtrlCreateGroup('Txt2Wav', 8, 144, 361, 281)
    $Txt2Wav = GUICtrlCreateEdit('', 16, 160, 345, 201, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
        GUICtrlSetData(-1, 'Text to convert...')
    $TextStream = GUICtrlCreateButton('Convert &Txt...', 148, 392, 75, 25, 0)
        GUICtrlCreateGroup('', -99, -99, 1, 1)
    ;$SAPIHelp = GUICtrlCreateButton('&Help...', 70, 440, 75, 25, 0)
    $SAPIAbout = GUICtrlCreateButton('&About...', 230, 440, 75, 25, 0)

GUISetState(@SW_SHOW)

;Creates the 'About' Form GUI
$AboutSPFS = GUICreate('About SAPI.SpFileStream', 316, 237, 357, 335)
    GUISetIcon('D:\006.ico')
$GroupBox1 = GUICtrlCreateGroup('', 8, 8, 305, 185)
    $Image1 = GUICtrlCreatePic('', 16, 24, 105, 97, BitOR($SS_NOTIFY,$WS_GROUP))
    $Label1 = GUICtrlCreateLabel('SAPI.SpFileStream', 152, 24, 93, 17, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel('v1.0', 152, 48, 25, 17, $WS_GROUP)
    $Label4 = GUICtrlCreateLabel('An easy to use way to turn text into a .wav file using Autoit.' _
        & @CRLF & 'This script was tested on Vista® using the AutoIt beta version', 16, _
        160, 685, 30, $WS_GROUP)
    $Label3 = GUICtrlCreateLabel('©2006 Copyright by terrabyte', 16, 136, 142, 17, $WS_GROUP)

$AboutOk = GUICtrlCreateButton('&OK', 112, 208, 75, 25)
GUISetState(@SW_HIDE)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FLBrowse
            _Search()
        Case $FileStream
            _File2Wav($FileRead)
        Case $TextStream
            _Txt2Wav(GUICtrlRead($Txt2Wav))
        ;Case $SAPIHelp
        ;   _SAPIHelp()
        Case $SAPIAbout
            GUISetState(@SW_SHOW, $AboutSPFS)
        Case $AboutOk
            GUISetState(@SW_HIDE, $AboutSPFS)

    EndSwitch
WEnd

Func _Search()
    $File = FileOpenDialog( 'SAPI.SpFileStream Open File...', @MyDocumentsDir, _
        'Text Files (*.txt)|All Files (*.*)', 3 )
    $FileRead = FileRead($File)
    
    GUICtrlSetData( $FileLoc, $File )
    GUICtrlSetColor( $FileLoc, 0x000000 )
    GUICtrlSetFont( $FileLoc, 9, 400, -1, -1 )
EndFunc

Func _File2Wav($Text)
    GUICtrlSetData($FileStream, 'Converting...')
    
    FileOpen($FileLoc, 0)
    $objVOICE = ObjCreate('SAPI.SpVoice')
    $objFSTRM = ObjCreate('SAPI.SpFileStream')

    $objFSTRM.Open($strFName , $SSFMCreateForWrite, False)
    $objVOICE.AudioOutputStream = $objFSTRM
    $objVOICE.Speak($Text)
    $objFSTRM.Close
    
    GUICtrlSetData($FileStream, 'Convert &File...')

    SoundPlay($strFName, 0)
EndFunc

Func _Txt2Wav($Text)
    GUICtrlSetData($TextStream, 'Converting...')
    
    $objVOICE = ObjCreate('SAPI.SpVoice')
    $objFSTRM = ObjCreate('SAPI.SpFileStream')

    $objFSTRM.Open($strFName , $SSFMCreateForWrite, False)
    $objVOICE.AudioOutputStream = $objFSTRM
    $objVOICE.Speak($Text)
    $objFSTRM.Close
    
    GUICtrlSetData($TextStream, 'Convert &Txt...')

    SoundPlay($strFName, 0)
EndFunc

This script was tested on Windows® Vista® using AutoIt Beta v3.2.1.5

I have not tried it on a .doc, .rtf, or an OpenOffice.org document yet. If you have tried it on another file extention other than .txt and it worked please let me know and what OS you are using so I can put it in the script. Thanks again.

Edited by terrabyte
Spoiler

 

"...Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like.My crime is that of outsmarting you, something that you will never forgive me for." --The Mentor

"Mess with the best, die like the rest!!" -Hackers

"This above all to thine own self be true." -William Shakespeare

"Corruption is only as corrupted as the individual makes it out to be." -i386

 

style7,AutoIt.png

 

 

Link to comment
Share on other sites

Anybody willing to try this out and give me any feedback? I would love it for any suggestions or any reports of any problems.

Spoiler

 

"...Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like.My crime is that of outsmarting you, something that you will never forgive me for." --The Mentor

"Mess with the best, die like the rest!!" -Hackers

"This above all to thine own self be true." -William Shakespeare

"Corruption is only as corrupted as the individual makes it out to be." -i386

 

style7,AutoIt.png

 

 

Link to comment
Share on other sites

Would be nice if it didn't save automatically.

Some fool might not understand the save process and hit convert a hundred times... 100 wave files...

The file is automaticly saved to the save file and it just rewrites over the same file over and over again. But, I will implement a save feature into it. Also changed the mistake in my syntax. Thanks The Ape

Spoiler

 

"...Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like.My crime is that of outsmarting you, something that you will never forgive me for." --The Mentor

"Mess with the best, die like the rest!!" -Hackers

"This above all to thine own self be true." -William Shakespeare

"Corruption is only as corrupted as the individual makes it out to be." -i386

 

style7,AutoIt.png

 

 

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