Using equivalent bash script for Windows batch file

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

Using equivalent bash script for Windows batch file

#1 Post by nic007 »

I have a Windows commandline application which I want to run with WINE. It's a text to mp3 converter. I have a Windows batch script which I want to use to convert all the text files in a folder to mp3. This is the batch script:

set filter="C:\Program Files\2nd Speech Center\Documents\*.txt"
for %%i in (%filter%) do ttscmd.exe /ttm "%%i" -s 162 -w 128 -r 16 -b 16 -q 7

In my Puppy setup the *.txt files will be in /mnt/sda3/Audiobook and
ttscmd.exe will be in "/2nd Speech Center"

I can get the commandline to work for the conversion of one file at a time, eg: wine "/2nd Speech Center/ttscmd.exe" /ttm "/mnt/sda3/Audiobooks/01 The Fallen - David Baldacci.txt" "/mnt/sda3/Audiobooks/01 The Fallen - David Baldacci.mp3" -s 162 -w 128 -r 16 -b 16 -q 7

I need a bash script for this and any help will be appreciated as I just can't get it working. Thanks.

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#2 Post by jafadmin »

You need something like this:

Code: Select all

#!/bin/bash

# This command produces the list of .txt files
LIST=$(ls /mnt/sda3/Audiobooks/*.txt)

IFS=$'\n'

for Line in $LIST  # Loop through the list
do
	MP3_Out=$(echo $Line | cut -d '.' -f1)".mp3"  # change .txt extension to .mp3

	wine "/2nd Speech Center/ttscmd.exe" /ttm "$Line" "$MP3_Out" -s 162 -w 128 -r 16 -b 16 -q 7 
done
Should get you close..

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#3 Post by nic007 »

Unfortunately that didn't work. The /ttm argument in the command already directs that the output will be in mp3 format. I don't know if that helps any. The script must find the .txt files and the mp3 output names must be the same as those of the corresponding .txt files, so eg: 1.txt becomes 1.mp3 after text to speech conversion and so on.

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#4 Post by puppy_apprentice »

Your batch:

Code: Select all

set filter="C:\Program Files\2nd Speech Center\Documents\*.txt"
for %%i in (%filter%) do (
     ttscmd.exe /ttm "%%i" -s 162 -w 128 -r 16 -b 16 -q 7
)
Try this or ask mushero:

Code: Select all

#!/bin/bash

# This command produces the list of .txt files
LIST=$(ls /mnt/sda3/Audiobooks/*.txt)

IFS=$'\n'

for Line in $LIST  # Loop through the list
do
   wine "/2nd Speech Center/ttscmd.exe" /ttm "$Line" -s 162 -w 128 -r 16 -b 16 -q 7
done 

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#5 Post by nic007 »

I did omit that line in one of my tries, didn't work either.

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#6 Post by puppy_apprentice »

Go to:

Code: Select all

/mnt/sda3/Audiobooks/
and open console there (in ROX filer `) and try:

Code: Select all

#!/bin/bash

# This command produces the list of .txt files
LIST=$(ls *.txt)

IFS=$'\n'

for Line in $LIST  # Loop through the list
do
   wine "/2nd Speech Center/ttscmd.exe" /ttm "$Line" -s 162 -w 128 -r 16 -b 16 -q 7
done

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#7 Post by musher0 »

puppy_apprentice wrote:Try this or ask mushero:

Code: Select all

#!/bin/bash

# This command produces the list of .txt files
LIST=$(ls /mnt/sda3/Audiobooks/*.txt)

IFS=$'\n'

for Line in $LIST  # Loop through the list
do
   wine "/2nd Speech Center/ttscmd.exe" /ttm "$Line" -s 162 -w 128 -r 16 -b 16 -q 7
done 
No-no, Puppy_Apprentice.
"Tray" this. ;) (Inside joke between Puppy_Apprentice and me!!!)

As for me, I'd do it the old-fashioned way:
Enter the directory
Create a one-column list of the files
Loop through the files list to play them
Remove the list file when finished.

Code: Select all

cd /mnt/sda3/Audiobooks 
ls -1 *.txt > list # No need to use or alter IFS if using < ls -1 >.
# Change "list" to something more telling if you wish.

while read line;do
     wine "/2nd Speech Center/ttscmd.exe" /ttm "$line" -s 162 -w 128 -r 16 -b 16 -q 7 
done < list # We do the job.

rm -f list # We clean up.
No guarantees ever in this business, but a good old while-do-done loop
should do the job, IMO.

IHTH
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
puppy_apprentice
Posts: 299
Joined: Tue 07 Feb 2012, 20:32

#8 Post by puppy_apprentice »

Another try:

1) Make a script try_me.sh. Put at the first line:

Code: Select all

#!/bin/bash
2) Save this:

Code: Select all

#!/bin/bash

# This command produces the list of .txt files
LIST=$(ls /mnt/sda3/Audiobooks/*.txt)

IFS=$'\n'

for Line in $LIST  # Loop through the list
do
   MP3_Out=$(echo $Line | cut -d '.' -f1)".mp3"  # change .txt extension to .mp3
   echo wine \""/2nd Speech Center/ttscmd.exe"\" /ttm "$Line" "$MP3_Out" -s 162 -w 128 -r 16 -b 16 -q 7 >>try_me.sh
done
as script eg. intermediate.sh in the same dir with try_me.sh, you should get script like your working one liner example:

Code: Select all

#!/bin/bash
wine "/2nd Speech Center/ttscmd.exe" /ttm "/mnt/sda3/Audiobooks/01 The Fallen - David Baldacci.txt" "/mnt/sda3/Audiobooks/01 The Fallen - David Baldacci.mp3" -s 162 -w 128 -r 16 -b 16 -q 7
wine "/2nd Speech Center/ttscmd.exe" /ttm "/mnt/sda3/Audiobooks/02 xxxx - yyyy.txt" "/mnt/sda3/Audiobooks/02 xxxx - yyyy.mp3" -s 162 -w 128 -r 16 -b 16 -q 7
etc.
3) Execute try_me.sh

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#9 Post by nic007 »

Sorry guys I made a mistake. The text files are actually in /mnt/sda3/AudioBooks and not /mnt/sda3/Audiobooks. Both jafadmin's and musher0's scripts worked well. I just added another command to also delete the text files in the folder after conversion. Thanks for the input.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#10 Post by musher0 »

My pleasure!
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#11 Post by some1 »

I dont have ttscmd.exe .

Nic007 wanted a conversion from txt to mp3.

Nic007 wrote that both jafadmins and Musher0s code works.


Jafadmins wine call specifies xxx.txt xxx.mp3
Musher0s wine call just specifies the xxx.txt

=============

Some questions:

Q:Does Musher0s wine-call produce persistent mp3-files? (a default behaviour of ttscmd.exe ?)
---
Q:Will
/TMPDIR/xxx.txt /PERSISTENTDIR/xxx.mp3
i.e jafadmins approach with different in-/output PATHS
work?

------

Nic007?
Q: Has puppy_apprentices code- try_me.sh-been tested with real txt-files?
(By the look -I guess it will run - but I cannot test it)`

----

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#12 Post by musher0 »

Hi some1.

It's not "my" wine call! I just plucked it off Puppy-Apprentice's script. Please
ask him? Also nic007 said that my script worked ok.

As a side note, I now prefer the opus musical format to any other.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply