Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 17 Nov 2018, 21:46
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Using equivalent bash script for Windows batch file
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [12 Posts]  
Author Message
nic007


Joined: 13 Nov 2011
Posts: 2677
Location: Cradle of Humankind

PostPosted: Tue 09 Oct 2018, 02:58    Post subject:  Using equivalent bash script for Windows batch file  

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.
Back to top
View user's profile Send private message 
jafadmin

Joined: 19 Mar 2009
Posts: 857

PostPosted: Wed 10 Oct 2018, 10:35    Post subject:  

You need something like this:
Code:

#!/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..
Back to top
View user's profile Send private message 
nic007


Joined: 13 Nov 2011
Posts: 2677
Location: Cradle of Humankind

PostPosted: Wed 10 Oct 2018, 11:24    Post subject:  

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.
Back to top
View user's profile Send private message 
puppy_apprentice


Joined: 07 Feb 2012
Posts: 212

PostPosted: Wed 10 Oct 2018, 11:42    Post subject:  

Your batch:
Code:
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:
#!/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
Back to top
View user's profile Send private message 
nic007


Joined: 13 Nov 2011
Posts: 2677
Location: Cradle of Humankind

PostPosted: Wed 10 Oct 2018, 11:52    Post subject:  

I did omit that line in one of my tries, didn't work either.
Back to top
View user's profile Send private message 
puppy_apprentice


Joined: 07 Feb 2012
Posts: 212

PostPosted: Wed 10 Oct 2018, 12:10    Post subject:  

Go to:
Code:
/mnt/sda3/Audiobooks/


and open console there (in ROX filer `) and try:

Code:
#!/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
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 12980
Location: Gatineau (Qc), Canada

PostPosted: Wed 10 Oct 2018, 12:15    Post subject:  

puppy_apprentice wrote:
Try this or ask mushero:
Code:
#!/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. Wink (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:
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
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
puppy_apprentice


Joined: 07 Feb 2012
Posts: 212

PostPosted: Wed 10 Oct 2018, 14:02    Post subject:  

Another try:

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

Code:
#!/bin/bash


2) Save this:
Code:
#!/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:
#!/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
Back to top
View user's profile Send private message 
nic007


Joined: 13 Nov 2011
Posts: 2677
Location: Cradle of Humankind

PostPosted: Wed 10 Oct 2018, 14:32    Post subject:  

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.
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 12980
Location: Gatineau (Qc), Canada

PostPosted: Wed 10 Oct 2018, 14:46    Post subject:  

My pleasure!
_________________
musher0
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
some1

Joined: 17 Jan 2013
Posts: 87

PostPosted: Mon 15 Oct 2018, 05:02    Post subject:  

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)`

----
Back to top
View user's profile Send private message 
musher0

Joined: 04 Jan 2009
Posts: 12980
Location: Gatineau (Qc), Canada

PostPosted: Fri 19 Oct 2018, 15:15    Post subject:  

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
~~~~~~~~~~
Je suis né pour aimer et non pas pour haïr. (Sophocle) /
I was born to love and not to hate. (Sophocles)
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [12 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0613s ][ Queries: 12 (0.0100s) ][ GZIP on ]