VBScript Text-To-Speech (to text) - vbscript

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

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

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

Related

Multi line vbs auto typer from .txt file [duplicate]

This question already has answers here:
Single Line Input VBS Autotyper
(2 answers)
Closed 2 years ago.
So i have been working on a troll terminal and now i want to type out the entire bee movie script or whatever i put in a text file.
What i need help with is taking the text(with enters and spaces) and fully typing it out.
Another way to say it is i want to take a text file and copy it threw typing it out.
I couldnt find any decent code to do this wich is why i'm asking here.
Also if possible make it type anything that you put in the text file.
(I have no clue why it doesnt let me post this)
Idea: I might know another way around but i dont know how to get it done.
Maby there is a way to infinetly generate variables for each line and type them out like that.
Other idea: I might be able to make a tool to let me quickly hard code it.
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\yourfirstfile", 1)
content = file.ReadAll
Const fsoForAppend = 8
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Open the text file
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("C:\yoursecondfile", fsoForAppend)
'Display the contents of the text file
objTextStream.WriteLine content
'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
Set wshShell = CreateObject("Wscript.Shell")
wshShell.run "C:\yoursecondfile"
Tell me if it works
Yes i m self anwsering.
This script works but it double taps enter i will update it if i figure out how to stop that from happening.
Set wsh=WScript.CreateObject("WScript.Shell")
sub custom_text_typer_confirm
Set objFileToRead =WScript.CreateObject("Scripting.FileSystemObject").OpenTextFile("Custom_Text_Typer.txt",1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close
custom_typer_wait = inputbox("How long should the program wait untill it will start typing?", "Eclips-Terminal Custom Text Typer")
custom_typer_wait1=custom_typer_wait * 1000
Wscript.sleep custom_typer_wait1
wsh.sendkeys (strFileText & "{enter}")
Wscript.sleep 1000
call home
end sub

open and write 2 files

I need create one script for open one file (Server.txt → content all servers names) and create logfile with ServerName (example: Server1.txt). After that I need WriteLine in this logfile result of the script retrieve registry values.
I have one script working retrieve all registry values but I need to create each FileLog with ServerName.
I think cannot use two Opentextfile before close one.
Can we help me?
This is code I'm using for test:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("Servers.txt")
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
Set objFile2 = objFSO.CreateTextFile(strComputer & ".txt",True)
set objHtml=objFSO.OpenTextFile(objFile2,8,true)
objHtml.WriteLine Now() & VbTab & RegResultQuery
objHtml.Close
Loop
You can call OpenTextFile twice, but you can't open the same file twice without closing it first. From what I see you don't need to open the file twice, though. CreateTextFile already returns a handle to the file, so you can simply use objFile2 throughout the loops.

VBS WScript.Run fails after passing Exists test

In a couple of place in my code I check if the file exists (it does) then I try to Run the file as above, or get the DateLastModified, and get errors about file not found or invalid path. How can the script NOT see a file after confirming it exists?
I'm working up a .vbs script that tries to run an Access .mdb file. The WScript.Run command seems to choke on the filename, but putting a MsgBox() before that call to display the path allows Run to work properly. I don't want to display a popup.
Error is:
The directory name is invalid.
How is this possible and how can I get around it?
Here is code:
AccessFileName = "App.mdb"
LocalPath = "C:\Folder\"
SET ws = WScript.CreateObject("WScript.Shell")
path = Chr(34) & LocalPath & AccessFileName & Chr(34)
if (fso.FileExists(LocalPath & AccessFileName)) THEN
'MsgBox(path) 'Uncommenting this line removes the error
ws.Run path 'This line errors
End If
Try to open your file with shell .InvokeVerb method:
AccessFileName = "App.mdb"
LocalPath = "C:\Folder\"
If CreateObject("Scripting.FileSystemObject").FileExists(LocalPath & AccessFileName) Then
CreateObject("Shell.Application").Namespace(LocalPath).ParseName(AccessFileName).InvokeVerb
End If
UPD: Both ActiveX WScript.Shell and Shell.Application uses native windows shell to perform a file execution.The first one launches new process via WSH core located in wscript.exe, cscript.exe, wshom.ocx, jscript.dll, vbscript.dll, ets, .Run and .Exec methods of WsShell object provides wide control on the launched process, and second one located in Shell32.dll, uses .InvokeVerb method of IShellDispatch object, called without name, runs default verb equals to the windows explorer "open" command.In case of any issues connected to WSH, explorer might still works without any proplems. If it does, that is just a work-around, I can't say what's wrong definetely without close look.
Hello the following code worked for me.
Basically this code gets a folder object and loops through all files in a folder and checks if its the one that you named. This it runs the application.
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = Wscript.CreateObject("Wscript.Shell")
AccessFileName = "App.mdb"
LocalPath = "C:\Folder\"
Set myFolder = fso.GetFolder(LocalPath)
For each myFile in myFolder.Files
If myFile.Name = AccessFileName Then
'Wscript.Echo myFile.Name
ws.Run myFolder.Path & "\" & myFile.Name
End If
Next
You can give this a shot. You probably do not need the quotes around the path, but I included it as a comment if you want to give it a shot. You just put quotes twice if you need to include a quote character in a string:
Set fso = CreateObject("Scripting.FileSystemObject")
AccessFileName = "App.mdb"
LocalPath = "C:\Folder\"
Set ws = WScript.CreateObject("WScript.Shell")
' path = """" & LocalPath & AccessFileName & """" <-- probably unnecessary
path = LocalPath & AccessFileName
If (fso.FileExists(path)) Then
Set file = fso.GetFile(path)
'MsgBox(path) 'Uncommenting this line removes the error
ws.Run file.Path 'This line errors
End If
This does not make any sense. Having a MsgBox line is altering the behavior of the program!!!
I feel it is probably some weird invisible character somewhere which is getting activated when you comment the line.
Try retyping the If block without the MsgBox in between.

File wont move to folder vbs

So im writing a script that drops a file folder then moves that file to the folder it dropped it self. Well the folder drops fine but the file wont move. Can some see whats wrong with my code? Or give me a better way to move the file. I also get no error message about trying to move the file.
Dim folder,fso,filsys,C
Set fso = CreateObject("Scripting.filesystemObject")
Set folder = fso.GetSpecialFolder(1)
Set wshshell = CreateObject("wscript.shell")
Set filesys = CreateObject("scripting.filesystemobject")
Set objfso = CreateObject("Scripting.filesystemObject")
Set c = fso.GetFile(Wscript.scriptFullname)
On Error Resume NEXT
Set objFolder = objFSO.CreateFolder("C:\55egr932ntn7mk23n124kv1053bmoss5")
If Err.Number<>0 Then
End If
WScript.Sleep 3000
C.Move ("C:\552ntn7mk23n124kv1053bmoss5\File.exe") (folder&"\File.exe")
And I have a program I use that turns the VBS into and EXE so you see the "file.exe" which really is the .VBS itself
I'm not familiar with this syntax, but the line below looks like it's expecting the folder variable to be a string.
C.Move ("C:\552ntn7mk23n124kv1053bmoss5\File.exe") (folder&"\File.exe")
Earlier in code it looks as though you're setting folder as an object.
Set folder = fso.GetSpecialFolder(1)
You might not get the error you mentioned in your comment if you convert folder to a string.
~~
Another thing to try is the following code:
Set fso = CreateObject("Scripting.filesystemObject")
Set folder = fso.GetSpecialFolder(1)
Alert (folder&"\File.exe")
(I'm not sure if it's "Alert" or "Msgbox" or something else.) That test will show you whether the file path makes sense. If you get an error on line 3 of that test, try converting folder to a string before your Alert (or Msgbox).

Using VB Script to read contents of .msg file

I have a folder with thousands of Outlook .msg files.
I'd like to know if it's possible to write a VB Script that can read the sender and receiver from each file, and move the .msg file to a folder based on this info?
Thanks
You shouldn't ask yes/no questions unless you expect the answer to be either "yes" or "no".
Set ol = CreateObject("Outlook.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In fso.GetFolder("C:\some\folder").Files
If LCase(fso.GetExtensionName(f)) = "msg" Then
Set msg = ol.CreateItemFromTemplate(f.Path)
WScript.Echo msg.Sender.Name
For Each rcpt In msg.Recipients
WScript.Echo rcpt.Name
Next
End If
Next
For reading the contents of a .msg file, I have used the following approach.
use CreateItemFromTemplate for the msg file using the outlook object
Use this outlook object to save the data into a .txt file
Once the .txt file is created read it and use the data as required
Script:
Dim OL : Set OL=CreateObject("Outlook.Application")
Dim Msg ':Set Msg= CreateObject("Outlook.MailItem")
Set Msg = OL.CreateItemFromTemplate("C:\test.msg")
'MsgBox Msg.Subject
Msg.saveAs "C:\test.txt", olDoc
'The above statement will save the contents of .msg file into the designate .txt file
Set OL = Nothing
Set Msg = Nothing
Once the .txt file is created use it as required for your computations.

Resources