From 0ffaa09c9507f9fd6b75c462b20f33931665fdb0 Mon Sep 17 00:00:00 2001 From: ivaaan Date: Fri, 5 Dec 2025 19:00:47 +0100 Subject: [PATCH 1/3] add tracking headers to Hume service --- src/pipecat/services/hume/tts.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pipecat/services/hume/tts.py b/src/pipecat/services/hume/tts.py index a2472c6d3..6b256961e 100644 --- a/src/pipecat/services/hume/tts.py +++ b/src/pipecat/services/hume/tts.py @@ -8,9 +8,11 @@ import base64 import os from typing import Any, AsyncGenerator, Optional +import httpx from loguru import logger from pydantic import BaseModel +from pipecat import __version__ from pipecat.frames.frames import ( ErrorFrame, Frame, @@ -26,11 +28,7 @@ from pipecat.utils.tracing.service_decorators import traced_tts try: from hume import AsyncHumeClient - from hume.tts import ( - FormatPcm, - PostedUtterance, - PostedUtteranceVoiceWithId, - ) + from hume.tts import FormatPcm, PostedUtterance, PostedUtteranceVoiceWithId from hume.tts.types import TimestampMessage except ModuleNotFoundError as e: # pragma: no cover - import-time guidance logger.error(f"Exception: {e}") @@ -40,6 +38,12 @@ except ModuleNotFoundError as e: # pragma: no cover - import-time guidance HUME_SAMPLE_RATE = 48_000 # Hume TTS streams at 48 kHz +# Tracking headers for Hume API requests +DEFAULT_HEADERS = { + "X-Hume-Client-Name": "pipecat", + "X-Hume-Client-Version": __version__, +} + class HumeTTSService(WordTTSService): """Hume Octave Text-to-Speech service. @@ -104,7 +108,11 @@ class HumeTTSService(WordTTSService): **kwargs, ) - self._client = AsyncHumeClient(api_key=api_key) + # Create a custom httpx.AsyncClient with tracking headers + # Headers are included in all requests made by the Hume SDK + custom_http_client = httpx.AsyncClient(headers=DEFAULT_HEADERS) + + self._client = AsyncHumeClient(api_key=api_key, httpx_client=custom_http_client) self._params = params or HumeTTSService.InputParams() # Store voice in the base class (mirrors other services) From 8c6ef21d84720ed59d854a50b3910eaf440efebb Mon Sep 17 00:00:00 2001 From: ivaaan Date: Fri, 5 Dec 2025 20:13:58 +0100 Subject: [PATCH 2/3] add stop, cancel --- src/pipecat/services/hume/tts.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/pipecat/services/hume/tts.py b/src/pipecat/services/hume/tts.py index 6b256961e..6571bff0f 100644 --- a/src/pipecat/services/hume/tts.py +++ b/src/pipecat/services/hume/tts.py @@ -14,6 +14,8 @@ from pydantic import BaseModel from pipecat import __version__ from pipecat.frames.frames import ( + CancelFrame, + EndFrame, ErrorFrame, Frame, InterruptionFrame, @@ -110,9 +112,9 @@ class HumeTTSService(WordTTSService): # Create a custom httpx.AsyncClient with tracking headers # Headers are included in all requests made by the Hume SDK - custom_http_client = httpx.AsyncClient(headers=DEFAULT_HEADERS) + self._http_client = httpx.AsyncClient(headers=DEFAULT_HEADERS) - self._client = AsyncHumeClient(api_key=api_key, httpx_client=custom_http_client) + self._client = AsyncHumeClient(api_key=api_key, httpx_client=self._http_client) self._params = params or HumeTTSService.InputParams() # Store voice in the base class (mirrors other services) @@ -146,6 +148,26 @@ class HumeTTSService(WordTTSService): self._cumulative_time = 0.0 self._started = False + async def stop(self, frame: EndFrame) -> None: + """Stop the service and cleanup resources. + + Args: + frame: The end frame. + """ + await super().stop(frame) + if hasattr(self, "_http_client") and self._http_client: + await self._http_client.aclose() + + async def cancel(self, frame: CancelFrame) -> None: + """Cancel the service and cleanup resources. + + Args: + frame: The cancel frame. + """ + await super().cancel(frame) + if hasattr(self, "_http_client") and self._http_client: + await self._http_client.aclose() + async def push_frame(self, frame: Frame, direction: FrameDirection = FrameDirection.DOWNSTREAM): """Push a frame and handle state changes. From 41214236ab0abe25302ed4875aa54f5d16211e10 Mon Sep 17 00:00:00 2001 From: ivaaan Date: Fri, 5 Dec 2025 20:47:04 +0100 Subject: [PATCH 3/3] add changelog --- changelog/3195.changed.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/3195.changed.md diff --git a/changelog/3195.changed.md b/changelog/3195.changed.md new file mode 100644 index 000000000..29df2589e --- /dev/null +++ b/changelog/3195.changed.md @@ -0,0 +1,3 @@ +- Added tracking headers (`X-Hume-Client-Name` and `X-Hume-Client-Version`) to all requests made by `HumeTTSService` to the Hume API for better usage tracking and analytics. +- Added `stop()` and `cancel()` cleanup methods to `HumeTTSService` to properly close the HTTP client and prevent resource leaks. +