Python
from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
res = client.v1.ai_voice_cloner.create(
assets={"audio_file_path": "api-assets/id/1234.mp3"},
style={
"language": "spanish",
"prompt": "Hello, this is my cloned voice.",
"speed": 1.15,
},
name="My Voice Cloner audio",
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["MAGIC_HOUR_API_KEY"] });
const res = await client.v1.aiVoiceCloner.generate(
{
assets: { audioFilePath: "/path/to/audio.mp3" },
name: "Voice Cloner audio",
style: { prompt: "Hello, this is my cloned voice." },
},
{
waitForCompletion: true,
downloadOutputs: true,
downloadDirectory: ".",
},
);package main
import (
os "os"
sdk "github.com/magichourhq/magic-hour-go/client"
nullable "github.com/magichourhq/magic-hour-go/nullable"
ai_voice_cloner "github.com/magichourhq/magic-hour-go/resources/v1/ai_voice_cloner"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("MAGIC_HOUR_API_KEY")),
)
res, err := client.V1.AiVoiceCloner.Create(ai_voice_cloner.CreateRequest{
Assets: types.V1AiVoiceClonerCreateBodyAssets{
AudioFilePath: "api-assets/id/1234.mp3",
},
Name: nullable.NewValue("My Voice Cloner audio"),
Style: types.V1AiVoiceClonerCreateBodyStyle{
Language: nullable.NewValue(types.V1AiVoiceClonerCreateBodyStyleLanguageEnumSpanish),
Prompt: "Hello, this is my cloned voice.",
Speed: nullable.NewValue(1.15),
},
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("MAGIC_HOUR_API_KEY").unwrap());
let res = client
.v1()
.ai_voice_cloner()
.create(magic_hour::resources::v1::ai_voice_cloner::CreateRequest {
assets: magic_hour::models::V1AiVoiceClonerCreateBodyAssets {
audio_file_path: "api-assets/id/1234.mp3".to_string(),
},
name: Some("My Voice Cloner audio".to_string()),
style: magic_hour::models::V1AiVoiceClonerCreateBodyStyle {
language: Some(
magic_hour::models::V1AiVoiceClonerCreateBodyStyleLanguageEnum::Spanish,
),
prompt: "Hello, this is my cloned voice.".to_string(),
speed: Some(1.15),
},
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/ai-voice-cloner \
--header 'accept: application/json' \
--header "authorization: Bearer $MAGIC_HOUR_API_KEY" \
--header 'content-type: application/json' \
--data '
{
"name": "My Voice Cloner audio",
"assets": {
"audio_file_path": "api-assets/id/1234.mp3"
},
"style": {
"language": "spanish",
"speed": 1.15,
"prompt": "Hello, this is my cloned voice."
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/ai-voice-cloner",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'My Voice Cloner audio',
'assets' => [
'audio_file_path' => 'api-assets/id/1234.mp3'
],
'style' => [
'language' => 'spanish',
'speed' => 1.15,
'prompt' => 'Hello, this is my cloned voice.'
]
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authorization: Bearer <token>",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.magichour.ai/v1/ai-voice-cloner")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Voice Cloner audio\",\"assets\":{\"audio_file_path\":\"api-assets/id/1234.mp3\"},\"style\":{\"language\":\"spanish\",\"speed\":1.15,\"prompt\":\"Hello, this is my cloned voice.\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/ai-voice-cloner")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"assets\": {\n \"audio_file_path\": \"api-assets/id/1234.mp3\"\n },\n \"style\": {\n \"prompt\": \"Hello, this is my cloned voice.\",\n \"language\": \"spanish\",\n \"speed\": 1.15\n },\n \"name\": \"My Voice Cloner audio\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 1
}{
"code": "invalid_request",
"message": "<string>"
}{
"code": "unauthorized",
"message": "<string>"
}{
"code": "insufficient_credits",
"message": "<string>"
}{
"code": "not_found",
"message": "<string>"
}{
"code": "unprocessable_entity",
"message": "<string>"
}{
"code": "internal_server_error",
"message": "<string>"
}Audio Projects
AI Voice Cloner
Clone a voice from an audio sample and generate speech.
- Each character costs 0.1 credits.
- The cost is rounded up to the nearest whole number
POST
/
v1
/
ai-voice-cloner
Python
from magic_hour import Client
from os import getenv
client = Client(token=getenv("MAGIC_HOUR_API_KEY"))
res = client.v1.ai_voice_cloner.create(
assets={"audio_file_path": "api-assets/id/1234.mp3"},
style={
"language": "spanish",
"prompt": "Hello, this is my cloned voice.",
"speed": 1.15,
},
name="My Voice Cloner audio",
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["MAGIC_HOUR_API_KEY"] });
const res = await client.v1.aiVoiceCloner.generate(
{
assets: { audioFilePath: "/path/to/audio.mp3" },
name: "Voice Cloner audio",
style: { prompt: "Hello, this is my cloned voice." },
},
{
waitForCompletion: true,
downloadOutputs: true,
downloadDirectory: ".",
},
);package main
import (
os "os"
sdk "github.com/magichourhq/magic-hour-go/client"
nullable "github.com/magichourhq/magic-hour-go/nullable"
ai_voice_cloner "github.com/magichourhq/magic-hour-go/resources/v1/ai_voice_cloner"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("MAGIC_HOUR_API_KEY")),
)
res, err := client.V1.AiVoiceCloner.Create(ai_voice_cloner.CreateRequest{
Assets: types.V1AiVoiceClonerCreateBodyAssets{
AudioFilePath: "api-assets/id/1234.mp3",
},
Name: nullable.NewValue("My Voice Cloner audio"),
Style: types.V1AiVoiceClonerCreateBodyStyle{
Language: nullable.NewValue(types.V1AiVoiceClonerCreateBodyStyleLanguageEnumSpanish),
Prompt: "Hello, this is my cloned voice.",
Speed: nullable.NewValue(1.15),
},
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("MAGIC_HOUR_API_KEY").unwrap());
let res = client
.v1()
.ai_voice_cloner()
.create(magic_hour::resources::v1::ai_voice_cloner::CreateRequest {
assets: magic_hour::models::V1AiVoiceClonerCreateBodyAssets {
audio_file_path: "api-assets/id/1234.mp3".to_string(),
},
name: Some("My Voice Cloner audio".to_string()),
style: magic_hour::models::V1AiVoiceClonerCreateBodyStyle {
language: Some(
magic_hour::models::V1AiVoiceClonerCreateBodyStyleLanguageEnum::Spanish,
),
prompt: "Hello, this is my cloned voice.".to_string(),
speed: Some(1.15),
},
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/ai-voice-cloner \
--header 'accept: application/json' \
--header "authorization: Bearer $MAGIC_HOUR_API_KEY" \
--header 'content-type: application/json' \
--data '
{
"name": "My Voice Cloner audio",
"assets": {
"audio_file_path": "api-assets/id/1234.mp3"
},
"style": {
"language": "spanish",
"speed": 1.15,
"prompt": "Hello, this is my cloned voice."
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/ai-voice-cloner",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'My Voice Cloner audio',
'assets' => [
'audio_file_path' => 'api-assets/id/1234.mp3'
],
'style' => [
'language' => 'spanish',
'speed' => 1.15,
'prompt' => 'Hello, this is my cloned voice.'
]
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"authorization: Bearer <token>",
"content-type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}HttpResponse<String> response = Unirest.post("https://api.magichour.ai/v1/ai-voice-cloner")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Voice Cloner audio\",\"assets\":{\"audio_file_path\":\"api-assets/id/1234.mp3\"},\"style\":{\"language\":\"spanish\",\"speed\":1.15,\"prompt\":\"Hello, this is my cloned voice.\"}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/ai-voice-cloner")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"assets\": {\n \"audio_file_path\": \"api-assets/id/1234.mp3\"\n },\n \"style\": {\n \"prompt\": \"Hello, this is my cloned voice.\",\n \"language\": \"spanish\",\n \"speed\": 1.15\n },\n \"name\": \"My Voice Cloner audio\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 1
}{
"code": "invalid_request",
"message": "<string>"
}{
"code": "unauthorized",
"message": "<string>"
}{
"code": "insufficient_credits",
"message": "<string>"
}{
"code": "not_found",
"message": "<string>"
}{
"code": "unprocessable_entity",
"message": "<string>"
}{
"code": "internal_server_error",
"message": "<string>"
}Authorizations
Bearer authentication header of the form Bearer <api_key>, where <api_key> is your API key. To get your API key, go to Developer Hub and click "Create new API Key".
Body
application/json
Body
Response
Success
Success
Unique ID of the audio. Use it with the Get audio Project API to fetch status and downloads.
Example:
"cuid-example"
Was this page helpful?