From 1fe940bd6b6b2e8be70057bac390340341c9fc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Fri, 13 Sep 2024 13:10:44 -0700 Subject: [PATCH] servceis(cartesia,elevenlabs): use word start times instead --- src/pipecat/services/cartesia.py | 2 +- src/pipecat/services/elevenlabs.py | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pipecat/services/cartesia.py b/src/pipecat/services/cartesia.py index b15f266e9..ac02ea469 100644 --- a/src/pipecat/services/cartesia.py +++ b/src/pipecat/services/cartesia.py @@ -177,7 +177,7 @@ class CartesiaTTSService(AsyncWordTTSService): await self.add_word_timestamps([("LLMFullResponseEndFrame", 0)]) elif msg["type"] == "timestamps": await self.add_word_timestamps( - list(zip(msg["word_timestamps"]["words"], msg["word_timestamps"]["end"])) + list(zip(msg["word_timestamps"]["words"], msg["word_timestamps"]["start"])) ) elif msg["type"] == "chunk": await self.stop_ttfb_metrics() diff --git a/src/pipecat/services/elevenlabs.py b/src/pipecat/services/elevenlabs.py index ae3021ab6..6a3b85914 100644 --- a/src/pipecat/services/elevenlabs.py +++ b/src/pipecat/services/elevenlabs.py @@ -51,22 +51,17 @@ def sample_rate_from_output_format(output_format: str) -> int: def calculate_word_times( alignment_info: Mapping[str, Any], cumulative_time: float ) -> List[Tuple[str, float]]: - end_times = [ - s + d for s, - d in zip( - alignment_info["charStartTimesMs"], - alignment_info["charDurationsMs"])] - zipped_end_times = list(zip(alignment_info["chars"], end_times)) + zipped_times = list(zip(alignment_info["chars"], alignment_info["charStartTimesMs"])) words = "".join(alignment_info["chars"]).split(" ") - # Calculate end time for each word. We do this by finding a space character + # Calculate start time for each word. We do this by finding a space character # and using the previous word time, also taking into account there might not # be a space at the end. times = [] - for (i, (a, b)) in enumerate(zipped_end_times): - if a == " " or i == len(zipped_end_times) - 1: - t = cumulative_time + (zipped_end_times[i - 1][1] / 1000.0) + for (i, (a, b)) in enumerate(zipped_times): + if a == " " or i == len(zipped_times) - 1: + t = cumulative_time + (zipped_times[i - 1][1] / 1000.0) times.append(t) word_times = list(zip(words, times))