Added support for reading a single AMBE file

This commit is contained in:
Simon 2020-10-02 17:13:34 +01:00
parent 785f86b93b
commit 6be6f91761
1 changed files with 37 additions and 2 deletions

View File

@ -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'))