Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playai: enable streaming TTS #1340

Merged
merged 8 commits into from
Jan 10, 2025
Merged

playai: enable streaming TTS #1340

merged 8 commits into from
Jan 10, 2025

Conversation

davidzhao
Copy link
Member

No description provided.

@davidzhao davidzhao requested a review from jayeshp19 January 6, 2025 22:51
Copy link

changeset-bot bot commented Jan 6, 2025

🦋 Changeset detected

Latest commit: 66c72e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-plugins-playai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@theomonnom theomonnom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

@jayeshp19
Copy link
Collaborator

jayeshp19 commented Jan 9, 2025

Relocated client creation to the _run method to handle occasional WebSocket connection drops by creating a new client.

@jayeshp19 jayeshp19 requested a review from theomonnom January 9, 2025 12:51
Comment on lines +241 to +244
self._client = PlayHTAsyncClient(
user_id=self._user_id,
api_key=self._api_key,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to recreate a new client for every request?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a workaround for now. WebSocket connection drops from playht server sometimes and it's not handled in pyht sdk.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey guys, this is causing latency problems for customers--there is a significant overhead around creating the connection on every request.

Copy link
Collaborator

@jayeshp19 jayeshp19 Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, The workaround was introduced to mitigate occasional connection drops from the PlayHT server, as the current pyht SDK doesn't seem to handle these drops robustly.

packages/pyht/async_client.py", line 471, in _tts_ws
    await self._ws.send(json.dumps(json_data))
  File "/Users/jayesh/dev/livekit/agents/venv/lib/python3.10/site-packages/websockets/asyncio/connection.py", line 403, in send
    async with self.send_context():
  File "/opt/homebrew/Cellar/[email protected]/3.10.16/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 199, in __aenter__
    return await anext(self.gen)
  File "/Users/jayesh/dev/livekit/agents/venv/lib/python3.10/site-packages/websockets/asyncio/connection.py", line 873, in send_context
    raise self.protocol.close_exc from original_exc
websockets.exceptions.ConnectionClosedError: no close frame received or sent

Could the SDK be updated to include automatic reconnection? This would greatly help reduce overhead

Let me know your thoughts!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify for me the pyht version that you have installed (even if a newer one is in your requirements.txt, maybe it has not actually been upgraded)?

Currently the ws.send() call is in a try-except that should re-establish the connection if there is an exception. Could be it is still dropping this somehow! But curious if upgrading to the latest pyht will help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I figured out how this can still occur even in the latest pyht.

It is a little hard to test it as I have not been able to reproduce the disconnect, but I have a PR here and will try to have it tested and released tomorrow so you can remove the per-request reconnection.

@davidzhao davidzhao merged commit 5eb41e9 into main Jan 10, 2025
14 checks passed
@davidzhao davidzhao deleted the playai-streaming branch January 10, 2025 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants