Page 1 of 1
Using equivalent bash script for Windows batch file
Posted: Tue 09 Oct 2018, 06:58
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.
Posted: Wed 10 Oct 2018, 14:35
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..
Posted: Wed 10 Oct 2018, 15:24
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.
Posted: Wed 10 Oct 2018, 15:42
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
Posted: Wed 10 Oct 2018, 15:52
by nic007
I did omit that line in one of my tries, didn't work either.
Posted: Wed 10 Oct 2018, 16:10
by puppy_apprentice
Go to:
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
Posted: Wed 10 Oct 2018, 16:15
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
Posted: Wed 10 Oct 2018, 18:02
by puppy_apprentice
Another try:
1) Make a script try_me.sh. Put at the first line:
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
Posted: Wed 10 Oct 2018, 18:32
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.
Posted: Wed 10 Oct 2018, 18:46
by musher0
My pleasure!
Posted: Mon 15 Oct 2018, 09:02
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)`
----
Posted: Fri 19 Oct 2018, 19:15
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.