def test_Mix(self): self._sample_1.extract_channel(0) self._sample_2.extract_channel(0) formatter1 = ChannelFormatter(self._sample_1.get_channel(0)) formatter1.set_framerate(16000) formatter1.set_sampwidth(2) formatter1.convert() formatter2 = ChannelFormatter(self._sample_2.get_channel(0)) formatter2.set_framerate(16000) formatter2.set_sampwidth(2) formatter2.convert() equalizer = ChannelsEqualizer() equalizer.append_channel(formatter1.channel) equalizer.append_channel(formatter2.channel) equalizer.equalize() mixer = ChannelsMixer() mixer.append_channel(equalizer.get_channel(0)) mixer.append_channel(equalizer.get_channel(1)) newchannel = mixer.mix() self.assertEqual(newchannel.get_nframes(), equalizer.get_channel(0).get_nframes()) self.assertEqual(newchannel.get_nframes(), equalizer.get_channel(1).get_nframes())
def equalize_channels( settings, p=None ): """ Equalize channels of the settings. @param settings: a list of dictionaries with extracted information from a settings file. @param p is a progress dialog """ equalizer = ChannelsEqualizer() if p: p.update(0.25, "Load channels to equalize. ") for channel in settings: equalizer.append_channel( channel['channel'] ) if p: p.update(0.50, "Equalize each channel... ") equalizer.equalize() if p: p.update(0.90, "Save equalized channels. ") for i,channel in enumerate(settings): channel['channel'] = equalizer.get_channel(i)
parser = ArgumentParser(usage="%s -w input files [options]" % os.path.basename(PROGRAM), description="A script to equalize the number of frames of audio files") parser.add_argument("-w", metavar="file", nargs='+', required=True, help='Audio Input file names') # ---------------------------------------------------------------------------- if len(sys.argv) <= 1: sys.argv.append('-h') args = parser.parse_args() # ---------------------------------------------------------------------------- equalizer = ChannelsEqualizer() file = signals.open(args.w[0]) sampwidth = file.get_sampwidth() framerate = file.get_framerate() for inputFile in args.w: audio = signals.open(inputFile) if audio.get_sampwidth() != sampwidth: print "Input files must have the same sample width !" sys.exit(1) if audio.get_framerate() != framerate: print "Input files must have the same framerate !" sys.exit(1) idx = audio.extract_channel(1) equalizer.append_channel(audio.get_channel(idx))