From 3cbe97d346c42d5694ba06f35ec92d2c5feeab00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 12 Sep 2024 00:31:23 -0700 Subject: [PATCH] clocks: added new BaseClock and SystemClock --- src/pipecat/clocks/__init__.py | 0 src/pipecat/clocks/base_clock.py | 18 ++++++++++++++++++ src/pipecat/clocks/system_clock.py | 21 +++++++++++++++++++++ src/pipecat/transcriptions/__init__.py | 0 4 files changed, 39 insertions(+) create mode 100644 src/pipecat/clocks/__init__.py create mode 100644 src/pipecat/clocks/base_clock.py create mode 100644 src/pipecat/clocks/system_clock.py create mode 100644 src/pipecat/transcriptions/__init__.py diff --git a/src/pipecat/clocks/__init__.py b/src/pipecat/clocks/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/pipecat/clocks/base_clock.py b/src/pipecat/clocks/base_clock.py new file mode 100644 index 000000000..aa7b7b806 --- /dev/null +++ b/src/pipecat/clocks/base_clock.py @@ -0,0 +1,18 @@ +# +# Copyright (c) 2024, Daily +# +# SPDX-License-Identifier: BSD 2-Clause License +# + +from abc import ABC, abstractmethod + + +class BaseClock(ABC): + + @abstractmethod + def get_time(self) -> int: + pass + + @abstractmethod + def start(self): + pass diff --git a/src/pipecat/clocks/system_clock.py b/src/pipecat/clocks/system_clock.py new file mode 100644 index 000000000..20319cff6 --- /dev/null +++ b/src/pipecat/clocks/system_clock.py @@ -0,0 +1,21 @@ +# +# Copyright (c) 2024, Daily +# +# SPDX-License-Identifier: BSD 2-Clause License +# + +import time + +from pipecat.clocks.base_clock import BaseClock + + +class SystemClock(BaseClock): + + def __init__(self): + self._time = 0 + + def get_time(self) -> int: + return time.monotonic_ns() - self._time if self._time > 0 else 0 + + def start(self): + self._time = time.monotonic_ns() diff --git a/src/pipecat/transcriptions/__init__.py b/src/pipecat/transcriptions/__init__.py new file mode 100644 index 000000000..e69de29bb