def test_decode(self): """opus_decode()""" packet = chr((63 << 2) + 3) + chr(49) for j in range(2, 51): packet += chr(0) dec = decoder.create(48000, 2) try: decoder.decode(dec, packet, 51, 960, 0) except OpusError as e: self.assertEqual(e.code, constants.INVALID_PACKET) packet = chr(63 << 2) + chr(0) + chr(0) try: decoder.decode(dec, packet, -1, 960, 0) except OpusError as e: self.assertEqual(e.code, constants.BAD_ARG) try: decoder.decode(dec, packet, 3, 60, 0) except OpusError as e: self.assertEqual(e.code, constants.BUFFER_TOO_SMALL) try: decoder.decode(dec, packet, 3, 480, 0) except OpusError as e: self.assertEqual(e.code, constants.BUFFER_TOO_SMALL) try: decoder.decode(dec, packet, 3, 960, 0) except OpusError: self.fail('Decode failed') decoder.destroy(dec)
def test_decode(self): """opus_decode()""" packet = chr((63<<2)+3)+chr(49) for j in range(2, 51): packet += chr(0) dec = decoder.create(48000, 2) try: decoder.decode(dec, packet, 51, 960, 0) except OpusError as e: self.assertEqual(e.code, constants.INVALID_PACKET) packet = chr(63<<2)+chr(0)+chr(0) try: decoder.decode(dec, packet, -1, 960, 0) except OpusError as e: self.assertEqual(e.code, constants.BAD_ARG) try: decoder.decode(dec, packet, 3, 60, 0) except OpusError as e: self.assertEqual(e.code, constants.BUFFER_TOO_SMALL) try: decoder.decode(dec, packet, 3, 480, 0) except OpusError as e: self.assertEqual(e.code, constants.BUFFER_TOO_SMALL) try: decoder.decode(dec, packet, 3, 960, 0) except OpusError: self.fail('Decode failed') decoder.destroy(dec)
def decode(self, data): return opus_decoder.decode(self.decoder, data, length=len(data), frame_size=self.untalk.frame_size, decode_fec=self.untalk.decode_fec, channels=CHANNELS)
def decode(self, data): return opus_decoder.decode(self.decoder, data, len(data), self.chunk, self.fec, channels=self.channels)
def test_get_pitch(self): dec = decoder.create(48000, 2) i = decoder.ctl(dec, ctl.get_pitch) self.assertIn(i, (-1, 0)) packet = chr(63 << 2) + chr(0) + chr(0) decoder.decode(dec, packet, 3, 960, False) i = decoder.ctl(dec, ctl.get_pitch) self.assertIn(i, (-1, 0)) packet = chr(1) + chr(0) + chr(0) decoder.decode(dec, packet, 3, 960, False) i = decoder.ctl(dec, ctl.get_pitch) self.assertIn(i, (-1, 0)) decoder.destroy(dec)
def test_get_pitch(self): dec = decoder.create(48000, 2) i = decoder.ctl(dec, ctl.get_pitch) self.assertIn(i, (-1, 0)) packet = chr(63<<2)+chr(0)+chr(0) decoder.decode(dec, packet, 3, 960, False) i = decoder.ctl(dec, ctl.get_pitch) self.assertIn(i, (-1, 0)) packet = chr(1)+chr(0)+chr(0) decoder.decode(dec, packet, 3, 960, False) i = decoder.ctl(dec, ctl.get_pitch) self.assertIn(i, (-1, 0)) decoder.destroy(dec)
def run(self): while True: data = sock.recvfrom( INPUT_FRAMES_PER_BLOCK) # buffer size is 1024 bytes try: assert len(data[0]) == 136 (serial, ) = struct.unpack('q', data[0][:8]) raw_audio = decoder.decode(dec, data[0][8:], len(data[0][8:]), INPUT_FRAMES_PER_BLOCK, False, 1) #try: if len(buf) < MAX_BUFF_SIZE: heapq.heappush(buf, ((serial, raw_audio))) else: heapq.heappop(buf) heapq.heappush(buf, ((serial, raw_audio))) print "receiving and push to jb", serial #print len(buf) #except #print "Raw Data: ",raw_audio except AssertionError: print 'Didn\'t get full packet!' sys.exit(1)
def decode(self, data): out = opus_decoder.decode(self.decoder, data, len(data), self.frame_size, False, self.channels) return out
with open(inputfile,'r') as fr: print("Reading file %s..." % inputfile) for ln in fr: if ln.startswith("[Read]20"): str_pkt = ln[11:].strip() #if ln.startswith("20"): # str_pkt = ln[5:].strip() data += bytes.fromhex(str_pkt) fr.close() chunk_len = 640 index = 0 output = bytearray() encodeLength = 0 while (index < len(data)-encodeLength): encodeLength = data[index] encodeData = data[index+1:index+encodeLength+1] decodeData = decoder.decode(dec, bytes(encodeData), len(encodeData), chunk_len, 0); output.extend(decodeData[:chunk_len]) del data[index] index += encodeLength; with open(outputfile, 'wb') as fw: fw.write(output) print('Saved file %s!\n- 16bit, 16000Hz, 1 channel' % outputfile) fw.close()