cartesia async fixed

This commit is contained in:
Kwindla Hultman Kramer
2024-06-06 11:24:26 -04:00
parent 3eff1e559b
commit aee3916cd1
3 changed files with 4 additions and 15 deletions

View File

@@ -19,7 +19,6 @@ from pipecat.services.cartesia import CartesiaTTSService
from pipecat.services.openai import OpenAILLMService from pipecat.services.openai import OpenAILLMService
from pipecat.transports.services.daily import DailyParams, DailyTransport from pipecat.transports.services.daily import DailyParams, DailyTransport
from pipecat.vad.silero import SileroVADAnalyzer from pipecat.vad.silero import SileroVADAnalyzer
from pipecat.processors.logger import FrameLogger
from runner import configure from runner import configure
@@ -73,9 +72,7 @@ async def main(room_url: str, token):
tma_in, # User responses tma_in, # User responses
llm, # LLM llm, # LLM
tts, # TTS tts, # TTS
FrameLogger("tts out"),
transport.output(), # Transport bot output transport.output(), # Transport bot output
FrameLogger("transport out"),
tma_out # Assistant spoken responses tma_out # Assistant spoken responses
]) ])

View File

@@ -72,9 +72,7 @@ async def main(room_url: str, token):
tma_in, # User responses tma_in, # User responses
llm, # LLM llm, # LLM
tts, # TTS tts, # TTS
FrameLogger("tts out"),
transport.output(), # Transport bot output transport.output(), # Transport bot output
FrameLogger("transport out"),
tma_out # Assistant spoken responses tma_out # Assistant spoken responses
]) ])

View File

@@ -17,8 +17,8 @@ from pipecat.services.ai_services import TTSService
from loguru import logger from loguru import logger
try: try:
from pyht import Client
from pyht.client import TTSOptions from pyht.client import TTSOptions
from pyht.async_client import AsyncClient
from pyht.protos.api_pb2 import Format from pyht.protos.api_pb2 import Format
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
logger.error(f"Exception: {e}") logger.error(f"Exception: {e}")
@@ -35,7 +35,7 @@ class PlayHTTTSService(TTSService):
self._user_id = user_id self._user_id = user_id
self._speech_key = api_key self._speech_key = api_key
self._client = Client( self._client = AsyncClient(
user_id=self._user_id, user_id=self._user_id,
api_key=self._speech_key, api_key=self._speech_key,
) )
@@ -53,15 +53,10 @@ class PlayHTTTSService(TTSService):
ttfb = None ttfb = None
logger.debug(f"Generating TTS: [{text}]") logger.debug(f"Generating TTS: [{text}]")
async def async_generator(sync_gen):
for item in sync_gen:
await asyncio.sleep(0) # Yield control back to the event loop
yield item
try: try:
b = bytearray() b = bytearray()
in_header = True in_header = True
sync_gen = self._client.tts( playht_gen = self._client.tts(
text, text,
voice_engine="PlayHT2.0-turbo", voice_engine="PlayHT2.0-turbo",
options=self._options) options=self._options)
@@ -69,8 +64,7 @@ class PlayHTTTSService(TTSService):
# need to ask Aleix about this. frames are getting pushed. # need to ask Aleix about this. frames are getting pushed.
# but playback is blocked # but playback is blocked
# for chunk in sync_gen: async for chunk in playht_gen:
async for chunk in async_generator(sync_gen):
# skip the RIFF header. # skip the RIFF header.
if in_header: if in_header:
b.extend(chunk) b.extend(chunk)