Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9270171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:18:14+00:00 2026-06-18T15:18:14+00:00

A while ago I made a function that you can call from the command

  • 0

A while ago I made a function that you can call from the command prompt or any batch file (it was just for fun, I don’t see how it could be useful). It basically just makes your (Microsoft) computer speak whatever you wrote in as the parameter.
I recently got some inspiration to add a switch to it where it would read the contents of a file. My standalone script worked, but when I added it to my function, it didn’t work as I would have liked.

Here’s the code:

@echo off & setlocal enabledelayedexpansion

if "%~1"=="/?" (
    echo.
    echo TALK "Text" [Parameters]
    echo.
    echo Text - The phrase you want to be spoken.
    echo.
    echo [Parameters]:
    echo              /f - Read the contents of a file. "Text" changes to the file path.
    echo.
    endlocal
    exit /b
)

if "%~2 X" equ "/f X" (

    if not exist %~1 (
        echo File does not exist or cannot be found.
        endlocal
        exit /b
    )

    set cont= 
    for /f "delims=" %%i in (%~1) do set cont=!cont! %%i
    :b
    echo Set a = Wscript.CreateObject("SAPI.SpVoice") > "Talk.vbs"
    echo a.speak "%cont%" >> "Talk.vbs"
    start /WAIT Talk.vbs
    del Talk.vbs
    endlocal
    exit /b
)

set text=%~1

echo set speech = Wscript.CreateObject("SAPI.spVoice") > "talk.vbs"
echo speech.speak "%text%" >> "talk.vbs"
start /WAIT talk.vbs
del Talk.vbs
endlocal
exit /b

Unfortunately I don’t have working function code (before I added the /f switch).

This is a last resort for me as I’ve edited it heavily and scoured the code for any give away as to what the problem might be.

Another bad thing is that I didn’t take note of what I changed, so I can’t exactly tell you what I’ve tried. I can tell you what the outputs are though.

The first time I tried, it gave the output The syntax of the command is incorrect.

It’s now at the point where the original function (just converting text to speech) doesn’t work anymore. The contents of the file Talk.vbs (which was made during the process) is a.speak "".

I’ll keep updating my attempts, but knowing me it’s something really simple that I’ve overlooked.

–EDIT–
At the suggestion of someone, I put carats before the square brackets in the syntax section. Nothing changed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:18:15+00:00Added an answer on June 18, 2026 at 3:18 pm

    Along with escaping the parenthesis you also had to surround if exist %~1 in quotes in case of a argument of "some words I want it to say". Also cleaned it up a bit. Code at the bottom, but first an explanation.

    If you looked at talk.vbs before it was deleted you would see this:

    a.speak "!cont! contents of the file here" 
    

    This is because of this code:

    for /f "delims=" %%i in (%~1) do set cont=!cont! %%i
    :b
    echo Set a = Wscript.CreateObject("SAPI.SpVoice") > "Talk.vbs"
    

    If you turned echo on and watched the code you would see the last unescaped ) was taking the contents of the for loop and including it in the redirect.

    Corrected and cleaned code:

    @echo off & setlocal enabledelayedexpansion
    if "%~1"=="/?" (
        echo.
        echo TALK "Text" [Parameters]
        echo.
        echo Text - The phrase you want to be spoken.
        echo.
        echo [Parameters]:
        echo              /f - Read the contents of a file. "Text" changes to the file path.
        echo.
        endlocal
        exit /b
    )
    set text=
    if [%2]==[/f] (
        if exist "%~1" (
            for /f "usebackq delims=" %%i in (%1) do set text=!text! %%i
        ) else (
            endlocal
            exit /B
        )
    )
    if [%2]==[] set text=%~1
    
    echo set speech = Wscript.CreateObject^("SAPI.spVoice"^) > "talk.vbs"
    echo speech.speak "%text%" >> "talk.vbs"
    cscript //NoLogo //B talk.vbs
    del Talk.vbs
    endlocal
    exit /b
    

    Edit: fixed the for statement pointed out by Andriy M

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a script a while ago that wrote to a file, I did
So I have a validation script I made a while ago. I can pass
A while ago, I wrote a program that outputs any localhost or network database
I made a while ago some code that adds an object to my table
I made the transition from C++ to objective-C a while ago, and am now
I made a keystore a while ago for my Android apps but I can't
I have a cms I made for school a while ago that I am
Hi I made this site a while ago in my table days but have
I made an image slider using this plugin http://slidesjs.com/ while ago for a mobile
A while ago I did this to ignore changes to a file tracked by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.