Convert Text Into WAV Files
There are several situations where it would be to your benefit to listen to a WAV file rather than read a text file.
- When you are driving home.
- Someone who is visually impaired.
- You do not want the contents of a text file edited.
So, I started looking into how difficult it would be to create such a program. As it turns out, not very difficult.
I used AutoIT to create a simple executable that lets you either double click on the program and select a text file or drop a text file right on it. It will then automatically create a WAV file with the same name in the same folder as your original file.
You can download the MakeWAV application for free.
Also, if you are interested, here is the source code that you can copy and compile to make your own application. It’s open source so have fun!
#NoTrayIcon
Opt("MustDeclareVars", 1)
Dim $strTXTFile ;Name of the text file to convert to a WAV
Dim $strWAVFile ;Name of the WAV file to create
Dim $strTextData ;Text information to convert to a
WAV file
If $CmdLine[0] > 0 Then
$strTXTFile = $CmdLine[1]
Else
$strTXTFile = FileOpenDialog("Select Text File...", @MyDocumentsDir, "All (*.*)|Text files (*.txt;*.csv;*.log;*.msg;*.asc)", 1)
EndIf
If Not FileExists($strTXTFile) Then Exit
$strWAVFile = StringLeft($strTXTFile, StringLen($strTXTFile) - 3) & "wav"
$strTextData = FileRead($strTXTFile)
SplashTextOn("", "Creating WAV file. Please be patient.", 275, 20, -1, -1, 1)
_MakeWAV($strTextData, $strWAVFile)
Func _MakeWAV($strSentence, $strFileName)
Dim $oVoice ;SAPI voice object
Dim $oFilestream ;SAPI file stream object
$oVoice = ObjCreate("SAPI.SpVoice")
$oFilestream = ObjCreate("SAPI.SpFileStream")
$oFilestream.Open($strFileName, 3, False)
$oVoice.AudioOutputStream = $oFilestream
$oVoice.Speak($strSentence)
$oFilestream.Close
$oFilestream = 0
$oVoice = 0
EndFunc ;==>_MakeWAV
4 Responses to “Convert Text Into WAV Files”
-
Me Says:
August 27th, 2008 at 9:03 amI am sorry for a lame question but what kind of language is it? It looks VB-scriptish but it’s not. What is it?
-
Tim Fehlman Says:
August 27th, 2008 at 9:05 amI do pretty much all of my coding in AutoIT. It is a free scripting language with a very active community.
Tim
-
Anigan Says:
August 27th, 2008 at 10:59 pmAny way I can change the voice it uses to record with?
-
Justin Joseph Says:
November 11th, 2008 at 2:07 amHi Tim Fehlman,
thats one amazing piece of information, i have been looking around for some time. The scripts looks too good too. Thanks for sharing this informationwith regards
Justin
