| | |
| | | step_index: int, |
| | | wav_bytes: bytes, |
| | | conn: Any = None, |
| | | text: Optional[str] = None, |
| | | ) -> Optional[str]: |
| | | """Persist the follow-read utterance. Returns relative audio_id or None.""" |
| | | if not wav_bytes: |
| | |
| | | if conn is not None: |
| | | from core.audio_archive import archive_wav |
| | | |
| | | archived = archive_wav(conn, wav_bytes, kind="asr", extra=extra) |
| | | archived = archive_wav(conn, wav_bytes, kind="asr", extra=extra, text=text) |
| | | if archived: |
| | | return archived |
| | | if not session_id: |
| | | return None |
| | | try: |
| | | from config.config_loader import get_project_dir |
| | | from core.audio_archive import write_sidecar_text |
| | | |
| | | directory = os.path.join(get_project_dir(), "data", "task_sessions", "audio") |
| | | os.makedirs(directory, exist_ok=True) |
| | |
| | | path = os.path.join(directory, filename) |
| | | with open(path, "wb") as handle: |
| | | handle.write(wav_bytes) |
| | | if text is not None: |
| | | write_sidecar_text(path, text) |
| | | return filename |
| | | except Exception: |
| | | return None |