Skip to content

cielo24/playht-python

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:

import playht

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:

import playht

Getting Started

Please follow the installation procedure and then run the following:

from __future__ import print_function
import time
import playht
from playht.rest import ApiException
from pprint import pprint

# Configure API key authorization: ApiKeyAuth
configuration = 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: UserAuth
configuration = 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 class
api_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)
except ApiException as e:
    print("Exception when calling DefaultApi->cloned_voices: %s\n" % e)

# Configure API key authorization: ApiKeyAuth
configuration = 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: UserAuth
configuration = 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 class
api_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)
except ApiException as e:
    print("Exception when calling DefaultApi->convert_ssml_to_speech: %s\n" % e)

# Configure API key authorization: ApiKeyAuth
configuration = 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: UserAuth
configuration = 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 class
api_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 MB
voice_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)
except ApiException as e:
    print("Exception when calling DefaultApi->create_instant_voice_clone_url: %s\n" % e)

# Configure API key authorization: ApiKeyAuth
configuration = 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: UserAuth
configuration = 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 class
api_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)
except ApiException as e:
    print("Exception when calling DefaultApi->delete_cloned_voices: %s\n" % e)

# Configure API key authorization: ApiKeyAuth
configuration = 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: UserAuth
configuration = 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 class
api_instance = playht.DefaultApi(playht.ApiClient(configuration))
transcription_id = 'transcription_id_example' # str | Transcription ID

try:
    # 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)
except ApiException as e:
    print("Exception when calling DefaultApi->get_conversion_job_status: %s\n" % e)

# Configure API key authorization: ApiKeyAuth
configuration = 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: UserAuth
configuration = 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 class
api_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)
except ApiException as e:
    print("Exception when calling DefaultApi->sp_voices: %s\n" % e)

# Configure API key authorization: ApiKeyAuth
configuration = 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: UserAuth
configuration = 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 class
api_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)
except ApiException as e:
    print("Exception when calling DefaultApi->voices: %s\n" % e)

Documentation for API Endpoints

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

Class Method HTTP request Description
DefaultApi cloned_voices GET /api/v2/cloned-voices Obtains a list of all cloned voices created by the user.
DefaultApi convert_ssml_to_speech POST /api/v1/convert 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).
DefaultApi create_instant_voice_clone_url POST /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.
DefaultApi delete_cloned_voices DELETE /api/v2/cloned-voices Delete Cloned Voices. Deletes a cloned voice created by the user using the provided voice_id.
DefaultApi get_conversion_job_status GET /api/v1/articleStatus Get conversion job status. Gets text-to-speech job status and generated audio file URL.
DefaultApi sp_voices GET /api/v1/getVoices Gets the full list of Standard & Premium (S&P) voices.
DefaultApi voices GET /api/v2/voices Gets 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

[email protected]

About

PlayHT Python API Library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published