Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: cscript text-to-speech , improve script ?  (Read 6948 times)

0 Members and 1 Guest are viewing this topic.

vmars.usa

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Other
    cscript text-to-speech , improve script ?
    « on: December 15, 2016, 11:54:53 AM »
    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

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: cscript text-to-speech , improve script ?
    « Reply #1 on: December 15, 2016, 12:24:26 PM »
    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.  :)

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: cscript text-to-speech , improve script ?
    « Reply #2 on: December 15, 2016, 12:42:13 PM »
    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.
    I was trying to dereference Null Pointers before it was cool.

    Salmon Trout

    • Guest
    Re: cscript text-to-speech , improve script ?
    « Reply #3 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, 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.

    vmars.usa

      Topic Starter


      Greenhorn

      • Experience: Beginner
      • OS: Other
      Re: cscript text-to-speech , improve script ?
      « Reply #4 on: December 15, 2016, 03:12:31 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 .

      vmars.usa

        Topic Starter


        Greenhorn

        • Experience: Beginner
        • OS: Other
        Re: cscript text-to-speech , improve script ?
        « Reply #5 on: December 15, 2016, 03:16:00 PM »
        This 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 .

        vmars.usa

          Topic Starter


          Greenhorn

          • Experience: Beginner
          • OS: Other
          Re: cscript text-to-speech , improve script ?
          « Reply #6 on: December 15, 2016, 04:07:58 PM »
          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"

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: cscript text-to-speech , improve script ?
          « Reply #7 on: December 15, 2016, 04:33:48 PM »
          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.

          I was trying to dereference Null Pointers before it was cool.

          vmars.usa

            Topic Starter


            Greenhorn

            • Experience: Beginner
            • OS: Other
            Re: cscript text-to-speech , improve script ?
            « Reply #8 on: December 19, 2016, 09:42:00 AM »
            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"

            Thanks

            vmars.usa

              Topic Starter


              Greenhorn

              • Experience: Beginner
              • OS: Other
              Re: cscript text-to-speech , improve script ?
              « Reply #9 on: December 19, 2016, 06:30:35 PM »
              Ahhhh...
              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