Reputation: 335
I made a very simple text-to-speech program using VBScript (which I have limited experience with). It simply opens a command prompt, you type something, and Windows spvoice speaks the message.
I want this app to take the message input and add that text to a separate .txt file. So basically, this would be text-to-speech-to-text. Is VBScript too limited to read and write to text file?
Dim message, sapi
message=InputBox("Enter text:","Enter Text")
Set sapi=CreateObject("sapi.spvoice")
sapi.Speak message
Upvotes: 2
Views: 5124
Reputation: 335
This seemed to work. I was running into issues with 800A0046 error at first. To fix this, I made a new folder in the C: drive and rooted to that.
Dim message, sapi, objFileToWrite
message=InputBox("What do you want me to say?","Speak to Me")
Set sapi=CreateObject("sapi.spvoice")
sapi.Speak message
Set objFileToWrite =
CreateObject("Scripting.FileSystemObject")
_.OpenTextFile("C:\Speech\LiveChat.txt",2,true)
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing
Upvotes: 1
Reputation: 387
You could use the following to write the message to a text file.
Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile _
("C:\SpeechMessage.txt",2,true)
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing
VBScript Text Files: Read, Write, Append
EDIT:
Create the following to avoid permissions issues on the root of C:
C:\Speech\
And Try this code that will create the file if it does not exist and append to it if it does.
Set objFileToWrite = CreateObject("Scripting.FileSystemObject")
If objFileToWrite.FileExists("C:\Speech\Message.txt") then
Set objFileToWrite = objFileToWrite.OpenTextFile("C:\Speech\SpeechMessage.txt",8,true)
Else
Set objFileToWrite = objFileToWrite.CreateTextFile("C:\Speech\SpeechMessage.txt")
End If
objFileToWrite.WriteLine(message)
objFileToWrite.Close
Set objFileToWrite = Nothing
Upvotes: 2