Getting Started

The Deeptune Python library provides convenient access to the Deeptune API from Python.

Installation

1pip install deeptune

Usage

Instantiate and use the client with the following:

1from deeptune.client import Deeptune
2from deeptune.utils import play
3
4client = Deeptune(
5 api_key="YOUR_API_KEY",
6)
7
8audio = client.text_to_speech.generate(
9 text="Wow, Deeptune's text to speech API is amazing!",
10 voice="d770a0d0-d7b0-4e52-962f-1a41d252a5f6",
11)
12play(audio)

Cloning Voices

There are two different ways you can manage voices with the Deeptune API.

  1. Use Deeptune’s inbuilt voices to upload and manage voices.
  2. Manage voices yourself (eg in your own DB) and clone with generate_from_prompt.

Saving the output

Saving manually

The generate and generate_from_prompt endpoints return an iterator of bytes. Make sure to get all of the bytes before writing as demonstrated below.

1audio = client.text_to_speech.generate(
2 text="Wow, Deeptune's text to speech API is amazing!",
3 voice="d770a0d0-d7b0-4e52-962f-1a41d252a5f6",
4)
5audio_bytes = b"".join(audio)
6
7# Now, you can save however you'd like
8with open("output.mp3", "wb") as audio_file:
9 audio_file.write(audio_bytes)

Using built in utils

The also has inbuilt play, save, and stream utility methods. Under the hood, these methods use ffmpeg and mpv to play audio streams.

1from deeptune.utils import play, save, stream
2
3# plays audio using ffmpeg
4play(audio)
5# streams audio using mpv
6stream(audio)
7# saves audio to file
8save(audio, "my-file.mp3")

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API.

1from deeptune.client import Deeptune
2from deeptune.utils import play
3
4client = AsyncDeeptune(
5 api_key="YOUR_API_KEY",
6)
7audio = await client.text_to_speech.generate_from_prompt(
8 text="string",
9 voice="string",
10)
11play(audio)