diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/talkclips.py | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/tools/talkclips.py b/tools/talkclips.py index 425c1b12bf..7f34608f44 100755 --- a/tools/talkclips.py +++ b/tools/talkclips.py | |||
@@ -23,40 +23,40 @@ import sys | |||
23 | # The following lines provide variables which you can modify to adjust | 23 | # The following lines provide variables which you can modify to adjust |
24 | # settings... See comments next to each line. | 24 | # settings... See comments next to each line. |
25 | # Start opts: | 25 | # Start opts: |
26 | espeak = '/usr/bin/espeak' # location of easpeak binary | 26 | espeak = '/usr/bin/espeak' # location of easpeak binary |
27 | rbspeexenc = './rbspeexenc' # path to rbspeexenc binary (default currentdir) | 27 | rbspeexenc = './rbspeexenc' # path to rbspeexenc binary (default currentdir) |
28 | VOPTS=espeak+" -s 320 -z" # Your espeak opts | 28 | VOPTS=espeak+" -s 320 -z" # Your espeak opts |
29 | ROPTS=rbspeexenc+" -q 4 -c 10" # rbspeex opts | 29 | ROPTS=rbspeexenc+" -q 4 -c 10" # rbspeex opts |
30 | logfile="/tmp/talkclips.log" # a file where output should be logged | 30 | logfile="/tmp/talkclips.log" # a file where output should be logged |
31 | # End opts | 31 | # End opts |
32 | # Don't touch the below settings. Unless you know what your doing. | 32 | # Don't touch the below settings. Unless you know what your doing. |
33 | log=open(logfile, 'w') # logging leave this var alone. | 33 | log=open(logfile, 'w') # logging leave this var alone. |
34 | USAGE="Usage: %s <directory>" % (sys.argv[0]) # usage prompt don't touch | 34 | USAGE="Usage: %s <directory>" % (sys.argv[0]) # usage prompt don't touch |
35 | if not os.path.exists(rbspeexenc): | 35 | if not os.path.exists(rbspeexenc): |
36 | print "%s not found, please change your rbspeexenc path appropriately,\n"\ | 36 | print ("%s not found, please change your rbspeexenc path appropriately,\n"\ |
37 | "or place the binary in %s\n"\ | 37 | "or place the binary in %s\n"\ |
38 | % (rbspeexenc, os.path.realpath(rbspeexenc)) | 38 | % (rbspeexenc, os.path.realpath(rbspeexenc))) |
39 | print USAGE | 39 | print (USAGE) |
40 | exit (-1) # Rbspeexenc not found | 40 | exit (-1) # Rbspeexenc not found |
41 | if not os.path.exists(espeak): | 41 | if not os.path.exists(espeak): |
42 | print "Espeak not found, please install espeak, or adjust the path of\n"\ | 42 | print ("Espeak not found, please install espeak, or adjust the path of\n"\ |
43 | 'the "espeak" variable appropriately.\n' | 43 | 'the "espeak" variable appropriately.\n') |
44 | print USAGE | 44 | print (USAGE) |
45 | exit (-1) # espeak not found | 45 | exit (-1) # espeak not found |
46 | 46 | ||
47 | if len(sys.argv) != 2: | 47 | if len(sys.argv) != 2: |
48 | print USAGE | 48 | print (USAGE) |
49 | exit (-1) # user failed to supply enough arguments | 49 | exit (-1) # user failed to supply enough arguments |
50 | 50 | ||
51 | RBDIR=sys.argv[1] # grab user input on the command line (don't touch) | 51 | RBDIR=sys.argv[1] # grab user input on the command line (don't touch) |
52 | if not os.path.exists(sys.argv[1]): | 52 | if not os.path.exists(sys.argv[1]): |
53 | print "The path %s doesn't exist, please try again.\n\n%s"\ | 53 | print ("The path %s doesn't exist, please try again.\n\n%s"\ |
54 | % (sys.argv[1], USAGE) | 54 | % (sys.argv[1], USAGE)) |
55 | exit(-1) # path doesn't exist | 55 | exit(-1) # path doesn't exist |
56 | else: # check if it's a dir | 56 | else: # check if it's a dir |
57 | if not os.path.isdir(sys.argv[1]): # a file | 57 | if not os.path.isdir(sys.argv[1]): # a file |
58 | print "This script only currently works for directories.\n\n%s" % (USAGE) | 58 | print ("This script only currently works for directories.\n\n%s" % (USAGE)) |
59 | exit (-1) # not a dir | 59 | exit (-1) # not a dir |
60 | 60 | ||
61 | def gentalkclip(clipname, fullpath, isdir): | 61 | def gentalkclip(clipname, fullpath, isdir): |
62 | """Generate an individual talk clip. | 62 | """Generate an individual talk clip. |
@@ -65,23 +65,23 @@ def gentalkclip(clipname, fullpath, isdir): | |||
65 | synth, and encoder, and save accordingly.""" | 65 | synth, and encoder, and save accordingly.""" |
66 | 66 | ||
67 | if isdir: # directory | 67 | if isdir: # directory |
68 | output=os.path.join(fullpath, "_dirname.talk") # dir clip name | 68 | output=os.path.join(fullpath, "_dirname.talk") # dir clip name |
69 | if os.path.exists(output): | 69 | if os.path.exists(output): |
70 | return True # no need to create again | 70 | return True # no need to create again |
71 | try: # Don't let the script stop if bash raises filename errors | 71 | try: # Don't let the script stop if bash raises filename errors |
72 | os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) | 72 | os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) |
73 | os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) | 73 | os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) |
74 | os.remove(output+".tmp") # delete the old wav file | 74 | os.remove(output+".tmp") # delete the old wav file |
75 | except OSError: | 75 | except OSError: |
76 | log.write('Failed to create clip for directory: "%s"\n' % (clipname)) | 76 | log.write('Failed to create clip for directory: "%s"\n' % (clipname)) |
77 | return False | 77 | return False |
78 | log.write( 'Created clip for directory: "%s"\n' % (clipname)) # log | 78 | log.write( 'Created clip for directory: "%s"\n' % (clipname)) # log |
79 | return True | 79 | return True |
80 | else: # file | 80 | else: # file |
81 | output=fullpath+".talk" | 81 | output=fullpath+".talk" |
82 | if os.path.exists(output): | 82 | if os.path.exists(output): |
83 | return True # no need to create again | 83 | return True # no need to create again |
84 | try: | 84 | try: |
85 | os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) | 85 | os.system('%s "%s" -w "%s"' % (VOPTS, clipname, output+".tmp")) |
86 | os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) | 86 | os.system('%s "%s" "%s"' % (ROPTS, output+".tmp", output)) |
87 | os.remove (output+".tmp") | 87 | os.remove (output+".tmp") |
@@ -89,7 +89,7 @@ def gentalkclip(clipname, fullpath, isdir): | |||
89 | log.write('Failed to create clip for file: "%s"\n' % (clipname)) | 89 | log.write('Failed to create clip for file: "%s"\n' % (clipname)) |
90 | return False # something failed, so continue with next file | 90 | return False # something failed, so continue with next file |
91 | log.write('Created clip for file: "%s"\n' % (clipname)) # logging | 91 | log.write('Created clip for file: "%s"\n' % (clipname)) # logging |
92 | return True # clips created | 92 | return True # clips created |
93 | 93 | ||
94 | def istalkclip(file): | 94 | def istalkclip(file): |
95 | """Is file a talkclip? | 95 | """Is file a talkclip? |
@@ -110,12 +110,12 @@ def walker(directory): | |||
110 | for item in os.listdir(directory): # get subdirs and files | 110 | for item in os.listdir(directory): # get subdirs and files |
111 | if os.path.isdir(os.path.join(directory, item)): | 111 | if os.path.isdir(os.path.join(directory, item)): |
112 | gentalkclip (item, os.path.join(directory, item), True) # its a dir | 112 | gentalkclip (item, os.path.join(directory, item), True) # its a dir |
113 | walker(os.path.join(directory, item)) # go down into this sub dir | 113 | walker(os.path.join(directory, item)) # go down into this sub dir |
114 | continue | 114 | continue |
115 | else: # a file | 115 | else: # a file |
116 | if istalkclip (item): | 116 | if istalkclip (item): |
117 | continue # is a talk clip | 117 | continue # is a talk clip |
118 | else: # create clip | 118 | else: # create clip |
119 | gentalkclip(item, os.path.join(directory, item), False) # a file | 119 | gentalkclip(item, os.path.join(directory, item), False) # a file |
120 | continue | 120 | continue |
121 | 121 | ||