Instant Voice Clone (Python SDK)

View as Markdown

Create an instant voice clone by uploading a short audio sample (5-15 seconds) via the Python SDK.

You can access the source code for the Python SDK on our GitHub repository.

Prefer plain HTTP? The Instant Voice Clone (REST API) page covers the same operation without the SDK.

Requirements

Before you begin, ensure you have the following:

  • Python (3.9 or higher) installed on your machine.
  • An API key from the Smallest AI platform.

Setup

Install our SDK

$pip install smallestai

Set your API key as an environment variable.

$export SMALLEST_API_KEY=YOUR_API_KEY

Add your Voice

The Smallest AI SDK allows you to clone your voice by uploading an audio file. This feature is available both synchronously and asynchronously, making it flexible for different use cases. Below are examples of how to use this functionality.

Synchronously

python
1from smallestai import SmallestAI
2
3def main():
4 client = SmallestAI() # reads SMALLEST_API_KEY from the environment
5 with open("my_voice.wav", "rb") as f:
6 res = client.waves.create_voice_clone(
7 display_name="My Voice",
8 file=("my_voice.wav", f, "audio/wav"),
9 )
10 print(res)
11
12if __name__ == "__main__":
13 main()

Asynchronously

python
1import asyncio
2from smallestai import AsyncSmallestAI
3
4async def main():
5 client = AsyncSmallestAI() # reads SMALLEST_API_KEY from the environment
6 with open("my_voice.wav", "rb") as f:
7 res = await client.waves.create_voice_clone(
8 display_name="My Voice",
9 file=("my_voice.wav", f, "audio/wav"),
10 )
11 print(res)
12
13if __name__ == "__main__":
14 asyncio.run(main())

Parameters

  • api_key: Your API key. Set the SMALLEST_API_KEY environment variable, or pass it explicitly with SmallestAI(api_key="YOUR_API_KEY").
  • display_name: Name of the voice to be created.
  • file: The audio file to clone from, opened in binary mode.
  • Optional: description, accent, tags, language, and model.
  • Pass the file as a (filename, file_object, content_type) tuple so the upload carries the right file type.

These parameters are part of the create_voice_clone function. They can be set when calling the function as shown above.

Get All Cloned Voices

Once you have cloned your voices, you can retrieve a list of all cloned voices associated with your account using the following code:

python
1from smallestai import SmallestAI
2
3client = SmallestAI() # reads SMALLEST_API_KEY from the environment
4print(f"Available Voices: {client.waves.list_voice_clones()}")

If you have any questions or run into any issues, our community is here to help!