{"id":27281,"library":"pyht","title":"PlayHT Python Library","description":"The official Python client for PlayHT's text-to-speech API. Current version 0.1.14, supports Python 3.8+. The library provides async and sync clients, WebSocket streaming, and support for PlayHT 2.0 and HD voices. Release cadence is irregular.","status":"active","version":"0.1.14","language":"python","source_language":"en","source_url":"https://github.com/playht/pyht","tags":["text-to-speech","playht","tts","audio","api"],"install":[{"cmd":"pip install pyht","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"The top-level import is the correct one; the internal module path may break in future versions.","wrong":"from pyht.client import Client","symbol":"Client","correct":"from pyht import Client"},{"note":"TTSOptions is re-exported from the top-level module. Importing from submodules is fragile.","wrong":"from pyht.options import TTSOptions","symbol":"TTSOptions","correct":"from pyht import TTSOptions"},{"note":"Format enum is available at top level.","wrong":"from pyht.format import Format","symbol":"Format","correct":"from pyht import Format"}],"quickstart":{"code":"import os\nfrom pyht import Client, TTSOptions, Format\n\nclient = Client(\n    user_id=os.environ.get('PLAYHT_USER_ID', ''),\n    api_key=os.environ.get('PLAYHT_API_KEY', ''),\n)\noptions = TTSOptions(\n    voice='s3://voice-cloning-zero-shot/xxxxx',\n    format=Format.FORMAT_MP3,\n    sample_rate=24000,\n)\nwith client.tts(text=\"Hello, world!\", options=options) as audio_stream:\n    with open('output.mp3', 'wb') as f:\n        for chunk in audio_stream:\n            f.write(chunk)","lang":"python","description":"Initialize a client, create TTS options, and stream audio to a file."},"warnings":[{"fix":"Set the environment variables or pass them explicitly.","message":"The API key and user ID must be provided via environment variables PLAYHT_API_KEY and PLAYHT_USER_ID, or passed directly. The library does not read .env files automatically.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Use the full S3 URI from the PlayHT dashboard.","message":"The 'voice' parameter in TTSOptions accepts a URI string. The old pattern of using a voice name directly is no longer supported.","severity":"deprecated","affected_versions":">=0.1.12"},{"fix":"Use the context manager or explicitly iterate.","message":"The client.tts() returns a generator. You must iterate over it to actually process the audio. Calling it without consuming the generator may lead to silent failures.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Implement custom retry logic or re-create the client periodically.","message":"WebSocket connections may drop if the token expires. There is no built-in reconnection logic.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Stick with synchronous Client for production.","message":"The 'async' variant (AsyncClient) is not yet stable and may have breaking changes.","severity":"deprecated","affected_versions":">=0.1.10"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Set PLAYHT_USER_ID and PLAYHT_API_KEY environment variables, or pass them to Client().","cause":"Missing or invalid API key or user ID.","error":"pyht.exceptions.NotAuthenticatedError: Authentication failed"},{"fix":"Run 'pip install pyht' in the correct virtual environment.","cause":"The library is not installed or the wrong Python environment is used.","error":"ModuleNotFoundError: No module named 'pyht'"},{"fix":"Upgrade to the latest version: pip install --upgrade pyht","cause":"Older version of pyht that used a different import path.","error":"AttributeError: module 'pyht' has no attribute 'Client'"},{"fix":"Call client.tts(text=..., options=options) not client.tts(text=..., options=options()).","cause":"Using TTSOptions() incorrectly, e.g., calling it instead of passing options to client.tts().","error":"TypeError: 'TTSOptions' object is not callable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}