Пример #1
0
 def testTrimTrack(self):
     """ 
     Test correct trimming on real (albeit contrived) data
     (assume a single track - remove leading/trailing silences)
     """
     voicesubsamples = CP.load(open('dummyVoice.p'))
     voicetrack = Segmentor.segmentVoice(voicesubsamples)[0]
     self.assert_(min(voicetrack) == 45 and max(voicetrack) == 104)
Пример #2
0
 def doTapeFlip(self):
     """ For 2-sided tape, save the first side and resume... """
     self.status.config(text='Flip tape, then play...')
     # Save side one
     self.recsound.stop()
     (sampfreq,subrate) = (44100,20000)
     samps = Segmentor.getMonoAmpSamples(self.recsound,
                                         subrate)            
     trackAssign = Segmentor.segmentVoice(samps)
     (tstart,tend) = (min(trackAssign[0])*subrate,
                      max(trackAssign[0])*subrate)
     self.sideone = tkSnack.Sound()
     self.sideone.copy(self.recsound,start=tstart,end=tend)
     # Restart recording
     self.recsound = tkSnack.Sound()
     self.recsound.configure(channels="Stereo")
     self.recsound.configure(frequency=44100)
     self.recsound.record()
Пример #3
0
 def recordSound(self):
     """ Start/stop recording from the mic input """        
     if(self.state == 0):
         #
         # Start recording
         #
         self.recsound = tkSnack.Sound()
         self.recsound.configure(channels="Stereo")
         self.recsound.configure(frequency=44100)
         self.recsound.record()
         self.status.config(text='Recording...')
         self.record_sound.config(text="STOP",bg="red")
         self.state = 1
     elif(self.state == 1):
         #
         # Stop recording, write tracks out to disk for burning
         # 
         self.recsound.stop()
         # Wave sampling freq (Hz)
         sampfreq = 44100 
         # Convert to mono (take max amplitude over channels) and subsample
         subrate = 20000
         samps = Segmentor.getMonoAmpSamples(self.recsound,
                                             subrate)            
         # Process subsampled audio
         self.status.config(text='Processing audio...')
         if(self.tracksplit.get() == 0):
             # VOICE: just find single track
             trackAssign = Segmentor.segmentVoice(samps)                
         elif(self.tracksplit.get() == 2):
             # MUSIC: segment recording into individual tracks
             trackAssign = Segmentor.segmentTracks(samps)
         # Write these tracks out to disk                     
         if(self.sideone != None):
             # We have a previous side-one track, write it out
             fn = os.path.join(datadir,'track%d.wav' % 0)
             self.sideone.write(fn)
             # Then write out the current track
             (tstart,tend) = (min(trackAssign[0])*subrate,
                              max(trackAssign[0])*subrate)
             newTrack = tkSnack.Sound()
             newTrack.copy(self.recsound,start=tstart,end=tend)
             fn = os.path.join(datadir,'track%d.wav' % 1)
             newTrack.write(fn)
         else:                
             # No side-one, just write these tracks out to disk
             for (tracknum,ta) in enumerate(trackAssign):
                 (tstart,tend) = (min(ta)*subrate,max(ta)*subrate)
                 newTrack = tkSnack.Sound()
                 newTrack.copy(self.recsound,start=tstart,end=tend)
                 fn = os.path.join(datadir,'track%d.wav' % tracknum)
                 newTrack.write(fn)
         self.status.config(text='Ready to burn!')            
         self.recsound = None
         self.record_sound.config(text="BURN",bg='red')
         self.state = 2
     elif(self.state == 2):
         #
         # Burn tracks from disk to a blank CD 
         #
         tracks = [fn for fn in os.listdir(datadir)
                   if re.match('track\d+\.wav',fn)]
         def sortfn(a,b):
             aval = int(re.match('track(\d+)\.wav',a).group(1))
             bval = int(re.match('track(\d+)\.wav',b).group(1))
             return aval-bval
         tracks.sort(sortfn)        
         # Construct cdrecord command for CD burning
         cmd = 'cdrecord fs=4096k -v -useinfo speed=1 '
         cmd += '-dao -eject -pad -audio '
         cmd += '-dev=%s ' % (self.dev)
         for track in tracks:
             cmd += '\"%s\" ' % os.path.join(datadir,track)
         self.status.config(text='Burning CD...')
         os.system(cmd)
         self.status.config(text='Done - CD completed')
         # Now that we're done, cleanup by deleting temp track files
         for track in tracks:
             os.remove(os.path.join(datadir,track))
         # Reset state
         self.state = 0