0

This is a matter of someone totally lay (in this case I am a layman). I have been asking this question. And I used this answer to compose a bash script that downloads translate google multiple tts segments, convert them to mp3 format file and merge them into single file called page.mp3. You can see how this works at these links (GitHub, GitHub Wiki, Vimeo).

What I want now is to build (and include in full.sh) a command that reads a file containing text that I want to be made into tts (I don't want to copy the translation just using the tts service) and then save the file har generated without me having to open Firefox, wait for the original text to be converted to a tts segment url and then save har.file. I really am a layperson in web resources, regex, etc. So I don't have any MWE to start a post by normal standards. But I hope for some suggestion or solution to this goal.

1 Answer 1

0

I was unaware of the gtts tool, although I suspected this before posting this question:

So here is an alternative that works:

My experience bellow:

For a simple translation of a file saved locally on your machine you can use the following command order:

gtts-cli -l pt -f <file>  -o  <name.output>.mp3

four different text files to translate, in both cases, the text files were saved without using any extension.:

Capitule 1 from Book: files (pages): 1 and 2

Capitule 2 from book: files (pages): 3 and 4

Create a finish.sh file in the folder where files 1, 2,3, and 4 are, and place the following code inside the finish.sh file:

#!/bin/bash
awk -F, '{print $1"3;"}' pre.full.gtts.txt > mp3.txt; awk '/\.mp3/{sub(".mp3",++count"&")} 1'  mp3.txt > pre.count.txt; awk '/\-o/{sub(" -o",++count"&")} 1'  pre.count.txt > pre.count1.txt; awk 'ORS=" "' pre.count1.txt > hor.mp3.txt; awk -F, '{print "#!/bin/bash \n "$1" "$2""}' hor.mp3.txt > gtts.sh; chmod +x gtts.sh; export PATH=$PATH:$pwd; gtts.sh

Also create a pre.full.gtts.txt file and save in the same folder with follow code:

gtts-cli -l pt -f   -o  .mp
gtts-cli -l pt -f   -o  .mp
gtts-cli -l pt -f   -o  .mp
gtts-cli -l pt -f   -o  .mp
gtts-cli -l pt -f   -o  .mp

Note: The number of lines (gtts-cli -l en -f -o .mp) need not be exactly the number of text files to translate but cannot be less than this number.

Case 1: Just generating the respective mp3 files from each text page: Enter the terminal into the folder where you saved files 1, 2, 3 and 4 and make the following command: $ chmod + x finish.sh; export PATH = $ PATH: $ pwd and then execute $ finish.sh.

Case 2: Saving files 1, 2, 3 and 4 together in a single file called book.mp3. I left in the folder only the text files 1, 2, 3 and 4. Then create a file in this folder called full.end.sh and put the following code into it and save:

#!/bin/bash
awk -F, '{print $1"3;"}' pre.full.gtts.txt > mp3.txt; awk '/\.mp3/{sub(".mp3",++count"&")} 1'  mp3.txt > pre.count.txt; awk '/\-o/{sub(" -o",++count"&")} 1'  pre.count.txt > pre.count1.txt; awk 'ORS=" "' pre.count1.txt > hor.mp3.txt; awk -F, '{print "#!/bin/bash \n "$1" "$2""}' hor.mp3.txt > gtts.sh; chmod +x gtts.sh; export PATH=$PATH:$pwd; gtts.sh

printf '#!/bin/bash'> oz.txt; awk -F, '{print $1"\n seq 1 4 > ozn1.txt"}' oz.txt > ozn.sh;chmod +x ozn.sh; ozn.sh; awk -F, '{print $1".mp3"}' ozn1.txt > ozn2.txt; awk 'ORS=" "' ozn2.txt > ozn3.txt; awk -F, '{print "#!/bin/bash \n cat "$1" > book.mp3"}' ozn3.txt > ozn4.sh; chmod +x ozn4.sh; ozn4.sh

Note 1: You must also have the pre.full.gts.txt file inside the Case 2 folder. Note 2: Note that the file range we want to put inside book.mp3 is set in the code snippet print $1"\n seq 1 4 . Run the finish.sh command (assuming you had already done $ export PATH=$PATH:$pwd; chmod + x finish.sh

Case 3: Saving pages 1 and 2 in a single mp3 file we'll call capitule1.mp3, and, saving pages 3 and 4 in another single mp3 file we'll call capitule2.mp3 To do so just add one more line (printf '#!/bin/bash'> oz.txt; awk -F, '{print $1"\n seq 1 4 > ozn1.txt"}' oz.txt > ozn.sh;chmod +x ozn.sh; ozn.sh; awk -F, '{print $1".mp3"}' ozn1.txt > ozn2.txt; awk 'ORS=" "' ozn2.txt > ozn3.txt; awk -F, '{print "#!/bin/bash \n cat "$1" > book.mp3"}' ozn3.txt > ozn4.sh; chmod +x ozn4.sh; ozn4.sh) in the file full.end.sh and change the range of the respective pages belonging to each chapter in the excerpt (e.g.: print $1"\n seq 3 4) e rename book.mp3 to capitule2.mp3 and the execute $ full.end.sh. See what the code will look like full.end.sh:

#!/bin/bash
awk -F, '{print $1"3;"}' pre.full.gtts.txt > mp3.txt; awk '/\.mp3/{sub(".mp3",++count"&")} 1'  mp3.txt > pre.count.txt; awk '/\-o/{sub(" -o",++count"&")} 1'  pre.count.txt > pre.count1.txt; awk 'ORS=" "' pre.count1.txt > hor.mp3.txt; awk -F, '{print "#!/bin/bash \n "$1" "$2""}' hor.mp3.txt > gtts.sh; chmod +x gtts.sh; export PATH=$PATH:$pwd; gtts.sh

printf '#!/bin/bash'> oz.txt; awk -F, '{print $1"\n seq 1 2 > ozn1.txt"}' oz.txt > ozn.sh;chmod +x ozn.sh; ozn.sh; awk -F, '{print $1".mp3"}' ozn1.txt > ozn2.txt; awk 'ORS=" "' ozn2.txt > ozn3.txt; awk -F, '{print "#!/bin/bash \n cat "$1" > capitule1.mp3"}' ozn3.txt > ozn4.sh; chmod +x ozn4.sh; ozn4.sh

printf '#!/bin/bash'> oz.txt; awk -F, '{print $1"\n seq 3 4 > ozn1.txt"}' oz.txt > ozn.sh;chmod +x ozn.sh; ozn.sh; awk -F, '{print $1".mp3"}' ozn1.txt > ozn2.txt; awk 'ORS=" "' ozn2.txt > ozn3.txt; awk -F, '{print "#!/bin/bash \n cat "$1" > capitule2.mp3"}' ozn3.txt > ozn4.sh; chmod +x ozn4.sh; ozn4.sh

Thankx!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .