Page 3 of 3 FirstFirst 123
Results 21 to 29 of 29

Thread: Need to convert PDF to Audio MP3

  1. #21
    Join Date
    Dec 2010
    Location
    Austin, Tx
    Beans
    2
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Need to convert PDF to Audio MP3

    This script is essential for turning .pdf, .txt, and .dat into .mp3 format using your default festival voice. I had been looking for something to convert ebooks into .mp3 for when i was on the go and this has proven to be the best open source solution available.

    Thank you for this script rennau80.

    P.S. This will take a long time for larger files such as an ebook for dummies, and if you anticipate having to "seek" in-between chapters then you should convert the original.pdf file into a .txt, and then break it into smaller .txt files for each chapter respectively.

  2. #22
    Join Date
    Aug 2007
    Beans
    38

    Re: Need to convert PDF to Audio MP3

    Hmmm..

    Love it mate thanks alot, i am having a problem though, i do no some python myself but no idea were to start with this, i couldnt even see in the script where it makes use of Festival lol.
    Would be great if you can break down the script / tutorial... i know its not a python coding fourm but still


    Anyway my error is:

    Code:
    pdf2mp3.py Hagak*.pdf
    converting pdf to ascii...
    sh: Syntax error: "(" unexpected
    start converting ascii to wav...
    sh: Syntax error: "(" unexpected
    converting to mp3...
    sh: Syntax error: "(" unexpected
    sh: Syntax error: "(" unexpected
    finished. don't forget to delete txt file if you don't need it
    Thanks in advance to anyone who can assist me


    EDIT/UPDATE:

    Just tried your v2, here is the error i got with v2.

    Code:
    pdf2mp3-v2.py -v en -f Haga*.pdf -o wayofsamuri.mp3
    converting pdf file: Hagakure (The Way of the Samurai).pdf to ASCII
    sh: Syntax error: "(" unexpected
    sh: Syntax error: "(" unexpected
    wayofsamuri.wav 
    Must pass filenames of wave files to merge.
    Usage: wavmerge [-o outfile] mergefiles...
    mv: cannot stat `merged.wav': No such file or directory
    Could not find "wayofsamuri.wav".
    1 0

    I assume its just having problems with symbols found in the pdf??
    Last edited by keyboardslave; April 16th, 2011 at 11:11 AM.
    ..."Life is like a roller coster, you think its real because thats how powerful your mind is; You choose to go on it. Its very loud and brightly colored, it has chills and thrills, but then you think 'is this real or just a ride"?

  3. #23
    Join Date
    Jul 2009
    Location
    CyberspacEastEngland
    Beans
    Hidden!
    Distro
    Ubuntu 13.10 Saucy Salamander

    Re: Need to convert PDF to Audio MP3

    fantastically useful script rennau 80

    the file comes out as a 24kbps mp3

    do you have any idea how to increase this to say 64 or 96 or 128 what would have to be modified in the script

    would love to know


    thanx shan
    Linux is Latin for off-the-beaten-track [◄►] ● Is there Voodoo in the machine?
    ShanArt ● Mark as SolvedXmms

  4. #24
    Join Date
    Nov 2011
    Beans
    1

    Re: Need to convert PDF to Audio MP3

    I made a script that converts pdf to mp3
    here it is:


    #!/bin/sh

    sudo apt-get install calibre #delete this line after running script
    sudo apt-get install espeak #delete this line after running script

    ebook-convert $1 book.txt

    espeak -f book.txt -w $2

    rm book.txt

    : save it in you bin folder and allow it to execute as a program,


    here is how to use.

    tta file.pdf file.mp3

    PS- it should also let you convert other ebook formats


    Enjoy
    Last edited by Gatmasta; April 21st, 2012 at 05:14 PM.

  5. #25
    Join Date
    Oct 2007
    Location
    wrong planet
    Beans
    746
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Need to convert PDF to Audio MP3

    This software called JSpeak makes gespeaker look pathetic, just saying.

    http://linuxinnovations.blogspot.com...to-speach.html
    Linux Advanced Guides and News!
    http://linuxinnovations.blogspot.com/

    Green means go, Yellow means faster, Red means don't stop.

  6. #26
    Join Date
    Aug 2012
    Beans
    4

    Re: Need to convert PDF to Audio MP3

    Wow! Thanks a million. I'm buried in readings right now for classes and haven't been able to even get through a fraction of them on a weekly basis. Now I will!

  7. #27
    Join Date
    Sep 2012
    Beans
    2

    Re: Need to convert PDF to Audio MP3

    Server not found can you attach the file again thanks

  8. #28
    Join Date
    Jan 2008
    Beans
    49

    Re: Need to convert PDF to Audio MP3

    This one works in a console. Converts txt only but there are many methods of extracting txt from pdf.

    I gave up the mbrola voices with espeak because at certain moment I realized they are less clear.

    At first they seem to sound nicer and more natural, but later you come to a conclusion that pure espeak is definitely more clear and you can listen faster.

    The problem with espeak+mbrola is that there are kind of micro-gaps between pronounced letters / words. The more I listened to it the less I liked it.

    Here's the script. Save it in a file and chmod +x it.
    The script accepst clear text only. No spaces in the filename.
    Usage is:

    script file.txt language_code - reads the file

    en for English and so on.

    or

    script file.txt language_code l

    encodes with lame. g encodes with gogo (faster. considerable difference if converting an unabridged book).


    Code:
    #!/bin/sh
    # txt2mp3 - convert text files to mp3 audio files (aka audiobooks)
    # v0.1
    #
    # (c) 2011 http://www.gnu.org/copyleft/gpl.html
    #
    # OBS.: install some pre-requisites first, with
    #       sudo apt-get install espeak lame gogo
    
    
    # espeak parameters
    speed=200	#160
    pitch=70	#50
    paragraph=40	#0
    gap=0
    lang=$2
    
    
    
    if [ "$1" = "" ]; then
        clear
        echo "No arguments. The usage is:"
        echo "$0 file.txt lang_code [g | l] "
        echo "g is for gogo, l for lame encoding."
        echo "Without g or l text will be played only."
        echo "Gogo is more than 2 times faster than lame "
        echo "and with speech encoding there are no "
        echo "substantial quality differences."
        echo "Language code is en, pl, ru and so on."
        echo "Refer to espeak manual."
        echo "Look inside the file to change speed, pitch etc."
        echo "because these are kind of fixed preferences."
        exit
    
    fi
    
    if [ "$2" = "" ]; then
        echo "Not enough arguments. The usage is:"
        echo "$0 file.txt lang_code [g | l]."
        echo "g is for gogo, l for lame encoding."
        echo "Without g or l text will be played only."
        echo "Gogo is more than 2 times faster than lame "
        echo "and with speech encoding there are no "
        echo "substantial quality differences."
        echo "Language code is en, pl, ru and so on."
        echo "Refer to espeak manual."
        echo "Look inside the file to change speed, pitch etc."
        echo "because these are kind of fixed preferences."
        exit
    
    
        exit
    fi
    
    
    if [ "$2" = g ]; then
        echo "The second argument should be the language: en, pl and so on."
        echo "The optional 'g' or 'l' goes on third position."
        exit
    fi
    
    
    
    
    # encoding
    encode="$3"    # If g or l in command line is ommited, the text will be played. 
    
    TXT_FILE="$1"
    BASENAME=`echo "$TXT_FILE" | sed 's/\(.*\)\(\....$\)/\1/g'`
    
    echo "Processing ${TXT_FILE} with TTS"
    
    
    if [ "$encode" = l ] ; then
    	espeak -f "$1" -gap $gap -s $speed -l $paragraph -p $pitch -v$lang --stdout | \
    	lame --verbose  --preset cbr 32  - "${BASENAME}_espeak-l.mp3"
    	echo "...done! Voice saved as ${BASENAME}_espeak-l.mp3"
    elif [ "$encode" = g ] ; then
    	espeak -f "$1" -gap $gap -s $speed -l $paragraph -p $pitch -v$lang --stdout | \
    	gogo stdin -b 32 -m m -emp 5 "${BASENAME}_espeak-g.mp3"
    	echo "...done! Voice saved as ${BASENAME}_espeak-g.mp3"
    else
    	espeak -f "$1" -s $speed -l $paragraph -p $pitch -v$lang
    	echo "...done! Add 'g' or 'l'  to command line to encode. "
    fi

    I also cut the file afterwards into 15 minutes chunks cause my phone much better handles them that way (better scrolling, quicker search for a chapter if necessary).

    I use mp3splt with -0 0.2 which makes an overlap of 2 sec. betwen chunks.
    Last edited by frytek; October 10th, 2012 at 04:03 PM.

  9. #29
    Join Date
    Jan 2008
    Beans
    49

    Re: Need to convert PDF to Audio MP3

    I also found some code that does the actual conversion but I don't use it as usually I convert ebooks to txt and to mp3, (not pdf, doc or odt). And and I do it from Callibre.
    Anyway, if someone would like to use this, here it goes:

    install some pre-requisites first, with
    # sudo apt-get install espeak lame xpdf-utils odt2txt antiword



    Code:
    # if it isn't a TXT file, convert it first
    if [ "$ext" != "txt" ] ; then
        TMP_FILE="/tmp/espeakfile-$$.txt"
    
        # PDF
        if [ "$ext" = "pdf" ] ; then
            echo "converting from PDF to TXT"
            pdftotext "${TXT_FILE}" "${TMP_FILE}"
        fi
    
        # ODT
        if [ "$ext" = "odt" ] ; then
            echo "converting from ODT to TXT"
            odt2txt --subst=all "${TXT_FILE}" > "${TMP_FILE}"
        fi
    
        # DOC
        if [ "$ext" = "doc" ] ; then
            echo "converting from DOC to TXT"
            antiword "${TXT_FILE}" > "${TMP_FILE}"
        fi
    
        TXT_FILE="${TMP_FILE}"
    fi
    Last edited by frytek; October 10th, 2012 at 04:04 PM.

Page 3 of 3 FirstFirst 123

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •