|
Answer» Hello & Thanks , I have a .bat to do tts (see below) . Works great for typing a text to speak . But I want to modify it so that it can get the text from a *.txt file . Can someone tell me how to do that ? Thanks
echo off title Text to Speech Conversion color 0a
rem The user decides what to convert here :input cls echo What do you want the computer to convert into speech? echo. set /p text=
rem Making the temp file :num set num=%random% if exist temp%num%.vbs goto num echo ' > "temp%num%.vbs" echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp%num%.vbs" echo speech.speak "%text%" >> "temp%num%.vbs" start temp%num%.vbs pause del temp%num%.vbs goto input This is dictation. That looks very clever. I never thought about using VBScript to start up the speech recognition engine that is built into MICROSOFT Windows. If you're using Windows 10, there already are applications that make it easy to convert speech to text. Here is one of many such references. http://www.pcworld.com/article/2834835/stop-typing-and-start-dictating-documents-in-windows.html . Sorry, I'm not able to help you with the script. For one thing, it's much more difficult for me to write scripts that used to be now that I am getting old. Moreover, I don't feel motivated to write a batch file to start up the speech to text converter. It's easier for me just click my mouse on a suitable application and start dictating. Besides Windows 10, speech to text conversion has been around for a while and there are some programs available at very low costs that do it for you. But if you're using Windows 10, you don't have to buy anything extra. There are apps in the Windows store for free that will make it easier. But don't let me discourage you. In your post you should also include some information about which version of Windows you're using and also do you have all the libraries installed on your computer. I mean the libraries that are needed for the Microsoft .NET stuff. Here's a question. Would it not be possible to write a program in Visual Studio rather than using VBScript? Hopefully one of the other members can help you with your script. The batch file is superfluous. It doesn't seem to serve any purpose here. Except for retrieving input; all of thsi can be done in VBS or at the very least there is no reason to constantly be generating a VBScript from Batch for the purpose when a VBScript can simply be made generic.
Code: [Select]If WScript.Arguments.Count > 0 Then
Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.FileExists(WScript.Arguments(0)) Then Set tfile = FSO.OpenTextFile(WScript.Arguments(0)) TextSay = tfile.ReadAll() Else ReDim arr(WScript.Arguments.Count-1) For i = 0 To WScript.Arguments.Count-1 arr(i) = WScript.Arguments(i) Next TextSay = Join(arr," ") End If
Set speech = CreateObject("SAPI.spVoice") speech.Speak TextSay Else
'No arguments, nothing to do... End If
You can invoke .vbs files directly. If this was "say.vbs" for example:
Code: [Select]say.vbs hello there
Would say "hello there"
and if there was a text file, you can give the file path:
Code: [Select]say.vbs D:\saythis.txt
And if the specified file exists it will say the contents of the text file. From a batch, or the prompt, the useful (and British!) Nircmd.exe toolbox utility INCLUDES the Speak option, which can take various input parameters including the clipboard, directly quoted text, or name of an xml or text file. You can also specify rate, volume, and a WAV output file instead of direct speaker output, with a big choice of file format parameters - bit rate, etc.
speak [type] [text/Filename] {rate} {volume} {.wav Output Filename} {Output Format}
Examples:
Nircmd speak text ~$clipboard$ Nircmd speak text "Please visit the Web site of NirSoft at http://www.nirsoft.net" 2 80 Nircmd speak file "c:\temp\speak1.txt" Nircmd speak file "c:\temp\speak1.txt" 0 100 "c:\temp\speak.wav" 48kHz16BitStereo
http://nircmd.nirsoft.net/speak.html
You can play around with what you feed it - it pronounces text in an odd LITERAL way, e.g. 'chocolate" comes out as "chocolatty" - I had to send "choclet" to make it approximate to the UK pronunciation, and judicious insertion of pauses can help clarity.
Quote from: Salmon Trout on December 15, 2016, 01:02:25 PM From a batch, or the prompt, the useful (and British!) Nircmd.exe toolbox utility includes the Speak option
Thanks , I am currently using Nircmd , and I want to get away from it .
Quote from: Geek-9pm on December 15, 2016, 12:24:26 PMThis is dictation....... the other members can help you with your script.
Thanks , yes , that's for dictation . I am currently using Nirsoft's NirCmd program , and I want to get away from that .Hi BC_Programmer , I tried all your code , each as a .vbs file , then as a .bat file . Sorry to say , but couldn't get any of them to work .
I did find this 2 LINER , and it works great . But again how can I tell it to read input from a .txt file ? What is the syntax of such a command ? Thanks 2 liner as a .vbs file : set speech = Wscript.CreateObject("SAPI.spVoice") speech.speak "hello" The first one is a vbs file. you invoke it on the command line, or in ta batch file, with the other two being examples of how to use it.
Hello & Thanks , Could someone please show me how to get input from this script FROM a speakThis.txt file .
set speech = Wscript.CreateObject("SAPI.spVoice") speech.speak "hello"
ThanksAhhhh... At last I have an ANSWER:
Code: [Select]Const ForReading = 1 Dim fso Set fso = CreateObject("Scripting.FileSystemObject") Dim f Set f = fso.OpenTextFile("C:\TextToSpeech\speakThis.txt", ForReading) Dim text text = f.ReadAll set speech = Wscript.CreateObject("SAPI.spVoice") speech.speak text f.Close
|