Пример #1
0
 def test_Sync(self):
     self._sample_1.extract_channel(0)
     self._sample_2.extract_channel(0)
     
     channel = self._sample_1.get_channel(0)
     
     formatter = ChannelFormatter(self._sample_2.get_channel(0))
     formatter.sync(channel)
     
     self.assertEqual(channel.get_framerate(), formatter.channel.get_framerate())  
     self.assertEqual(channel.get_sampwidth(), formatter.channel.get_sampwidth())
Пример #2
0
    def export(self, inputname, outputname):
        """
        Create a new wav file with requested parameters.

        @param inputname (string) name of the inputfile
        @param reqSamplewidth (string) name of the outputfile

        """
        toconvert = False

        audio = signals.open(inputname)

        if (audio.get_sampwidth() < self._reqSamplewidth):
            raise NameError("The sample width of ("+str(audio.get_sampwidth())+") of the given file is not appropriate. " + str(self._reqSamplewidth) + " bytes required")

        if (audio.get_framerate() < self._reqFramerate):
            raise NameError("The framerate of ("+str(audio.get_framerate())+") of the given file is not appropriate. " + str(self._reqFramerate) + " Hz required")

        if (self._reqSamplewidth != audio.get_sampwidth()):
            toconvert = True
            if self._logfile:
                self._logfile.print_message("The sample width of ("+str(audio.get_sampwidth())+") of the given file is not appropriate. Sample width is changed to " + str(self._reqSamplewidth) + " bytes", indent=3, status=1)

        if (self._reqChannels != audio.get_nchannels()):
            toconvert = True
            if self._logfile:
                self._logfile.print_message("The number of channels of ("+str(audio.get_nchannels())+") of the given file is not appropriate. Number of channels is changed to " + str(self._reqChannels) + " channels", indent=3, status=1)

        if (self._reqFramerate != audio.get_framerate()):
            toconvert = True
            if self._logfile:
                self._logfile.print_message("The framerate of ("+str(audio.get_framerate())+") of the given file is not appropriate. Framerate is changed to " + str(self._reqFramerate) + " Hz", indent=3, status=1)

        if toconvert is True:
            # Get the expected channel
            idx = audio.extract_channel(0)
            # no more need of input data, can close
            audio.close()

            # Do the job (do not modify the initial channel).
            formatter = ChannelFormatter( audio.get_channel(idx) )
            formatter.set_framerate(self._reqFramerate)
            formatter.set_sampwidth(self._reqSamplewidth)
            formatter.convert()

            # Save the converted channel
            audio_out = Audio()
            audio_out.append_channel( formatter.channel )
            signals.save( outputname, audio_out )

        return toconvert
Пример #3
0
    print "Wrong bitrate value"
    sys.exit(1)

# ----------------------------------------------------------------------------

print (time.strftime("%H:%M:%S"))
audio = signals.open(args.w)

# Get the expected channel
idx = audio.extract_channel(args.c-1)
# no more need of input data, can close
audio.close()
print (time.strftime("%H:%M:%S"))

# Do the job (do not modify the initial channel).
formatter = ChannelFormatter( audio.get_channel(idx) )
if args.r:
    formatter.set_framerate(args.r)
if args.b:
    formatter.set_sampwidth(args.b)
formatter.convert()
print (time.strftime("%H:%M:%S"))

# Save the converted channel
audio_out = Audio()
audio_out.append_channel( formatter.channel )
signals.save( args.o, audio_out )
print (time.strftime("%H:%M:%S"))

# ----------------------------------------------------------------------------
Пример #4
0
 def test_Equalize(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()
     
     self.assertEqual(equalizer.get_channel(0).get_nframes(), equalizer.get_channel(1).get_nframes())  
Пример #5
0
# ----------------------------------------------------------------------------

if len(sys.argv) <= 1:
    sys.argv.append('-h')

args = parser.parse_args()
    
# ----------------------------------------------------------------------------

audio = signals.open(args.w)

# Get the expected channel
idx = audio.extract_channel(args.c-1)

# Do the job (do not modify the initial channel).
formatter = ChannelFormatter( audio.get_channel(idx) )

if args.r:
    formatter.set_framerate(args.r)
else:
    formatter.set_framerate(audio.get_framerate())
    

if args.b:
    if not args.b in [1,2,4]:
        print "Wrong bitrate value"
        sys.exit(1)
    formatter.set_sampwidth(args.b)
else:
    formatter.set_sampwidth(audio.get_sampwidth())