From 6be6f91761f2bf36a8f91ee1780fd1200caa4a8a Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 2 Oct 2020 17:13:34 +0100 Subject: [PATCH] Added support for reading a single AMBE file --- read_ambe.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/read_ambe.py b/read_ambe.py index 2918d9d..0981570 100644 --- a/read_ambe.py +++ b/read_ambe.py @@ -13,6 +13,7 @@ class readAMBE: for i in range(0, len(data), 108): yield bitarray([k for k in islice(it, 108)] ) + #Read indexed files def readfiles(self): _AMBE_LENGTH = 9 indexDict = {} @@ -61,9 +62,43 @@ class readAMBE: bitarray('001010110000001010101000000100000000000010000000000000000000000100010000000100000000001000000000001000000000')] ]) return _wordBADict - + + def readSingleFile(self,filename): + ambeBytearray = {} + _wordBitarray = bitarray(endian='big') + _wordBA= [] + try: + with open(self.path+filename,'rb') as ambe: + _wordBitarray.frombytes(ambe.read()) + #108 + _wordBA = [] + pairs = 1 + _lastburst = '' + for _burst in self._make_bursts(_wordBitarray): +#Not sure if we need to pad or not? Seems to make little difference. + if len(_burst) < 108: + pad = (108 - len(_burst)) + for i in range(0,pad,1): + _burst.append(False) + if pairs == 2: + _wordBA.append([_lastburst,_burst]) + _lastburst = '' + pairs = 1 + next + else: + pairs = pairs + 1 + _lastburst = _burst + + _wordBitarray.clear() + ambe.close() + except IOError: + return(False) + + return(_wordBA) + + if __name__ == '__main__': test = readAMBE('en_GB','./Audio/') - print(test.readfiles()) + print(test.readSingleFile('44xx.ambe'))