def testResults(self): "Test decoder stack: test frames content" decoder = FileDecoder(uri=self.source, start=self.start, duration=self.duration, stack=True) pitch_on_file = AubioPitch() pipe = (decoder | pitch_on_file) pipe.run() self.assertIsInstance(pipe.frames_stack, list) pitch_results_on_file = pipe.results['aubio_pitch.pitch'].data.copy() # If the pipe is used for a second run, the processed frames stored # in the stack are passed to the other processors # without decoding the audio source again. #Let's define a second analyzer equivalent to the previous one: pitch_on_stack = AubioPitch() pipe |= pitch_on_stack pipe.run() # to assert that the frames passed to the two analyzers are the same, # we check that the results of these analyzers are equivalent: pitch_results_on_stack = pipe.results['aubio_pitch.pitch'].data self.assertTrue( np.array_equal(pitch_results_on_stack, pitch_results_on_file))
def tearDown(self): decoder = FileDecoder(self.source) (decoder | self.analyzer).run() results = self.analyzer.results for key in self.expected.keys(): self.assertEquals(results[key].data_object.value, self.expected[key])
def testEmptyFile(self): "Test decoding empty file" import tempfile self.tmpfile = tempfile.NamedTemporaryFile(delete=True) self.source = self.tmpfile.name with self.assertRaises(IOError): FileDecoder(self.source) self.tmpfile.close()
def testProcess(self): "Test decoder stack: test process" decoder = FileDecoder(uri=self.source, start=self.start, duration=self.duration, stack=True) self.assertTrue(decoder.stack) self.assertFalse(decoder.from_stack) pipe = ProcessPipe(decoder) pipe.run() self.assertFalse(decoder.stack) self.assertTrue(decoder.from_stack) self.assertEqual(len(pipe.frames_stack), 44) pipe.run()
# -*- coding: utf-8 -*- from timeside.core import * from timeside.decoder import FileDecoder from timeside.encoder import Mp3Encoder import sys if len(sys.argv) > 1: source = sys.argv[1] else: import os.path audio_file = '../samples/sweep.flac' source = os.path.join(os.path.dirname(__file__), audio_file) #source = '/home/thomas/data/CNRSMH_E_1985_001_001_001_04.wav' decoder = FileDecoder(source) print "Creating decoder with id=%s for: %s" % (decoder.id(), source) dest1 = "/tmp/test_filesink.mp3" dest2 = "/tmp/test_appsink.mp3" f = open(dest2, 'w') streaming = True encoder = Mp3Encoder(dest1, streaming=streaming, overwrite=True) pipe = (decoder | encoder) print pipe #pipe.run() for chunk in pipe.stream():
def tearDown(self): decoder = FileDecoder(uri=self.source, start=self.start, duration=self.duration) decoder.setup(samplerate=self.samplerate, channels=self.channels, blocksize=self.blocksize) totalframes = 0 while True: frames, eod = decoder.process() totalframes += frames.shape[0] if eod or decoder.eod: break self.assertEqual(frames.shape[0], decoder.blocksize()) self.assertEqual(frames.shape[1], decoder.channels()) ratio = decoder.output_samplerate / decoder.input_samplerate if 0: print "input / output_samplerate:", decoder.input_samplerate, '/', decoder.output_samplerate, print "ratio:", ratio print "input / output_channels:", decoder.input_channels, decoder.output_channels print "input_duration:", decoder.input_duration print "input_totalframes:", decoder.input_totalframes print "mime_type", decoder.mime_type() if self.channels: # when specified, check that the channels are the ones requested self.assertEqual(self.channels, decoder.output_channels) else: # otherwise check that the channels are preserved, if not specified self.assertEqual(decoder.input_channels, decoder.output_channels) # and if we know the expected channels, check the output match if self.expected_channels: self.assertEqual(self.expected_channels, decoder.output_channels) # do the same with the sampling rate if self.samplerate: self.assertEqual(self.samplerate, decoder.output_samplerate) else: self.assertEqual(decoder.input_samplerate, decoder.output_samplerate) if self.expected_samplerate: self.assertEqual(self.expected_samplerate, decoder.output_samplerate) self.assertEqual(decoder.mime_type(), self.expected_mime_type) self.assertEqual(totalframes, self.expected_totalframes) input_duration = decoder.input_totalframes / decoder.input_samplerate output_duration = decoder.totalframes() / decoder.output_samplerate if self.test_exact_duration: self.assertEqual(input_duration, output_duration) self.assertEqual(input_duration, decoder.uri_duration) self.assertEqual(self.source_duration, decoder.uri_duration) else: self.assertAlmostEqual(input_duration, output_duration, places=1) self.assertAlmostEqual(input_duration, decoder.uri_duration, places=1) self.assertAlmostEqual(self.source_duration, decoder.uri_duration, places=1)
def testNoAudioStream(self): "Test decoding file withouth audio stream" self.source = __file__ with self.assertRaises(IOError): FileDecoder(self.source)
def testDevNull(self): "Test decoding dev null" self.source = "/dev/null" with self.assertRaises(IOError): FileDecoder(self.source)
def test_bad_duration_value(self): "Test decoding segment with a too large duration value argument" decoder = FileDecoder(self.source, duration=10) pipe = ProcessPipe(decoder) self.assertRaises(ValueError, pipe.run)
def test_bad_start_value(self): "Test decoding segment with start value exceeding the media duration" decoder = FileDecoder(self.source, start=10) pipe = ProcessPipe(decoder) self.assertRaises(ValueError, pipe.run)
# -*- coding: utf-8 -*- from timeside.core import * from timeside.decoder import FileDecoder from timeside.encoder import Mp3Encoder, VorbisEncoder import sys if len(sys.argv) > 1: source = sys.argv[1] else: import os.path audio_file = '../samples/sweep.flac' source = os.path.join(os.path.dirname(__file__), audio_file) decoder = FileDecoder(audio_file) print "Creating decoder with id=%s for: %s" % (decoder.id(), audio_file) dest1 = "/tmp/test_filesink.ogg" dest2 = "/tmp/test_appsink.ogg" f = open(dest2, 'w') streaming = True encoder = VorbisEncoder(dest1, streaming=streaming, overwrite=True) pipe = (decoder | encoder) print pipe #pipe.run() for chunk in pipe.stream():
def tearDown(self): decoder = FileDecoder(uri=self.source, start=self.start, duration=self.duration) decoder.setup(samplerate=self.samplerate, channels=self.channels, blocksize=self.blocksize) totalframes = 0 while True: frames, eod = decoder.process() totalframes += frames.shape[0] if eod or decoder.eod: break self.assertEqual(frames.shape[0], decoder.blocksize()) self.assertEqual(frames.shape[1], decoder.channels()) ratio = decoder.output_samplerate / decoder.input_samplerate if 0: print "input / output_samplerate:", decoder.input_samplerate, '/', decoder.output_samplerate, print "ratio:", ratio print "input / output_channels:", decoder.input_channels, decoder.output_channels print "input_duration:", decoder.input_duration print "input_totalframes:", decoder.input_totalframes print "mime_type", decoder.mime_type() if self.channels: # when specified, check that the channels are the ones requested self.assertEqual(self.channels, decoder.output_channels) else: # otherwise check that the channels are preserved, if not specified self.assertEqual(decoder.input_channels, decoder.output_channels) # and if we know the expected channels, check the output match if self.expected_channels: self.assertEqual( self.expected_channels, decoder.output_channels) # do the same with the sampling rate if self.samplerate: self.assertEqual(self.samplerate, decoder.output_samplerate) else: self.assertEqual( decoder.input_samplerate, decoder.output_samplerate) if self.expected_samplerate: self.assertEqual( self.expected_samplerate, decoder.output_samplerate) self.assertEqual(decoder.mime_type(), self.expected_mime_type) self.assertEqual(totalframes, self.expected_totalframes) input_duration = decoder.input_totalframes / decoder.input_samplerate output_duration = decoder.totalframes() / decoder.output_samplerate if self.test_exact_duration: self.assertEqual(input_duration, output_duration) self.assertEqual(input_duration, decoder.uri_duration) self.assertEqual(self.source_duration, decoder.uri_duration) else: self.assertAlmostEqual(input_duration, output_duration, places=1) self.assertAlmostEqual(input_duration, decoder.uri_duration, places=1) self.assertAlmostEqual(self.source_duration, decoder.uri_duration, places=1)
def tearDown(self): decoder = FileDecoder(self.source) (decoder | self.grapher).run() self.grapher.render(self.image)
# -*- coding: utf-8 -*- from timeside.core import * from timeside.decoder import FileDecoder from timeside.encoder import Mp3Encoder import sys if len(sys.argv) > 1: source = sys.argv[1] else: import os.path audio_file = '../samples/sweep.flac' source = os.path.join(os.path.dirname(__file__), audio_file) #source = '/home/thomas/data/CNRSMH_E_1985_001_001_001_04.wav' decoder = FileDecoder(source) print "Creating decoder with id=%s for: %s" % (decoder.id(), source) dest1 = "/tmp/test_filesink.mp3" dest2 = "/tmp/test_appsink.mp3" f = open(dest2, 'w') streaming = True encoder = Mp3Encoder(dest1, streaming=streaming, overwrite=True) pipe = (decoder | encoder) print pipe #pipe.run()
# -*- coding: utf-8 -*- from timeside.core import * from timeside.decoder import FileDecoder from timeside.encoder import Mp3Encoder import sys if len(sys.argv) > 1: source = sys.argv[1] else: import os.path source = os.path.join(os.path.dirname(__file__), "../samples/sweep.flac") decoder = FileDecoder(source) print "Creating decoder with id=%s for: %s" % (decoder.id(), source) decoder.setup() channels = decoder.channels() print 'channels :', channels samplerate = decoder.samplerate() #nframes = decoder.nframes() dest1 = "/tmp/test_filesink.mp3" dest2 = "/tmp/test_appsink.mp3" f = open(dest2, 'w') streaming = True encoder = Mp3Encoder(dest1, streaming=True, overwrite=True) encoder.setup(channels=channels, samplerate=samplerate,
# -*- coding: utf-8 -*- from timeside.core import * from timeside.decoder import FileDecoder from timeside.encoder import Mp3Encoder import sys if len(sys.argv) > 1: source = sys.argv[1] else: import os.path source= os.path.join (os.path.dirname(__file__), "../samples/sweep.flac") decoder = FileDecoder(source) print "Creating decoder with id=%s for: %s" % (decoder.id(), source) decoder.setup() channels = decoder.channels() print 'channels :', channels samplerate = decoder.samplerate() #nframes = decoder.nframes() dest1 = "/tmp/test_filesink.mp3" dest2 = "/tmp/test_appsink.mp3" f = open(dest2,'w') streaming=True encoder = Mp3Encoder(dest1, streaming=True, overwrite=True) encoder.setup(channels=channels, samplerate=samplerate, blocksize=decoder.blocksize(), totalframes=decoder.totalframes())