feat: add voice studio prototype flow
This commit is contained in:
@@ -26,6 +26,38 @@ def build_turn_assistant_audio_path(session_id: str, turn_index: int) -> Path:
|
||||
return session_storage_dir(session_id) / f"turn-{turn_index:03d}-assistant.mp3"
|
||||
|
||||
|
||||
def _normalize_audio_suffix(file_name: str | None, mime_type: str | None) -> str:
|
||||
if file_name and "." in file_name:
|
||||
return file_name.rsplit(".", 1)[-1].lower()
|
||||
|
||||
if mime_type == "audio/webm":
|
||||
return "webm"
|
||||
if mime_type == "audio/wav":
|
||||
return "wav"
|
||||
if mime_type == "audio/mpeg":
|
||||
return "mp3"
|
||||
if mime_type == "audio/mp4":
|
||||
return "m4a"
|
||||
return "bin"
|
||||
|
||||
|
||||
def write_uploaded_user_audio(
|
||||
*,
|
||||
session_id: str,
|
||||
turn_index: int,
|
||||
file_name: str | None,
|
||||
mime_type: str | None,
|
||||
audio_data: bytes,
|
||||
) -> str:
|
||||
"""Persist one uploaded user-audio turn and return the saved file path."""
|
||||
|
||||
suffix = _normalize_audio_suffix(file_name, mime_type)
|
||||
return write_session_audio(
|
||||
build_turn_user_audio_path(session_id, turn_index, suffix),
|
||||
audio_data,
|
||||
)
|
||||
|
||||
|
||||
def write_session_audio(path: Path, audio_data: bytes) -> str:
|
||||
"""Persist session audio bytes atomically and return the saved path."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user