MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / read_csv_audio

Function read_csv_audio

examples/csv2wav/csv2wav.py:41–71  ·  view source on GitHub ↗
(file_path)

Source from the content-addressed store, hash-verified

39
40
41def 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
74def sample_rate_from_times(times):

Callers 1

convert_csv_to_wavFunction · 0.85

Calls 3

openFunction · 0.85
find_audio_columnsFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected