-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdf2mp3.py
More file actions
executable file
·33 lines (27 loc) · 1.14 KB
/
Copy pathpdf2mp3.py
File metadata and controls
executable file
·33 lines (27 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
import os,sys
import string
# get filenname
ifpdf=1
filename_inp = sys.argv[1]
if filename_inp[-4:]=='.dat' or filename_inp[-4:]=='.txt':
ifpdf=0
if filename_inp[-4:]=='.pdf' or filename_inp[-4:]=='.dat' or filename_inp[-4:]=='.txt':
filename = filename_inp[:-4]
if os.path.isfile(str(filename_inp)):
if ifpdf:
print 'converting pdf to ascii...'
os.popen('pdftotext ' + str(filename) + '.pdf ' + str(filename) + '.txt')
print 'start converting ascii to wav...'
os.popen('cat ' + str(filename) + '.txt\
|sed \'s/[^a-zA-Z .,!?]//g\'|text2wave -o ' + str(filename) + '.wav')
print 'converting to mp3...'
os.popen('lame -f ' + str(filename) + '.wav ' + str(filename) + '.mp3')
os.popen('rm -f ' + str(filename) + '.wav')
print 'finished. don\'t forget to delete txt file if you don\'t need it'
else:
print '*** file does not exist ***'
else:
print '*** please give extension of your file (.dat, .txt or .pdf)'
print '*** or your file called: ' + str(filename_inp) + '\n*** does not exist'
# that's it. have fun!!! :)