(file_path)
| 39 | |
| 40 | |
| 41 | def read_csv_audio(file_path): |
| 42 | # utf-8-sig transparently strips the UTF-8 BOM that Serial Studio writes on |
| 43 | # the first column header; without it the BOM corrupts the first match. |
| 44 | with open(file_path, "r", newline="", encoding="utf-8-sig") as f: |
| 45 | reader = csv.reader(f) |
| 46 | headers = next(reader) |
| 47 | |
| 48 | audio_cols = find_audio_columns(headers) |
| 49 | if not audio_cols: |
| 50 | raise ValueError("No audio channels found in CSV headers") |
| 51 | |
| 52 | time_col = None |
| 53 | if headers and headers[0].strip() == TIME_HEADER: |
| 54 | time_col = 0 |
| 55 | |
| 56 | rows = [] |
| 57 | times = [] |
| 58 | for row in reader: |
| 59 | try: |
| 60 | vals = [float(row[i]) for i in audio_cols] |
| 61 | rows.append(vals) |
| 62 | if time_col is not None: |
| 63 | times.append(float(row[time_col])) |
| 64 | except Exception: |
| 65 | continue |
| 66 | |
| 67 | audio = np.asarray(rows, dtype=np.float32) |
| 68 | if audio.ndim == 1: |
| 69 | audio = audio[:, None] |
| 70 | audio = np.nan_to_num(audio, nan=0.0, posinf=0.0, neginf=0.0) |
| 71 | return audio, times |
| 72 | |
| 73 | |
| 74 | def sample_rate_from_times(times): |
no test coverage detected