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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 #!/usr/bin/python # # this script shows the user what to say and then records his voice # into the correct file # from subprocess import Popen from optparse import OptionParser from time import sleep import os, sys op = OptionParser() op.add_option("-n", "--name", dest="nickname", help = "what nickname to append to the wave files") op.add_option("-d", "--dry-run", dest="dryrun", help = "don't record", default=False, action="store_true") op.add_option("-s", "--sleep", dest="sleeptime", help = "sleep N seconds", metavar="N", default=3, type="int") op.add_option("-o", "--overwrite-existing", dest="autoskip", help = "overwrite existing files", default = "True", action="store_false") op.add_option("-b", "--bunch", dest="bunch", help = "record only the first NUM files.", default = -1, type="int") (options, args) = op.parse_args() if not options.nickname: print "you need to specify a nickname with the -n switch." op.print_help() sys.exit() definitions = """# 1_lerfu - read: english pronounciation, lojban lerfu form, example words a ei abu gasnu catra b bi by blabi bebna c si cy cacra cutci d di dy dandu dunda e i ebu bebna jbena f ef fy farlu lifri g dji gy gletu gugde i ai ibu cipni pinji j djei jy jmaji jijnu k kei ky kukte klaku l el ly loldi livla m em my makfa mamta n en ny cnino snanu o "o" o ponse botpi p pi py panpi porpi r ar ry renro rorci s es sy srasu sisku t ti ty titla tatru u iu ubu bancu gusni v vi vy vinji bevri #############miks nii? x eks xy xexso, xalka y vai ybu .y., lujvo? z zed zy zvati, zasti # 2_conclus - read: lerfu forms, example words bl by ly blabi blanu br by ry bredi briju cf cy fy cfari cfipu ck cy ky ckafi ckabu cl cy ly cladu clani cm cy my cmavo cmene cn cy ny cnita cnino cp cy py cpana cpacu cr cy ry cradi cribe ct cy ty ctebi ctuca dj dy jy djica djedi dr dy ry drani drata dz dy zy dzipo dzena fl fy ly flira flani fr fy ry fraso frili gl gy ly gletu glico gr gy ry grusi grake jb jy by jbena jbama jd jy dy jdini jdice jg jy gy jgari jgita jm jy my jmive jmaji jv jy vy jvinu kl ky ly klaku klama kr ky ry krinu krasi ml my ly mlatu mleca mr my ry mrilu mruli pl py ly plise plana pr py ry prenu prali sf sy fy sfani sfofa sk sy ky skami skicu sl sy ly sliru slabu sm sy my smacu smuci sn sy ny snife snada sp sy py speni spati sr sy ry srasu srera st sy ty stuna stagi tc ty cy tcidu tcadu tr ty ry troci trati ts ty sy tsali tsiju vl vy ly vlipa vlagi vr vy ry vrude vraga xl xy ly xlali xlura xr xy ry xruti xrani zb zy by zbasu zbepi zd zy dy zdani zdile zg zy gy zgana zgike zm zy my zmadu zmiku zv zy vy zvati # 3_diph - read: lerfu form of letters, pronounciation ai abu ibu ai au abu ubu au ei ebu ibu ei ia ibu abu ia ie ibu ebu ie ii ibu ibu ii io ibu obu io iu ibu ubu iu iy ibu ybu iy oi obu ibu oi ua ubu abu ua ue ubu ebu ue ui ubu ibu ui uo ubu obu uo uu ubu ubu uu uy ubu ybu uy""" liste = [l.split("\t") for l in definitions.split("\n")] # filename scheme: # type_id_nickname.wav # type = lerfu / conclus # id = a, b, c, ... , [consonant clusters] # nickname = what the user typed above # example: # lerfu_a_timo.wav # lerfu_a_elmo.wav # ... # conclus_bl_timo.wav # ... print """welcome to the lojban voice recording assistant. this program will help you record all the voice samples for the ULTIMATE LOJBAN PRONOUNCIATION GUIDE ==================================== it will tell you what to say and then wait a couple of seconds. if you hit ctrl-c during that period the file will be skipped. then it will start recording the file. hit ctrl-c when you are done speaking. try to keep a 1 second margin if possible. """ print "configuration:" print "nickname:", options.nickname if options.autoskip: print "skipping files that already exist" else: print "overwriting files that already exist" if options.dryrun: print " - dry run! -" if options.bunch == -1: print "recording all files" else: print "recording only the first %i files" % options.bunch sleep(2) header = "" number = 1 for ln in liste: if number > options.bunch and options.bunch > 0: continue if ln[0][0] == "#": typ = ln[0].split(" ")[1] header = " ".join(ln[0].split(" ")[3:]) print "=====================" print " reached new section" print "=====================" print header sleep(2) continue filename = "%s_%s_%s.wav" % (typ, ln[0], options.nickname) # check if the file already exists try: os.stat(filename) except OSError: fileexists = False else: fileexists = True print print print "------------------" if fileexists: print "overwriting file: ", filename else: print "new file: ", filename print print print " %s - %s" % (ln[0], ", ".join(ln[1:])) print " ", header print print if fileexists: if options.autoskip: #print "SKIPPING! - hit ctrl-c in 2 seconds to overwrite the file" print "skipped" continue #try: # sleep(2) # continue #except: # print "OK" print print "start recording in %i seconds" % options.sleeptime try: sleep(options.sleeptime) except KeyboardInterrupt: # the user decided to skip this file. print "skipping" continue print "recording now. hit ctrl-c to finish" if not options.dryrun: rec = Popen("arecord -f dat".split(), stdout = open(filename, "w")) try: rec.wait() except KeyboardInterrupt: print "k" else: sleep(1) # dummy number += 1