Skip to content

Repository files navigation

playht

This is a non-official python library based on the PlayHT's API docs available here.

NOTE Cielo24 has no affiliation with PlayHT. This repo is periodically updated as a kindness to others who have shown interest in it. Therefore, this exists to provide an easy way to access and contribute with the project, nothing more.


The PlayHT's API API allows developers to Realtime Text to Speech streaming Stream audio bytes from text, Convert long form Text to Speech Generate audio from text, and Voice Cloning Instant Cloning.

This Python package is automatically generated by the Swagger Codegen project:

  • API version: 1.0.0
  • Package version: 1.0.0
  • Build package: io.swagger.codegen.v3.generators.python.PythonClientCodegen

Requirements.

Python 2.7 and 3.4+

Installation & Usage

pip install

If the python package is hosted on Github, you can install directly from Github

pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git)

Then import the package:

importplayht

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

importplayht

Getting Started

Please follow the installation procedure and then run the following:

from __future__ importprint_functionimporttimeimportplayhtfromplayht.restimportApiExceptionfrompprintimportpprint# Configure API key authorization: ApiKeyAuthconfiguration=playht.Configuration()
configuration.api_key['AUTHORIZATION'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['AUTHORIZATION'] = 'Bearer'# Configure API key authorization: UserAuthconfiguration=playht.Configuration()
configuration.api_key['X-USER-ID'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['X-USER-ID'] = 'Bearer'# create an instance of the API classapi_instance=playht.DefaultApi(playht.ApiClient(configuration))
try:
# Obtains a list of all cloned voices created by the user.api_response=api_instance.cloned_voices()
pprint(api_response)
exceptApiExceptionase:
print("Exception when calling DefaultApi->cloned_voices: %s\n"%e)
# Configure API key authorization: ApiKeyAuthconfiguration=playht.Configuration()
configuration.api_key['AUTHORIZATION'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['AUTHORIZATION'] = 'Bearer'# Configure API key authorization: UserAuthconfiguration=playht.Configuration()
configuration.api_key['X-USER-ID'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['X-USER-ID'] = 'Bearer'# create an instance of the API classapi_instance=playht.DefaultApi(playht.ApiClient(configuration))
body=playht.SSMLConversionPayload() # SSMLConversionPayload | (optional)try:
# Convert SSML to Speech. It can generate text for Standard & Premium (S&P) voices. The identifiers for these voices look like 'en-US-JennyNeural'. If you are using PlayHT voices (their identifiers look like 'larry' or a URL).api_response=api_instance.convert_ssml_to_speech(body=body)
pprint(api_response)
exceptApiExceptionase:
print("Exception when calling DefaultApi->convert_ssml_to_speech: %s\n"%e)
# Configure API key authorization: ApiKeyAuthconfiguration=playht.Configuration()
configuration.api_key['AUTHORIZATION'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['AUTHORIZATION'] = 'Bearer'# Configure API key authorization: UserAuthconfiguration=playht.Configuration()
configuration.api_key['X-USER-ID'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['X-USER-ID'] = 'Bearer'# create an instance of the API classapi_instance=playht.DefaultApi(playht.ApiClient(configuration))
sample_file_url='sample_file_url_example'# str | The URL of the audio file selected as the source for the voice clone. The file should have a duration ranging from 2 seconds to 1 hour. It can be in any audio format, as long as it falls within the size range of 5kb to 50 MBvoice_name='voice_name_example'# str | The name for this new cloned voice.try:
# Create Instant Voice Clone (via file URL). Create an instant voice clone by providing an URL for a sample audio file.api_response=api_instance.create_instant_voice_clone_url(sample_file_url, voice_name)
pprint(api_response)
exceptApiExceptionase:
print("Exception when calling DefaultApi->create_instant_voice_clone_url: %s\n"%e)
# Configure API key authorization: ApiKeyAuthconfiguration=playht.Configuration()
configuration.api_key['AUTHORIZATION'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['AUTHORIZATION'] = 'Bearer'# Configure API key authorization: UserAuthconfiguration=playht.Configuration()
configuration.api_key['X-USER-ID'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['X-USER-ID'] = 'Bearer'# create an instance of the API classapi_instance=playht.DefaultApi(playht.ApiClient(configuration))
voice_id='voice_id_example'# str | The ID of the cloned voice to be deleted.try:
# Delete Cloned Voices. Deletes a cloned voice created by the user using the provided voice_id.api_instance.delete_cloned_voices(voice_id)
exceptApiExceptionase:
print("Exception when calling DefaultApi->delete_cloned_voices: %s\n"%e)
# Configure API key authorization: ApiKeyAuthconfiguration=playht.Configuration()
configuration.api_key['AUTHORIZATION'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['AUTHORIZATION'] = 'Bearer'# Configure API key authorization: UserAuthconfiguration=playht.Configuration()
configuration.api_key['X-USER-ID'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['X-USER-ID'] = 'Bearer'# create an instance of the API classapi_instance=playht.DefaultApi(playht.ApiClient(configuration))
transcription_id='transcription_id_example'# str | Transcription IDtry:
# Get conversion job status. Gets text-to-speech job status and generated audio file URL.api_response=api_instance.get_conversion_job_status(transcription_id)
pprint(api_response)
exceptApiExceptionase:
print("Exception when calling DefaultApi->get_conversion_job_status: %s\n"%e)
# Configure API key authorization: ApiKeyAuthconfiguration=playht.Configuration()
configuration.api_key['AUTHORIZATION'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['AUTHORIZATION'] = 'Bearer'# Configure API key authorization: UserAuthconfiguration=playht.Configuration()
configuration.api_key['X-USER-ID'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['X-USER-ID'] = 'Bearer'# create an instance of the API classapi_instance=playht.DefaultApi(playht.ApiClient(configuration))
try:
# Gets the full list of Standard & Premium (S&P) voices.api_response=api_instance.sp_voices()
pprint(api_response)
exceptApiExceptionase:
print("Exception when calling DefaultApi->sp_voices: %s\n"%e)
# Configure API key authorization: ApiKeyAuthconfiguration=playht.Configuration()
configuration.api_key['AUTHORIZATION'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['AUTHORIZATION'] = 'Bearer'# Configure API key authorization: UserAuthconfiguration=playht.Configuration()
configuration.api_key['X-USER-ID'] ='YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['X-USER-ID'] = 'Bearer'# create an instance of the API classapi_instance=playht.DefaultApi(playht.ApiClient(configuration))
try:
# Gets the full list of stock PlayHT Voices available for use with the API.api_response=api_instance.voices()
pprint(api_response)
exceptApiExceptionase:
print("Exception when calling DefaultApi->voices: %s\n"%e)

Documentation for API Endpoints

All URIs are relative to https://api.play.ht

ClassMethodHTTP requestDescription
DefaultApicloned_voicesGET /api/v2/cloned-voicesObtains a list of all cloned voices created by the user.
DefaultApiconvert_ssml_to_speechPOST /api/v1/convertConvert SSML to Speech. It can generate text for Standard & Premium (S&P) voices. The identifiers for these voices look like 'en-US-JennyNeural'. If you are using PlayHT voices (their identifiers look like 'larry' or a URL).
DefaultApicreate_instant_voice_clone_urlPOST /api/v2/cloned-voices/instant/Create Instant Voice Clone (via file URL). Create an instant voice clone by providing an URL for a sample audio file.
DefaultApidelete_cloned_voicesDELETE /api/v2/cloned-voicesDelete Cloned Voices. Deletes a cloned voice created by the user using the provided voice_id.
DefaultApiget_conversion_job_statusGET /api/v1/articleStatusGet conversion job status. Gets text-to-speech job status and generated audio file URL.
DefaultApisp_voicesGET /api/v1/getVoicesGets the full list of Standard & Premium (S&P) voices.
DefaultApivoicesGET /api/v2/voicesGets the full list of stock PlayHT Voices available for use with the API.

Documentation For Models

Documentation For Authorization

ApiKeyAuth

  • Type: API key
  • API key parameter name: AUTHORIZATION
  • Location: HTTP header

UserAuth

  • Type: API key
  • API key parameter name: X-USER-ID
  • Location: HTTP header

Author

devs@play.ht

About

PlayHT Python API Library

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages