Skip to main content

A Python package for text-to-speech conversion using DeepAI API.

Project description

Speech Synthesis with DeepAI API

This Python script uses the DeepAI API to convert text to speech and play the resulting audio. It allows you to choose from various voices provided by DeepAI.

Prerequisites

Before running the script, ensure you have the following installed:

  • Python 3.11.4
  • playsound library
  • requests library

You can install the required libraries using pip:

pip install playsound requests

Usage

Function

The script defines a single function:

def speak(text: str, model: str="aura-luna-en", filename :str="data.mp3"):
    url = "https://api.deepai.org/speech_response"

    payload = {
        "model": model,
        "text": text
    }
    response = requests.post(url, json=payload)
    if response.status_code != 200: return f"Error: {response.status_code} - {response.text}"
    else:
        with open(filename, 'wb') as f:
            f.write(response.content)
        playsound.playsound(filename)
        os.remove(filename)

Parameters

  • text (str): The text you want to convert to speech.
  • model (str, optional): The voice model to use. Defaults to "aura-luna-en".
  • filename (str, optional): The name of the temporary file to save the audio. Defaults to "data.mp3".

Voice Models

You can choose from the following voice models:

  • "aura-asteria-en": Sophia (Female US English)
  • "aura-luna-en": Emily (Female US English)
  • "aura-stella-en": Rachel (Female US English)
  • "aura-athena-en": Eliza (Female UK English)
  • "aura-hera-en": Pam (Female US English)
  • "aura-orion-en": Kevin (Male US English)
  • "aura-arcas-en": Jeff (Male US English)
  • "aura-perseus-en": Alex (Male US English)
  • "aura-angus-en": Rory (Male Irish English)
  • "aura-orpheus-en": John (Male US English)
  • "aura-helios-en": Pete (Male UK English)
  • "aura-zeus-en": James (Male US English)

Example

Here's an example of how to use the speak function:

speak("Hello, this is a test message.", model="aura-luna-en")

This will convert the text "Hello, this is a test message." to speech using the "aura-luna-en" (Emily, Female US English) voice model and play the resulting audio.

Notes

  • Ensure you have an active internet connection as the script makes a request to the DeepAI API.
  • Make sure to handle API keys securely if required by the DeepAI API for authentication.
  • The temporary audio file is deleted after playing to keep your directory clean.

Troubleshooting

  • If you encounter an error, check the status code and response text returned by the API for more details.
  • Ensure the playsound and requests libraries are properly installed.

Created by NetHyTech (Anubhav Chaturvedi)

"Author of [NetHyTech_DeepTTS] is Anubhav Chaturvedi" "Youtube : https://youtube.com//@nethytech "

License

This script is provided as-is without any warranty. Use at your own risk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

NetHyTech-DeepTTS-0.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

NetHyTech_DeepTTS-0.1-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page