Search code examples
windowsbatch-filewindows-10batch-processing

Windows .bat script can't read ! character from text what to do?


Here the bat script

set "PROCESSED_TEXT="

REM Read the contents of processed_speech.txt line by line
for /F "usebackq delims=" %%A in ("processed_speech.txt") do (
    set "LINE=%%A"
    if not "!PROCESSED_TEXT!"=="" set "PROCESSED_TEXT=!PROCESSED_TEXT! "
    set "PROCESSED_TEXT=!PROCESSED_TEXT!%%A"
)

echo Processed text: !PROCESSED_TEXT!

Here processed_speech.txt file

Hello and welcome, one and all! Today, we are embarking on an exciting journey through the most intuitive and comprehensive deep voice cloning tutorial you will find anywhere. Our mission?
To show you how to train your voice and generate hours of speech in just a single click.
This tutorial is built on open source projects, meaning it is entirely free and runs directly on your own computer.
You may have heard of pricey services like Eleven Labs that offer voice training and speech synthesis.
But why break the bank when you can achieve stunning results without any prior technical knowledge? That is right, all you need to do is follow along with me.
Interestingly, the voice you are hearing now is a deep clone! Drop a comment to let me know what you think, and who it reminds you of.
We will switch to my natural voice after this introduction, so stay tuned!
Every step of this tutorial is meticulously detailed, both in this video and in the accompanying GitHub introduction file.
This file is your one stop shop, packed with all the information you will need. You will find the link in the description and the pinned comment, so don't forget to check it out.
Are you wondering why this tutorial stands out from the rest? It is because, with a simple drag and drop, your speech file can be transformed into your complete training data.
Thanks to our chosen user friendly graphical user interface, you can set up all training parameters and launch your training with just a single click.
Once the training is complete, my specially developed scripts will enable you to convert an entire text file into speech, again, just by dragging and dropping.
What is more, each step is clearly documented and demonstrated in this tutorial video, making it incredibly easy for you to follow along.
This tutorial offers a seamless and convenient process unlike any other. So, are you ready to jump into the world of voice cloning? Let's get started!

Here the output

 Hello and welcome, one and all Today, we are embarking on an exciting journey through the most intuitive and comprehensive deep voice cloning tutorial you will find anywhere. Our mission? To show you how to train your voice and generate hours of speech in just a single click. This tutorial is built on open source projects, meaning it is entirely free and runs directly on your own computer. You may have heard of pricey services like Eleven Labs that offer voice training and speech synthesis. But why break the bank when you can achieve stunning results without any prior technical knowledge? That is right, all you need to do is follow along with me. Interestingly, the voice you are hearing now is a deep clone Drop a comment to let me know what you think, and who it reminds you of. We will switch to my natural voice after this introduction, so stay tuned Every step of this tutorial is meticulously detailed, both in this video and in the accompanying GitHub introduction file. This file is your one stop shop, packed with all the information you will need. You will find the link in the description and the pinned comment, so don't forget to check it out. Are you wondering why this tutorial stands out from the rest? It is because, with a simple drag and drop, your speech file can be transformed into your complete training data. Thanks to our chosen user friendly graphical user interface, you can set up all training parameters and launch your training with just a single click. Once the training is complete, my specially developed scripts will enable you to convert an entire text file into speech, again, just by dragging and dropping. What is more, each step is clearly documented and demonstrated in this tutorial video, making it incredibly easy for you to follow along. This tutorial offers a seamless and convenient process unlike any other. So, are you ready to jump into the world of voice cloning? Let's get started

You see in the output there is !

I can't solve it. Thank you


Solution

  • You could solve it with a some variable manipulations

    @Echo off
    Setlocal EnableDelayedExpansion
    set "PROCESSED_TEXT="
    
    REM Read the contents of a file line by line
    for /F "delims=" %%A in ('findstr "^" text.txt') do (
        Setlocal DisableDelayedExpansion
        set "LINE=%%A"
        Setlocal EnableDelayedExpansion
        set "line=!line:*:=!"
        set "line=!line:"=""q!"
        set "line=!line:^=^^!"
        call set "line=%%line:^!=""c^!%%"
        set "line=!line:""c=^!"
        set "line=!line:""q="!"
        FOR /F "delims=" %%B in (""!line!"") do (
          endlocal
          endlocal
          if defined PROCESSED_TEXT (
            set "PROCESSED_TEXT=!PROCESSED_TEXT! %%~B" !
          ) ELSE (
            set "PROCESSED_TEXT=%%~B" !
          )
        )
    )
    
    echo Processed text: !PROCESSED_TEXT!
    

    A bit overkill for your problem, but it can handle empty lines and lines beginning with a semi colon.
    Also text containing quotes, carets and exclamation marks.

    The main goal is to add a single caret in front of each exclamation mark, when it's used in set "PROCESSED_TEXT=!PROCESSED_TEXT! %%~B" !, because the expansion of %%~B then removes the caret and escapes the exclamation mark.
    But to avoid problems if carets are in the text itself, it's necessary to double them.
    The exclamation mark in set "PROCESSED_TEXT=%%~B" ! looks strange, but is necessary to avoid problems when in the first line is only a caret.