mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-10 11:12:13 +02:00
Feat/enhanced timestamped transcript (#501)
* feat: add additional timestamps in call transcript optionally * fi: timestamp precision to millisec instead of micro * fix: address enhanced transcript review issues * fix: non vad user turn timestamp
This commit is contained in:
parent
d9b9a1efc8
commit
ac01f7775e
12 changed files with 441 additions and 15 deletions
|
|
@ -3,11 +3,26 @@ from typing import List
|
|||
from pipecat.utils.enums import RealtimeFeedbackType
|
||||
|
||||
|
||||
def generate_transcript_text(events: List[dict]) -> str:
|
||||
def _format_timestamp_range(payload: dict, event: dict, include_end_timestamps: bool) -> str:
|
||||
start_timestamp = payload.get("timestamp") or event.get("timestamp", "")
|
||||
if not include_end_timestamps:
|
||||
return start_timestamp
|
||||
|
||||
end_timestamp = payload.get("end_timestamp")
|
||||
if end_timestamp:
|
||||
return f"{start_timestamp} -> {end_timestamp}" if start_timestamp else end_timestamp
|
||||
return start_timestamp
|
||||
|
||||
|
||||
def generate_transcript_text(
|
||||
events: List[dict], *, include_end_timestamps: bool = False
|
||||
) -> str:
|
||||
"""Generate transcript text from realtime feedback events.
|
||||
|
||||
Filters for rtf-user-transcription (final) and rtf-bot-text events,
|
||||
formats them as '[timestamp] user/assistant: text\\n'.
|
||||
formats them as '[timestamp] user/assistant: text\\n'. When
|
||||
include_end_timestamps is True, formats as
|
||||
'[start_timestamp -> end_timestamp] user/assistant: text\\n'.
|
||||
"""
|
||||
lines: List[str] = []
|
||||
for event in events:
|
||||
|
|
@ -18,11 +33,11 @@ def generate_transcript_text(events: List[dict]) -> str:
|
|||
event_type == RealtimeFeedbackType.USER_TRANSCRIPTION.value
|
||||
and payload.get("final") is True
|
||||
):
|
||||
timestamp = payload.get("timestamp") or event.get("timestamp", "")
|
||||
timestamp = _format_timestamp_range(payload, event, include_end_timestamps)
|
||||
prefix = f"[{timestamp}] " if timestamp else ""
|
||||
lines.append(f"{prefix}user: {payload.get('text', '')}\n")
|
||||
elif event_type == RealtimeFeedbackType.BOT_TEXT.value:
|
||||
timestamp = payload.get("timestamp") or event.get("timestamp", "")
|
||||
timestamp = _format_timestamp_range(payload, event, include_end_timestamps)
|
||||
prefix = f"[{timestamp}] " if timestamp else ""
|
||||
lines.append(f"{prefix}assistant: {payload.get('text', '')}\n")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue