from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.auto_subtitle_generator.generate(
assets={"video_file_path": "/path/to/1234.mp4"},
end_seconds=15.0,
start_seconds=0.0,
style={},
name="Auto Subtitle video",
wait_for_completion=True,
download_outputs=True,
download_directory="."
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.autoSubtitleGenerator.generate(
{
assets: { videoFilePath: "/path/to/1234.mp4" },
endSeconds: 15.0,
name: "Auto Subtitle video",
startSeconds: 0.0,
style: {},
},
{
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"
auto_subtitle_generator "github.com/magichourhq/magic-hour-go/resources/v1/auto_subtitle_generator"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.AutoSubtitleGenerator.Create(auto_subtitle_generator.CreateRequest{
Assets: types.V1AutoSubtitleGeneratorCreateBodyAssets{
VideoFilePath: "api-assets/id/1234.mp4",
},
EndSeconds: 15.0,
Name: nullable.NewValue("My Auto Subtitle video"),
StartSeconds: 0.0,
Style: types.V1AutoSubtitleGeneratorCreateBodyStyle{},
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.auto_subtitle_generator()
.create(magic_hour::resources::v1::auto_subtitle_generator::CreateRequest {
assets: magic_hour::models::V1AutoSubtitleGeneratorCreateBodyAssets {
video_file_path: "api-assets/id/1234.mp4".to_string(),
},
end_seconds: 15.0,
name: Some("My Auto Subtitle video".to_string()),
start_seconds: 0.0,
style: magic_hour::models::V1AutoSubtitleGeneratorCreateBodyStyle {
..Default::default()
},
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/auto-subtitle-generator \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Auto Subtitle video",
"start_seconds": 0,
"end_seconds": 15,
"assets": {
"video_file_path": "api-assets/id/1234.mp4"
},
"style": {
"template": "karaoke",
"custom_config": {
"font": "Noto Sans",
"font_size": 24,
"font_style": "normal",
"text_color": "#FFFFFF",
"highlighted_text_color": "#FFD700",
"stroke_color": "#000000",
"stroke_width": 1,
"vertical_position": "bottom",
"horizontal_position": "center"
}
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/auto-subtitle-generator",
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 Auto Subtitle video',
'start_seconds' => 0,
'end_seconds' => 15,
'assets' => [
'video_file_path' => 'api-assets/id/1234.mp4'
],
'style' => [
'template' => 'karaoke',
'custom_config' => [
'font' => 'Noto Sans',
'font_size' => 24,
'font_style' => 'normal',
'text_color' => '#FFFFFF',
'highlighted_text_color' => '#FFD700',
'stroke_color' => '#000000',
'stroke_width' => 1,
'vertical_position' => 'bottom',
'horizontal_position' => 'center'
]
]
]),
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/auto-subtitle-generator")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Auto Subtitle video\",\"start_seconds\":0,\"end_seconds\":15,\"assets\":{\"video_file_path\":\"api-assets/id/1234.mp4\"},\"style\":{\"template\":\"karaoke\",\"custom_config\":{\"font\":\"Noto Sans\",\"font_size\":24,\"font_style\":\"normal\",\"text_color\":\"#FFFFFF\",\"highlighted_text_color\":\"#FFD700\",\"stroke_color\":\"#000000\",\"stroke_width\":1,\"vertical_position\":\"bottom\",\"horizontal_position\":\"center\"}}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/auto-subtitle-generator")
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 \"start_seconds\": 0,\n \"end_seconds\": 15,\n \"assets\": {\n \"video_file_path\": \"api-assets/id/1234.mp4\"\n },\n \"style\": {\n \"custom_config\": {\n \"font\": \"Noto Sans\",\n \"font_size\": 24,\n \"font_style\": \"normal\",\n \"text_color\": \"#FFFFFF\",\n \"highlighted_text_color\": \"#FFD700\",\n \"stroke_color\": \"#000000\",\n \"stroke_width\": 1,\n \"vertical_position\": \"bottom\",\n \"horizontal_position\": \"center\"\n }\n },\n \"name\": \"My Auto Subtitle video\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 450
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to create video"
}Auto Subtitle Generator API Reference - Magic Hour Docs
Automatically generate subtitles for your video in multiple languages.
from magic_hour import Client
from os import getenv
client = Client(token=getenv("API_TOKEN"))
res = client.v1.auto_subtitle_generator.generate(
assets={"video_file_path": "/path/to/1234.mp4"},
end_seconds=15.0,
start_seconds=0.0,
style={},
name="Auto Subtitle video",
wait_for_completion=True,
download_outputs=True,
download_directory="."
)import { Client } from "magic-hour";
const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.autoSubtitleGenerator.generate(
{
assets: { videoFilePath: "/path/to/1234.mp4" },
endSeconds: 15.0,
name: "Auto Subtitle video",
startSeconds: 0.0,
style: {},
},
{
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"
auto_subtitle_generator "github.com/magichourhq/magic-hour-go/resources/v1/auto_subtitle_generator"
types "github.com/magichourhq/magic-hour-go/types"
)
func main() {
client := sdk.NewClient(
sdk.WithBearerAuth(os.Getenv("API_TOKEN")),
)
res, err := client.V1.AutoSubtitleGenerator.Create(auto_subtitle_generator.CreateRequest{
Assets: types.V1AutoSubtitleGeneratorCreateBodyAssets{
VideoFilePath: "api-assets/id/1234.mp4",
},
EndSeconds: 15.0,
Name: nullable.NewValue("My Auto Subtitle video"),
StartSeconds: 0.0,
Style: types.V1AutoSubtitleGeneratorCreateBodyStyle{},
})
}let client = magic_hour::Client::default()
.with_bearer_auth(&std::env::var("API_TOKEN").unwrap());
let res = client
.v1()
.auto_subtitle_generator()
.create(magic_hour::resources::v1::auto_subtitle_generator::CreateRequest {
assets: magic_hour::models::V1AutoSubtitleGeneratorCreateBodyAssets {
video_file_path: "api-assets/id/1234.mp4".to_string(),
},
end_seconds: 15.0,
name: Some("My Auto Subtitle video".to_string()),
start_seconds: 0.0,
style: magic_hour::models::V1AutoSubtitleGeneratorCreateBodyStyle {
..Default::default()
},
})
.await;curl --request POST \
--url https://api.magichour.ai/v1/auto-subtitle-generator \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"name": "My Auto Subtitle video",
"start_seconds": 0,
"end_seconds": 15,
"assets": {
"video_file_path": "api-assets/id/1234.mp4"
},
"style": {
"template": "karaoke",
"custom_config": {
"font": "Noto Sans",
"font_size": 24,
"font_style": "normal",
"text_color": "#FFFFFF",
"highlighted_text_color": "#FFD700",
"stroke_color": "#000000",
"stroke_width": 1,
"vertical_position": "bottom",
"horizontal_position": "center"
}
}
}
'<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magichour.ai/v1/auto-subtitle-generator",
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 Auto Subtitle video',
'start_seconds' => 0,
'end_seconds' => 15,
'assets' => [
'video_file_path' => 'api-assets/id/1234.mp4'
],
'style' => [
'template' => 'karaoke',
'custom_config' => [
'font' => 'Noto Sans',
'font_size' => 24,
'font_style' => 'normal',
'text_color' => '#FFFFFF',
'highlighted_text_color' => '#FFD700',
'stroke_color' => '#000000',
'stroke_width' => 1,
'vertical_position' => 'bottom',
'horizontal_position' => 'center'
]
]
]),
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/auto-subtitle-generator")
.header("accept", "application/json")
.header("content-type", "application/json")
.header("authorization", "Bearer <token>")
.body("{\"name\":\"My Auto Subtitle video\",\"start_seconds\":0,\"end_seconds\":15,\"assets\":{\"video_file_path\":\"api-assets/id/1234.mp4\"},\"style\":{\"template\":\"karaoke\",\"custom_config\":{\"font\":\"Noto Sans\",\"font_size\":24,\"font_style\":\"normal\",\"text_color\":\"#FFFFFF\",\"highlighted_text_color\":\"#FFD700\",\"stroke_color\":\"#000000\",\"stroke_width\":1,\"vertical_position\":\"bottom\",\"horizontal_position\":\"center\"}}}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magichour.ai/v1/auto-subtitle-generator")
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 \"start_seconds\": 0,\n \"end_seconds\": 15,\n \"assets\": {\n \"video_file_path\": \"api-assets/id/1234.mp4\"\n },\n \"style\": {\n \"custom_config\": {\n \"font\": \"Noto Sans\",\n \"font_size\": 24,\n \"font_style\": \"normal\",\n \"text_color\": \"#FFFFFF\",\n \"highlighted_text_color\": \"#FFD700\",\n \"stroke_color\": \"#000000\",\n \"stroke_width\": 1,\n \"vertical_position\": \"bottom\",\n \"horizontal_position\": \"center\"\n }\n },\n \"name\": \"My Auto Subtitle video\"\n}"
response = http.request(request)
puts response.read_body{
"id": "cuid-example",
"credits_charged": 450
}{
"message": "Missing request body"
}{
"message": "Unauthorized"
}{
"message": "Payment required"
}{
"message": "Not Found"
}{
"message": "Unable to create video"
}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
Body
Start time of your clip (seconds). Must be ≥ 0.
x >= 00
End time of your clip (seconds). Must be greater than start_seconds.
x >= 0.115
Provide the assets for auto subtitle generator
Show child attributes
Show child attributes
Style of the subtitle. At least one of .style.template or .style.custom_config must be provided.
- If only
.style.templateis provided, default values for the template will be used. - If both are provided, the fields in
.style.custom_configwill be used to overwrite the fields in.style.template. - If only
.style.custom_configis provided, then all fields in.style.custom_configwill be used.
To use custom config only, the following custom_config params are required:
.style.custom_config.font.style.custom_config.text_color.style.custom_config.vertical_position.style.custom_config.horizontal_position
Show child attributes
Show child attributes
Give your video a custom name for easy identification.
"My Auto Subtitle video"
Response
Success
Success
Unique ID of the video. Use it with the Get video Project API to fetch status and downloads.
"cuid-example"
The amount of credits deducted from your account to generate the video. If the status is not 'complete', this value is an estimate and may be adjusted upon completion based on the actual FPS of the output video.
If video generation fails, credits will be refunded, and this field will be updated to include the refund.
450
Was this page helpful?