Esempio n. 1
0
    def test_lin2adpcm(self):
        self.assertEqual(audioop.lin2adpcm(datas[1], 1, None), (b"\x07\x7f\x7f", (-221, 39)))
        self.assertEqual(audioop.lin2adpcm(datas[2], 2, None), (b"\x07\x7f\x7f", (31, 39)))
        self.assertEqual(audioop.lin2adpcm(datas[4], 4, None), (b"\x07\x7f\x7f", (31, 39)))

        # Very cursory test
        for w in 1, 2, 4:
            self.assertEqual(audioop.lin2adpcm(b"\0" * w * 10, w, None), (b"\0" * 5, (0, 0)))
Esempio n. 2
0
    def test_lin2adpcm(self):
        self.assertEqual(audioop.lin2adpcm(datas[1], 1, None), (b"\x07\x7f\x7f", (-221, 39)))
        self.assertEqual(audioop.lin2adpcm(bytearray(datas[1]), 1, None), (b"\x07\x7f\x7f", (-221, 39)))
        self.assertEqual(audioop.lin2adpcm(memoryview(datas[1]), 1, None), (b"\x07\x7f\x7f", (-221, 39)))
        for w in 2, 3, 4:
            self.assertEqual(audioop.lin2adpcm(datas[w], w, None), (b"\x07\x7f\x7f", (31, 39)))

        # Very cursory test
        for w in 1, 2, 3, 4:
            self.assertEqual(audioop.lin2adpcm(b"\0" * w * 10, w, None), (b"\0" * 5, (0, 0)))
Esempio n. 3
0
    def test_lin2adpcm(self):
        self.assertEqual(audioop.lin2adpcm(datas[1], 1, None),
                         (b'\x07\x7f\x7f', (-221, 39)))
        self.assertEqual(audioop.lin2adpcm(datas[2], 2, None),
                         (b'\x07\x7f\x7f', (31, 39)))
        self.assertEqual(audioop.lin2adpcm(datas[4], 4, None),
                         (b'\x07\x7f\x7f', (31, 39)))

        # Very cursory test
        for w in 1, 2, 4:
            self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None),
                             (b'\0' * 5, (0, 0)))
Esempio n. 4
0
 def test_lin2adpcm(self):
     self.assertEqual(audioop.lin2adpcm(datas[1], 1, None),
                      (b'\x07\x7f\x7f', (-221, 39)))
     self.assertEqual(audioop.lin2adpcm(bytearray(datas[1]), 1, None),
                      (b'\x07\x7f\x7f', (-221, 39)))
     self.assertEqual(audioop.lin2adpcm(memoryview(datas[1]), 1, None),
                      (b'\x07\x7f\x7f', (-221, 39)))
     for w in (2, 3, 4):
         self.assertEqual(audioop.lin2adpcm(datas[w], w, None),
                          (b'\x07\x7f\x7f', (31, 39)))
     for w in (1, 2, 3, 4):
         self.assertEqual(audioop.lin2adpcm(b'\x00' * w * 10, w, None),
                          (b'\x00' * 5, (0, 0)))
Esempio n. 5
0
def testlin2adpcm(data):
    if verbose:
        print 'lin2adpcm'
    # Very cursory test
    if audioop.lin2adpcm('\0\0\0\0', 1, None) != ('\0\0', (0, 0)):
        return 0
    return 1
Esempio n. 6
0
def testlin2adpcm(data):
    if verbose:
        print 'lin2adpcm'
    # Very cursory test
    if audioop.lin2adpcm('\0\0\0\0', 1, None) <> ('\0\0', (0,0)):
        return 0
    return 1
Esempio n. 7
0
    def compress(self):
        read = wave.open(self.create_wave(), 'rb')
        string_wav = np.fromstring(read.readframes(-1), 'Int16')

        if (self.compression_mod == "a-LAW"):
            compressed_string = audioop.lin2alaw(string_wav,
                                                 read.getsampwidth())
            compressed_string = audioop.alaw2lin(compressed_string,
                                                 read.getsampwidth())
            self.working_signal = np.frombuffer(compressed_string,
                                                dtype='Int16')
        if (self.compression_mod == "u-LAW"):
            compressed_string = audioop.lin2ulaw(string_wav,
                                                 read.getsampwidth())
            compressed_string = audioop.ulaw2lin(compressed_string,
                                                 read.getsampwidth())
            self.working_signal = np.frombuffer(compressed_string,
                                                dtype='Int16')
        if (self.compression_mod == "ADPCM"):
            compressed_string = audioop.lin2adpcm(string_wav,
                                                  read.getsampwidth(), None)
            compressed_string = audioop.adpcm2lin(compressed_string[0],
                                                  read.getsampwidth(), None)
            self.working_signal = np.frombuffer(compressed_string[0],
                                                dtype='Int16')
Esempio n. 8
0
	def _lin2adpcm(self, data):
		import audioop
		if not hasattr(self, '_adpcmstate'):
			self._adpcmstate = None
		data, self._adpcmstate = audioop.lin2adpcm(data, 2,
							   self._adpcmstate)
		return data
Esempio n. 9
0
 def _lin2adpcm(self, data):
     with warnings.catch_warnings():
         warnings.simplefilter('ignore', category=DeprecationWarning)
         import audioop
     if not hasattr(self, '_adpcmstate'):
         self._adpcmstate = None
     data, self._adpcmstate = audioop.lin2adpcm(data, 2, self._adpcmstate)
     return data
Esempio n. 10
0
def convert_wave_data(f_rate,frame_count,sample_width,channels,data):
    """ Convert wave sample data into pleo format
    """
    if channels==2: data = audioop.tomono(data,sample_width,1,1)
    data = audioop.mul(data,sample_width,0.97999999999999998)
    data = audioop.ratecv(data,sample_width,1,f_rate,11025,None,4,4)[0]
    if sample_width==1:
       data = audioop.bias(data,1,-128)
       data = audioop.lin2lin(data,1,2)
    data = audioop.mul(data,2,(1.0/256))
    data = audioop.lin2adpcm(data,2,None)[0]
    return (11025,frame_count,sample_width,1,data)
Esempio n. 11
0
    def play_audio_as_adpcm(self, audio_file_name):
        """Play an audio file with 4-bit ADPCM compression at 9.6 kHz sampling"""
        print("Play Audio Msg - Start")

        self._serial.cancel_read()
        self._lock.acquire()
        try:
            #if not self._send(ENTER_VOICE_MODE):
            #    print("Error: Failed to put modem into voice mode.")
            #    return
            if not self._send(SET_VOICE_COMPRESSION_METHOD):
                print(
                    "Error: Failed to set compression method and sampling rate specifications."
                )
                return
            if not self._send(ENTER_TELEPHONE_ANSWERING_DEVICE_MODE):
                print("Error: Unable put modem into TAD mode.")
                return
            if not self._send(ENTER_VOICE_TRANSMIT_DATA_STATE, "CONNECT"):
                print("Error: Unable put modem into TAD data transmit state.")
                return

            time.sleep(1)

            # Play Audio File
            print("Play Audio Msg - playing wav file")

            wf = wave.open(audio_file_name, 'rb')
            chunk = 1024
            data = wf.readframes(chunk)

            state = None

            while data != '':
                adpcmfrag, state = audioop.lin2adpcm(data, 4, state)
                written = self._serial.write(adpcmfrag)
                if written == 0:
                    break
                data = wf.readframes(chunk)
                time.sleep(.05)
                # You may need to change this sleep interval to smooth-out the audio
            wf.close()

            print("End Phone output")

            # self._serial.flushInput()
            # self._serial.flushOutput()

            self._send(END_VOICE_TRANSMIT_DATA_STATE)
        finally:
            self._lock.release()

        print("Play Audio Msg - END")
Esempio n. 12
0
	def run(self):
		while 1:
			olddata = data = self.iport.readsamps(600)
			if self.do_ulaw:
				data = audioop.lin2ulaw(data, 2)
				data = audioop.ulaw2lin(data, 2)
			if self.do_adpcm:
				data, nacstate = audioop.lin2adpcm(data, 2, \
					  self.acstate)
				data, dummy = audioop.adpcm2lin(data, 2, \
					  self.acstate)
				self.acstate = nacstate
			if self.do_diff:
				olddata = audioop.mul(olddata, 2, -1)
				data = audioop.add(olddata, data, 2)
			self.oport.writesamps(data)
			fl.check_forms()
Esempio n. 13
0
	def run(self):
		while 1:
			olddata = data = self.iport.readsamps(600)
			if self.do_ulaw:
				data = audioop.lin2ulaw(data, 2)
				data = audioop.ulaw2lin(data, 2)
			if self.do_adpcm:
				data, nacstate = audioop.lin2adpcm(data, 2, \
					  self.acstate)
				data, dummy = audioop.adpcm2lin(data, 2, \
					  self.acstate)
				self.acstate = nacstate
			if self.do_diff:
				olddata = audioop.mul(olddata, 2, -1)
				data = audioop.add(olddata, data, 2)
			self.oport.writesamps(data)
			fl.check_forms()
Esempio n. 14
0
 def load_sample(self, name, filename):
     f = wave.open(filename, "rb")
     if f.getnchannels() != 1:
         print "Sorry - .wav file must be mono"
         sys.exit(1)
     if f.getsampwidth() != 2:
         print "Sorry - .wav file must be 16-bit"
         sys.exit(1)
     freq = f.getframerate()
     pcm16 = f.readframes(f.getnframes())
     (adpcm, _) = audioop.lin2adpcm(pcm16, f.getsampwidth(), (0,0))
     adpcm = adpcm[:len(adpcm) & ~7]
     da = array.array('B', [((ord(c) >> 4) | ((15 & ord(c)) << 4)) for c in adpcm])
     self.align(8)
     self.add(name, da.tostring())
     self.define(name + "_LENGTH", len(da))
     self.define(name + "_FREQ", freq)
Esempio n. 15
0
 def test_lin2adpcm(self):
     # Very cursory test
     self.assertEqual(audioop.lin2adpcm('\0\0\0\0', 1, None),
                      ('\0\0', (0, 0)))
Esempio n. 16
0
 def test_lin2adpcm(self):
     # Very cursory test
     self.assertEqual(audioop.lin2adpcm('\0\0\0\0', 1, None), ('\0\0', (0,0)))
Esempio n. 17
0
def testlin2adpcm(data):
	# Very cursory test
	if audioop.lin2adpcm('\0\0\0\0', 1, None) <> ('\0\0', (0,0)):
		return 0
	return 1
Esempio n. 18
0
 def code(self, data):
     data, self.state = audioop.lin2adpcm(data, self.width, self.state)
     return data
Esempio n. 19
0
def callback(input_data, frame_count, time_info, status):
    message = audioop.lin2adpcm(input_data, 2, None)
    message = audioop.adpcm2lin(message[0], 2, None)
    return (message[0], pyaudio.paContinue)
Esempio n. 20
0
 def compress(self, frames):
     state = (None, None)
     for frame in frames:
         state = audioop.lin2adpcm(frame, self.sample_size, state[1])
         yield state[0]
Esempio n. 21
0
# Compare different audio compression schemes.
def callback(input_data, frame_count, time_info, status):
    data = wf.readframes(frame_count)
    message = audioop.lin2adpcm(data, 2, None)
    get_transcription(message[0])
    return (input_data, pyaudio.paContinue)
Esempio n. 23
0
# Compare different audio compression schemes.
Esempio n. 24
0
"""Stuff to parse AIFF-C and AIFF files.
Esempio n. 25
0
def adpcm_compress(np_array, sample_width):
    compressed = audioop.lin2adpcm(np_array, sample_width, None)
    return np.frombuffer(audioop.adpcm2lin(compressed[0], sample_width,
                                           None)[0],
                         dtype=np.int16)
Esempio n. 26
0
 def readframes(self, nframes=-1):
     import audioop
     data, nframes = self._rdr.readframes(nframes)
     data, self.__state = audioop.lin2adpcm(data, self.__width,
                                            self.__state)
     return data, nframes