(
csv_path,
wav_path=None,
sample_rate=None,
in_format="float32",
dither=False,
)
| 145 | |
| 146 | |
| 147 | def convert_csv_to_wav( |
| 148 | csv_path, |
| 149 | wav_path=None, |
| 150 | sample_rate=None, |
| 151 | in_format="float32", |
| 152 | dither=False, |
| 153 | ): |
| 154 | if in_format not in INPUT_FORMATS: |
| 155 | raise ValueError( |
| 156 | f"Unsupported input format '{in_format}'. Supported: {', '.join(INPUT_FORMATS)}" |
| 157 | ) |
| 158 | |
| 159 | raw, times = read_csv_audio(csv_path) |
| 160 | audio_float = decode_input_to_float(raw, in_format) |
| 161 | |
| 162 | # An explicit --rate always wins; otherwise prefer the rate implied by the |
| 163 | # Elapsed (s) column, and fall back to the default for time-less CSVs. |
| 164 | if sample_rate is None: |
| 165 | detected = sample_rate_from_times(times) |
| 166 | if detected: |
| 167 | sample_rate = detected |
| 168 | print(f"Detected sample rate from timestamps: {sample_rate} Hz") |
| 169 | else: |
| 170 | sample_rate = DEFAULT_SAMPLE_RATE |
| 171 | print(f"No usable timestamps; using default {sample_rate} Hz") |
| 172 | |
| 173 | if wav_path is None: |
| 174 | base = os.path.splitext(csv_path)[0] |
| 175 | wav_path = base + ".wav" |
| 176 | |
| 177 | write_wav(audio_float, sample_rate, wav_path, dither=dither) |
| 178 | print(f"WAV file written: {wav_path}") |
| 179 | |
| 180 | |
| 181 | def main(): |
no test coverage detected