1313def audio_read (fullpath_aq8_rec_or_wav , start_tic , stop_tic ,
1414 nchan = 8 , ncomments = 3 , Fs = "smpl.frq= ([0-9.]+)Hz" , mmap = True , ** kw ):
1515 if not start_tic : start_tic = 0
16-
1716 ext = os .path .splitext (fullpath_aq8_rec_or_wav )[1 ]
17+
1818 if ext .startswith (".aq" + str (nchan )):
1919 tmp = fullpath_aq8_rec_or_wav .split ('-' )
2020 fullpath_aq8 , rec = '-' .join (tmp [:- 1 ]), tmp [- 1 ]
@@ -47,7 +47,6 @@ def audio_read(fullpath_aq8_rec_or_wav, start_tic, stop_tic,
4747 if np .ndim (data )== 1 :
4848 data = np .expand_dims (data , axis = 1 )
4949
50- if not start_tic : start_tic = 0
5150 if not stop_tic : stop_tic = np .shape (data )[0 ]+ 1
5251
5352 start_tic_clamped = max (0 , start_tic )
@@ -57,22 +56,44 @@ def audio_read(fullpath_aq8_rec_or_wav, start_tic, stop_tic,
5756
5857 return sampling_rate , data .shape , data_sliced
5958
59+ elif ext in Dexts :
60+ with open (fullpath_aq8_rec_or_wav , 'rb' ) as fid :
61+ for _ in range (ncomments ):
62+ line = fid .readline ().decode ()
63+ m = re .search (Fs , line )
64+ if m : sampling_rate = float (m .group (1 ))
65+ n0 = fid .tell ()
66+ n1 = fid .seek (0 ,2 )
67+ nsamples = (n1 - n0 )// 4
68+ fid .seek (n0 )
69+ if not stop_tic : stop_tic = nsamples
70+ fid .seek (4 * start_tic , 1 )
71+ b = fid .read (4 * (stop_tic - start_tic ))
72+
73+ v = np .frombuffer (b , dtype = np .float32 )
74+ a = np .reshape (v , (- 1 ,1 ))
75+ c = (a / 10 * np .iinfo (np .int16 ).max ).astype (np .int16 )
76+
77+ return sampling_rate , (nsamples ,1 ), c
78+
6079def audio_read_exts (nchan = 8 , ** kw ):
61- return ['.aq' + str (nchan ), '.wav' , '.WAV' ]
80+ return ['.aq' + str (nchan ), '.wav' , '.WAV' , * Dexts ]
6281
6382def audio_read_rec2ch (fullpath_aq8_or_wav , nchan = 8 , ** kw ):
6483 ext = os .path .splitext (fullpath_aq8_or_wav )[1 ]
6584 if ext == ".aq" + str (nchan ):
6685 return {"rec" + chr (65 + i ):[i ] for i in range (nchan )}
67- elif ext in ['.wav' , '.WAV' ]:
86+ elif ext in ['.wav' , '.WAV' ] or ext in Dexts :
6887 return {'recA' :[0 ]}
6988
7089def audio_read_strip_rec (fullpath_aq8_rec_or_wav , nchan = 8 , ** kw ):
7190 ext = os .path .splitext (fullpath_aq8_rec_or_wav )[1 ]
7291 if ext .startswith (".aq" + str (nchan )):
7392 return fullpath_aq8_rec_or_wav [:- 5 ]
74- elif ext in ['.wav' , '.WAV' ]:
93+ elif ext in ['.wav' , '.WAV' ] or ext in Dexts :
7594 return fullpath_aq8_rec_or_wav
7695
7796def audio_read_init (** kw ):
97+ global Dexts
98+ Dexts = ['.D' + str (x ).zfill (2 ) for x in range (1 ,99 )]
7899 pass
0 commit comments