Skip to content

Commit

Permalink
Merge pull request #314 from pipecat-ai/aleix/transcription-timestamps
Browse files Browse the repository at this point in the history
services: transcription timestamp should use ISO8601 format
  • Loading branch information
aconchillo authored Jul 23, 2024
2 parents eb998aa + 0852b50 commit 1676693
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to **pipecat** will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unrelease]

### Fixed

- STT services should be using ISO 8601 time format for transcription frames.

## [0.0.37] - 2024-07-22

### Added
Expand Down
7 changes: 4 additions & 3 deletions src/pipecat/services/deepgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#

import aiohttp
import time

from typing import AsyncGenerator

Expand All @@ -21,9 +20,11 @@
TranscriptionFrame)
from pipecat.processors.frame_processor import FrameDirection
from pipecat.services.ai_services import AsyncAIService, TTSService
from pipecat.utils.time import time_now_iso8601

from loguru import logger


# See .env.example for Deepgram configuration needed
try:
from deepgram import (
Expand Down Expand Up @@ -148,6 +149,6 @@ async def _on_message(self, *args, **kwargs):
transcript = result.channel.alternatives[0].transcript
if len(transcript) > 0:
if is_final:
await self.queue_frame(TranscriptionFrame(transcript, "", int(time.time_ns() / 1000000)))
await self.queue_frame(TranscriptionFrame(transcript, "", time_now_iso8601()))
else:
await self.queue_frame(InterimTranscriptionFrame(transcript, "", int(time.time_ns() / 1000000)))
await self.queue_frame(InterimTranscriptionFrame(transcript, "", time_now_iso8601()))
6 changes: 3 additions & 3 deletions src/pipecat/services/gladia.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import base64
import json
import time

from typing import Optional
from pydantic.main import BaseModel
Expand All @@ -22,6 +21,7 @@
TranscriptionFrame)
from pipecat.processors.frame_processor import FrameDirection
from pipecat.services.ai_services import AsyncAIService
from pipecat.utils.time import time_now_iso8601

from loguru import logger

Expand Down Expand Up @@ -110,6 +110,6 @@ async def _receive_task_handler(self):
transcript = utterance["transcription"]
if confidence >= self._confidence:
if type == "final":
await self.queue_frame(TranscriptionFrame(transcript, "", int(time.time_ns() / 1000000)))
await self.queue_frame(TranscriptionFrame(transcript, "", time_now_iso8601()))
else:
await self.queue_frame(InterimTranscriptionFrame(transcript, "", int(time.time_ns() / 1000000)))
await self.queue_frame(InterimTranscriptionFrame(transcript, "", time_now_iso8601()))
4 changes: 2 additions & 2 deletions src/pipecat/services/whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""This module implements Whisper transcription with a locally-downloaded model."""

import asyncio
import time

from enum import Enum
from typing_extensions import AsyncGenerator
Expand All @@ -16,6 +15,7 @@

from pipecat.frames.frames import ErrorFrame, Frame, TranscriptionFrame
from pipecat.services.ai_services import STTService
from pipecat.utils.time import time_now_iso8601

from loguru import logger

Expand Down Expand Up @@ -91,4 +91,4 @@ async def run_stt(self, audio: bytes) -> AsyncGenerator[Frame, None]:
if text:
await self.stop_ttfb_metrics()
logger.debug(f"Transcription: [{text}]")
yield TranscriptionFrame(text, "", int(time.time_ns() / 1000000))
yield TranscriptionFrame(text, "", time_now_iso8601())
11 changes: 11 additions & 0 deletions src/pipecat/utils/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Copyright (c) 2024, Daily
#
# SPDX-License-Identifier: BSD 2-Clause License
#

import datetime


def time_now_iso8601() -> str:
return datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="milliseconds")

0 comments on commit 1676693

Please sign in to comment.