13
13
def audio_read (fullpath_aq8_rec_or_wav , start_tic , stop_tic ,
14
14
nchan = 8 , ncomments = 3 , Fs = "smpl.frq= ([0-9.]+)Hz" , mmap = True , ** kw ):
15
15
if not start_tic : start_tic = 0
16
-
17
16
ext = os .path .splitext (fullpath_aq8_rec_or_wav )[1 ]
17
+
18
18
if ext .startswith (".aq" + str (nchan )):
19
19
tmp = fullpath_aq8_rec_or_wav .split ('-' )
20
20
fullpath_aq8 , rec = '-' .join (tmp [:- 1 ]), tmp [- 1 ]
@@ -47,7 +47,6 @@ def audio_read(fullpath_aq8_rec_or_wav, start_tic, stop_tic,
47
47
if np .ndim (data )== 1 :
48
48
data = np .expand_dims (data , axis = 1 )
49
49
50
- if not start_tic : start_tic = 0
51
50
if not stop_tic : stop_tic = np .shape (data )[0 ]+ 1
52
51
53
52
start_tic_clamped = max (0 , start_tic )
@@ -57,22 +56,44 @@ def audio_read(fullpath_aq8_rec_or_wav, start_tic, stop_tic,
57
56
58
57
return sampling_rate , data .shape , data_sliced
59
58
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
+
60
79
def audio_read_exts (nchan = 8 , ** kw ):
61
- return ['.aq' + str (nchan ), '.wav' , '.WAV' ]
80
+ return ['.aq' + str (nchan ), '.wav' , '.WAV' , * Dexts ]
62
81
63
82
def audio_read_rec2ch (fullpath_aq8_or_wav , nchan = 8 , ** kw ):
64
83
ext = os .path .splitext (fullpath_aq8_or_wav )[1 ]
65
84
if ext == ".aq" + str (nchan ):
66
85
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 :
68
87
return {'recA' :[0 ]}
69
88
70
89
def audio_read_strip_rec (fullpath_aq8_rec_or_wav , nchan = 8 , ** kw ):
71
90
ext = os .path .splitext (fullpath_aq8_rec_or_wav )[1 ]
72
91
if ext .startswith (".aq" + str (nchan )):
73
92
return fullpath_aq8_rec_or_wav [:- 5 ]
74
- elif ext in ['.wav' , '.WAV' ]:
93
+ elif ext in ['.wav' , '.WAV' ] or ext in Dexts :
75
94
return fullpath_aq8_rec_or_wav
76
95
77
96
def audio_read_init (** kw ):
97
+ global Dexts
98
+ Dexts = ['.D' + str (x ).zfill (2 ) for x in range (1 ,99 )]
78
99
pass
0 commit comments