Windows .bat 脚本无法读取文本中的 ! 字符,应该怎么办?

huangapple go评论70阅读模式
英文:

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

问题

Here is the translated content without any code:

"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!"

I have removed the extraneous characters, and the text is now clean.

英文:

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

答案1

得分: 2

以下是代码的翻译部分:

您可以通过一些变量操作来解决它

@Echo off
Setlocal EnableDelayedExpansion
set "PROCESSED_TEXT="

REM 逐行读取文件的内容
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!

这是您提供的代码的中文翻译。

英文:

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.

答案2

得分: 1

Here's the translated code portion:

@ECHO OFF
SETLOCAL DISABLEDELAYEDEXPANSION

SET "sourcedir=c:6x"
SET "destdir=u:\your results"
SET "filename1=%sourcedir%\q76220084.txt"
SET "outfile=%destdir%\outfile.txt"

(
FOR /f "usebackq delims=" %%e IN ("%filename1%") DO (
 <NUL set /p "=%%e "
)
)>"%outfile%"

TYPE "%outfile%"
GOTO :EOF

And here's the translated code portion with the additional lines:

@ECHO OFF
SETLOCAL DISABLEDELAYEDEXPANSION

SET "sourcedir=c:6x"
SET "destdir=u:\your results"
SET "filename1=%sourcedir%\q76220084.txt"
SET "outfile=%destdir%\outfile.txt"

(
FOR /f "usebackq delims=" %%e IN ("%filename1%") DO (
 <NUL set /p "=%%e "
)
echo/
)>"%outfile%"

TYPE "%outfile%"
FOR /f "usebackq delims=" %%e IN ("%outfile%") DO SET "contents=%%e"
ECHO ===
ECHO %contents:~0,-1%

GOTO :EOF

Please note that this translation is provided without any changes to the code logic.

英文:
@ECHO OFF
SETLOCAL DISABLEDELAYEDEXPANSION

SET &quot;sourcedir=c:6x&quot;
SET &quot;destdir=u:\your results&quot;
SET &quot;filename1=%sourcedir%\q76220084.txt&quot;
SET &quot;outfile=%destdir%\outfile.txt&quot;

(
FOR /f &quot;usebackqdelims=&quot; %%e IN (&quot;%filename1%&quot;) DO (
 &lt;NUL set /p&quot;=%%e &quot;
)
)&gt;&quot;%outfile%&quot;

TYPE &quot;%outfile%&quot;

GOTO :EOF

You would need to change the value assigned to sourcedir to suit your circumstances. The listing uses a setting that suits my system.

I used a file named q76220084.txt containing your data for my testing.

Obviously, you would need to read the output file into a variable if you want to have it in a variable.

Note that there will be a space at the end of the file/variable, and naturally the batch string-size limits need to be observed.

@ECHO OFF
SETLOCAL DISABLEDELAYEDEXPANSION

SET &quot;sourcedir=c:6x&quot;
SET &quot;destdir=u:\your results&quot;
SET &quot;filename1=%sourcedir%\q76220084.txt&quot;
SET &quot;outfile=%destdir%\outfile.txt&quot;

(
FOR /f &quot;usebackqdelims=&quot; %%e IN (&quot;%filename1%&quot;) DO (
 &lt;NUL set /p&quot;=%%e &quot;
)
echo/
)&gt;&quot;%outfile%&quot;

TYPE &quot;%outfile%&quot;
FOR /f &quot;usebackqdelims=&quot; %%e IN (&quot;%outfile%&quot;) DO SET &quot;contents=%%e&quot;
ECHO ===
ECHO %contents:~0,-1%

GOTO :EOF

Note that if the filename does not contain separators like spaces, then both usebackq and the quotes around %outfile% can be omitted on the for line.

The echo/ adds a terminal newline to the file.

The for to set contents will read the file for the sample data. set /p contents=&lt;&quot;%outfile%&quot; would truncate the read at 1024 characters.

huangapple
  • 本文由 发表于 2023年5月10日 23:12:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76220084.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定