示例#1
0
 def sonify_image(self):
     """Use the sonify module to create a sound wave based on color."""
     self.messageLabel.configure(text="")
     if self.targetImage is None:
         self.messageLabel.configure(text="Must load an image first.")
         return
     self.messageLabel.configure(text="Converting ...")
     self.myParent.update_idletasks()
     try:
         imYCbCr = self.targetImage.convert("YCbCr")
     except:
         self.messageLabel.configure(text='Unable to convert (%s) to YCbCr.' % self.targetImage.mode)
         return
     try:
         phi, rad, lum = sonify.phi_from_YCbCr(imYCbCr)
         amps = sonify.get_amplitudes(phi, figure=self.powerFigure)
         self.powerFigureCanvas.show()
     except:
         self.messageLabel.configure(text='Failure to calculate frequencies.')
         return
     try:
         self.channels = ((sonify.super_sine_wave(freqs=sonify.TONES, amps=amps, framerate=self.rate),),)        
     except:
         self.messageLabel.configure(text='Failure to calculate waveform.')
         return
     self.messageLabel.configure(text="Sonification complete.")
示例#2
0
 def sonify_image(self):
     self.messageLabel.configure(text="")
     if self.targetImage is None:
         self.messageLabel.configure(text="Must load an image first.")
         return
     if self.targetImage.mode != 'RGB':
         self.messageLabel.configure(text='Not RGB.  %s is invalid.' %
                                     self.targetImage.mode)
         return
     self.messageLabel.configure(text="Converting ...")
     self.myParent.update_idletasks()
     imYCbCr = self.targetImage.convert(
         "YCbCr")  # Convert the image to YCbCr
     phi, rad, lum = sonify.phi_from_YCbCr(imYCbCr)
     amps = sonify.get_amplitudes(phi, figure=self.powerFigure)
     self.powerFigureCanvas.show()
     channels = ((sonify.super_sine_wave(freqs=sonify.TONES,
                                         amps=amps,
                                         framerate=self.rate), ), )
     self.samples = wavebender.compute_samples(channels,
                                               nsamples=self.rate *
                                               self.time)
     try:
         wavebender.write_wavefile('./temp.wav',
                                   samples=self.samples,
                                   nframes=self.rate * self.time,
                                   nchannels=1,
                                   framerate=self.rate)
         self.snd.read('./temp.wav')
         self.messageLabel.configure(text="Sonification complete.")
     except:
         self.messageLabel.configure(text="Errors in temp write.")
示例#3
0
 def sonify_image(self):
     self.messageLabel.configure(text="")
     if self.targetImage is None:
         self.messageLabel.configure(text="Must load an image first.")
         return
     if self.targetImage.mode != 'RGB':
         self.messageLabel.configure(text='Not RGB.  %s is invalid.' % self.targetImage.mode)
         return
     self.messageLabel.configure(text="Converting ...")
     self.myParent.update_idletasks()
     imYCbCr = self.targetImage.convert("YCbCr")                       # Convert the image to YCbCr
     phi, rad, lum = sonify.phi_from_YCbCr(imYCbCr)
     amps = sonify.get_amplitudes(phi, figure=self.powerFigure)
     self.powerFigureCanvas.show()
     channels = ((sonify.super_sine_wave(freqs=sonify.TONES, amps=amps, framerate=self.rate),),)
     self.samples = wavebender.compute_samples(channels, nsamples=self.rate*self.time)
     try:
         wavebender.write_wavefile('./temp.wav', samples=self.samples, nframes=self.rate*self.time, 
                           nchannels=1, framerate=self.rate)
         self.snd.read('./temp.wav')
         self.messageLabel.configure(text="Sonification complete.")
     except:
         self.messageLabel.configure(text="Errors in temp write.")