Transcribe Local File
π Upload a Local File for Transcription
Use this API to upload and transcribe a local audio or file. Start by obtaining an upload_url
to securely upload your file and a public_url
to initiate transcription. The transcription initiation will return an order_id
for retrieving results.
β οΈ Note: Ensure the file path is correct and supported.
π Request Parameters
- file_name (string): The name of your file to be uploaded using the
upload_url
.
π Transcription Parameters
- url (string): The
public_url
obtained after uploading, used to initiate transcription. - language (string): Language code in ISO format, e.g.,
en-US
. - service (string): Type of transcription service:
Standard
Subtitle
- folder_id (string, optional): ID of the folder for storage. Default is "Recent Files".
- triggering_word (string, optional): A specific word to trigger a new line break in the transcription.
import json
import requests
# Step 1: Obtain the Upload URL
url = "https://api.tor.app/developer/transcription/local_file/get_upload_url"
# Replace with your actual API key
api_key = "your_api_key"
# Set up the headers, including the API key
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
"Accept": "application/json",
}
# Request body with the file name
body = json.dumps({"file_name": "your_file_name"})
# Request to get the upload URL
response = requests.post(url, headers=headers, data=body)
if response.status_code == 200:
response_json = response.json()
upload_url = response_json["upload_url"]
public_url = response_json[
"public_url"
] # URL to pass in initiate transcription step
print("Upload URL obtained:", upload_url)
print("Public URL obtained:", public_url)
else:
print("Failed to get upload URL:", response.status_code, response.text)
exit()
# Step 2: Upload the Local File
file_path = "path/to/your/file.mp3" # Replace with your actual file path
with open(file_path, "rb") as file_data:
upload_response = requests.put(upload_url, data=file_data)
if upload_response.status_code == 200:
print("File uploaded successfully")
else:
print("File upload failed:", upload_response.status_code, upload_response.text)
exit()
# Step 3: Initiate Transcription for the Uploaded File
initiate_url = (
"https://api.tor.app/developer/transcription/local_file/initiate_transcription"
)
# Configure transcription parameters
config = json.dumps(
{
"url": public_url, # Passing public_url to initiate transcription
"language": "en-US",
"service": "Standard",
# "folder_id": "your_folder_id", # Optional folder_id
# "triggering_word": "example", # Optional triggering_word
}
)
# Send request to initiate transcription
transcription_response = requests.post(initiate_url, headers=headers, data=config)
if transcription_response.status_code == 202:
transcription_json = transcription_response.json()
print(transcription_json["message"])
print("Order ID:", transcription_json["order_id"])
else:
print(
"Failed to initiate transcription:",
transcription_response.status_code,
transcription_response.text,
)
const axios = require('axios');
const fs = require('fs');
// Step 1: Obtain the Upload URL
const url = "https://api.tor.app/developer/transcription/local_file/get_upload_url";
const apiKey = "your_api_key"; // Replace with your actual API key
// Set up headers
const headers = {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`,
"Accept": "application/json"
};
// Request body with the file name
const body = JSON.stringify({ file_name: "your_file_name" });
(async () => {
try {
// Step 1: Get the upload URL
const response = await axios.post(url, body, { headers });
if (response.status === 200) {
const { upload_url, public_url } = response.data;
console.log("Upload URL obtained:", upload_url);
console.log("Public URL obtained:", public_url);
// Step 2: Upload the Local File
const filePath = "path/to/your/file.mp3";
const fileData = fs.createReadStream(filePath);
const uploadResponse = await axios.put(upload_url, fileData);
if (uploadResponse.status === 200) {
console.log("File uploaded successfully");
// Step 3: Initiate Transcription for the Uploaded File
const initiateUrl = "https://api.tor.app/developer/transcription/local_file/initiate_transcription";
const config = JSON.stringify({
url: public_url,
language: "en-US",
service: "Standard",
});
const transcriptionResponse = await axios.post(initiateUrl, config, { headers });
if (transcriptionResponse.status === 202) {
console.log(transcriptionResponse.data.message);
console.log("Order ID:", transcriptionResponse.data.order_id);
} else {
console.error("Failed to initiate transcription:", transcriptionResponse.status, transcriptionResponse.data);
}
} else {
console.error("File upload failed:", uploadResponse.status, uploadResponse.data);
}
} else {
console.error("Failed to get upload URL:", response.status, response.data);
}
} catch (error) {
console.error("Error:", error.response ? error.response.data : error.message);
}
})();
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.*;
public class TranscribeFile {
private static final String API_KEY = "your_api_key"; // Replace with your actual API key
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient();
// Step 1: Obtain the Upload URL
String url = "https://api.tor.app/developer/transcription/local_file/get_upload_url";
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, "{\"file_name\": \"your_file_name\"}");
Request request = new Request.Builder()
.url(url)
.post(body)
.addHeader("Authorization", "Bearer " + API_KEY)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
String responseData = response.body().string();
JSONObject json = new JSONObject(responseData);
String uploadUrl = json.getString("upload_url");
String publicUrl = json.getString("public_url");
System.out.println("Upload URL obtained: " + uploadUrl);
System.out.println("Public URL obtained: " + publicUrl);
// Step 2: Upload the Local File
File file = new File("path/to/your/file.mp3");
RequestBody fileBody = RequestBody.create(MediaType.parse("audio/mpeg"), file);
Request uploadRequest = new Request.Builder().url(uploadUrl).put(fileBody).build();
Response uploadResponse = client.newCall(uploadRequest).execute();
if (uploadResponse.isSuccessful()) {
System.out.println("File uploaded successfully");
// Step 3: Initiate Transcription
String initiateUrl = "https://api.tor.app/developer/transcription/local_file/initiate_transcription";
String configJson = String.format("{\"url\": \"%s\", \"language\": \"en-US\", \"service\": \"Standard\"}", publicUrl);
RequestBody configBody = RequestBody.create(JSON, configJson);
Request transcriptionRequest = new Request.Builder()
.url(initiateUrl)
.post(configBody)
.addHeader("Authorization", "Bearer " + API_KEY)
.build();
Response transcriptionResponse = client.newCall(transcriptionRequest).execute();
if (transcriptionResponse.isSuccessful()) {
System.out.println("Transcription initiated successfully: " + transcriptionResponse.body().string());
} else {
System.out.println("Failed to initiate transcription: " + transcriptionResponse.code());
}
} else {
System.out.println("File upload failed: " + uploadResponse.code());
}
} else {
System.out.println("Failed to get upload URL: " + response.code());
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class TranscriptionExample
{
private const string apiKey = "your_api_key"; // Replace with your actual API key
public static async Task Main()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
// Step 1: Obtain the Upload URL
var url = "https://api.tor.app/developer/transcription/local_file/get_upload_url";
var body = new StringContent(JsonSerializer.Serialize(new { file_name = "your_file_name" }), Encoding.UTF8, "application/json");
var response = await client.PostAsync(url, body);
if (response.IsSuccessStatusCode)
{
var jsonResponse = await response.Content.ReadAsStringAsync();
var data = JsonDocument.Parse(jsonResponse);
var uploadUrl = data.RootElement.GetProperty("upload_url").GetString();
var publicUrl = data.RootElement.GetProperty("public_url").GetString();
Console.WriteLine($"Upload URL obtained: {uploadUrl}");
Console.WriteLine($"Public URL obtained: {publicUrl}");
// Step 2: Upload the Local File
var filePath = "path/to/your/file.mp3";
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var fileContent = new StreamContent(fileStream);
var uploadResponse = await client.PutAsync(uploadUrl, fileContent);
if (uploadResponse.IsSuccessStatusCode)
{
Console.WriteLine("File uploaded successfully");
// Step 3: Initiate Transcription
var initiateUrl = "https://api.tor.app/developer/transcription/local_file/initiate_transcription";
var config = new { url = publicUrl, language = "en-US", service = "Standard" };
var configContent = new StringContent(JsonSerializer.Serialize(config), Encoding.UTF8, "application/json");
var transcriptionResponse = await client.PostAsync(initiateUrl, configContent);
if (transcriptionResponse.IsSuccessStatusCode)
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
const apiKey = "your_api_key" // Replace with your actual API key
func main() {
// Step 1: Obtain the Upload URL
url := "https://api.tor.app/developer/transcription/local_file/get_upload_url"
headers := map[string]string{
"Content-Type": "application/json",
"Authorization": "Bearer " + apiKey,
"Accept": "application/json",
}
body := map[string]string{"file_name": "your_file_name"}
bodyBytes, _ := json.Marshal(body)
request, _ := http.NewRequest("POST", url, bytes.NewBuffer(bodyBytes))
for key, value := range headers {
request.Header.Set(key, value)
}
client := &http.Client{}
response, _ := client.Do(request)
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
var result map[string]interface{}
json.NewDecoder(response.Body).Decode(&result)
uploadUrl := result["upload_url"].(string)
publicUrl := result["public_url"].(string)
fmt.Println("Upload URL obtained:", uploadUrl)
fmt.Println("Public URL obtained:", publicUrl)
// Step 2: Upload the Local File
file, _ := os.Open("path/to/your/file.mp3")
defer file.Close()
uploadRequest, _ := http.NewRequest("PUT", uploadUrl, file)
uploadResponse, _ := client.Do(uploadRequest)
defer uploadResponse.Body.Close()
if uploadResponse.StatusCode == http.StatusOK {
fmt.Println("File uploaded successfully")
// Step 3: Initiate Transcription
initiateUrl := "https://api.tor.app/developer/transcription/local_file/initiate_transcription"
config := map[string]string{
"url": publicUrl,
"language": "en-US",
"service": "Standard",
}
configBytes, _ := json.Marshal(config)
transcriptionRequest, _ := http.NewRequest("POST", initiateUrl, bytes.NewBuffer(configBytes))
transcriptionRequest.Header.Set("Authorization", "Bearer "+apiKey)
transcriptionRequest.Header.Set("Content-Type", "application/json")
transcriptionResponse, _ := client.Do(transcriptionRequest)
defer transcriptionResponse.Body.Close()
if transcriptionResponse.StatusCode == http.StatusAccepted {
var transcriptionResult map[string]interface{}
json.NewDecoder(transcriptionResponse.Body).Decode(&transcriptionResult)
fmt.Println("Transcription initiated successfully:", transcriptionResult["message"])
} else {
fmt.Println("Failed to initiate transcription:", transcriptionResponse.StatusCode)
}
} else {
fmt.Println("File upload failed:", uploadResponse.StatusCode)
}
} else {
fmt.Println("Failed to get upload URL:", response.StatusCode)
}
}
require 'net/http'
require 'json'
require 'uri'
# Step 1: Obtain the Upload URL
url = URI("https://api.tor.app/developer/transcription/local_file/get_upload_url")
api_key = "your_api_key" # Replace with your actual API key
headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{api_key}",
"Accept" => "application/json"
}
body = { file_name: "your_file_name" }.to_json
response = Net::HTTP.post(url, body, headers)
if response.code.to_i == 200
response_data = JSON.parse(response.body)
upload_url = response_data["upload_url"]
public_url = response_data["public_url"]
puts "Upload URL obtained: #{upload_url}"
puts "Public URL obtained: #{public_url}"
# Step 2: Upload the Local File
file_path = "path/to/your/file.mp3"
file_data = File.open(file_path, "rb")
upload_response = Net::HTTP.put(URI(upload_url), file_data.read)
if upload_response.code.to_i == 200
puts "File uploaded successfully"
# Step 3: Initiate Transcription
initiate_url = URI("https://api.tor.app/developer/transcription/local_file/initiate_transcription")
config = { url: public_url, language: "en-US", service: "Standard" }.to_json
transcription_response = Net::HTTP.post(initiate_url, config, headers)
if transcription_response.code.to_i == 202
transcription_data = JSON.parse(transcription_response.body)
puts transcription_data["message"]
puts "Order ID: #{transcription_data['order_id']}"
else
puts "Failed to initiate transcription: #{transcription_response.code}"
end
else
puts "File upload failed: #{upload_response.code}"
end
else
puts "Failed to get upload URL: #{response.code}"
end
<?php
$apiKey = "your_api_key"; // Replace with your actual API key
// Step 1: Obtain the Upload URL
$url = "https://api.tor.app/developer/transcription/local_file/get_upload_url";
$headers = [
"Content-Type: application/json",
"Authorization: Bearer $apiKey",
"Accept: application/json"
];
$body = json_encode(["file_name" => "your_file_name"]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if (isset($responseData["upload_url"])) {
$uploadUrl = $responseData["upload_url"];
$publicUrl = $responseData["public_url"];
echo "Upload URL obtained: $uploadUrl\n";
echo "Public URL obtained: $publicUrl\n";
// Step 2: Upload the Local File
$filePath = "path/to/your/file.mp3";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uploadUrl);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, fopen($filePath, 'rb'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$uploadResponse = curl_exec($ch);
curl_close($ch);
if ($uploadResponse) {
echo "File uploaded successfully\n";
// Step 3: Initiate Transcription
$initiateUrl = "https://api.tor.app/developer/transcription/local_file/initiate_transcription";
$config = json_encode(["url" => $publicUrl, "language" => "en-US", "service" => "Standard"]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $initiateUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $config);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$transcriptionResponse = curl_exec($ch);
curl_close($ch);
$transcriptionData = json_decode($transcriptionResponse, true);
if (isset($transcriptionData["order_id"])) {
echo "Transcription initiated successfully: Order ID - " . $transcriptionData["order_id"] . "\n";
} else {
echo "Failed to initiate transcription\n";
}
} else {
echo "File upload failed\n";
}
} else {
echo "Failed to get upload URL\n";
}
?>
import okhttp3.*
import org.json.JSONObject
import java.io.File
fun main() {
val apiKey = "your_api_key" // Replace with your actual API key
val client = OkHttpClient()
// Step 1: Obtain the Upload URL
val url = "https://api.tor.app/developer/transcription/local_file/get_upload_url"
val body = RequestBody.create(MediaType.parse("application/json"), """{"file_name": "your_file_name"}""")
val request = Request.Builder()
.url(url)
.post(body)
.addHeader("Authorization", "Bearer $apiKey")
.build()
val response = client.newCall(request).execute()
if (response.isSuccessful) {
val responseData = JSONObject(response.body()!!.string())
val uploadUrl = responseData.getString("upload_url")
val publicUrl = responseData.getString("public_url")
println("Upload URL obtained: $uploadUrl")
println("Public URL obtained: $publicUrl")
// Step 2: Upload the Local File
val file = File("path/to/your/file.mp3")
val fileBody = RequestBody.create(MediaType.parse("audio/mpeg"), file)
val uploadRequest = Request.Builder().url(uploadUrl).put(fileBody).build()
val uploadResponse = client.newCall(uploadRequest).execute()
if (uploadResponse.isSuccessful) {
println("File uploaded successfully")
// Step 3: Initiate Transcription
val initiateUrl = "https://api.tor.app/developer/transcription/local_file/initiate_transcription"
val configBody = RequestBody.create(
MediaType.parse("application/json"),
"""{"url": "$publicUrl", "language": "en-US", "service": "Standard"}"""
)
val transcriptionRequest = Request.Builder()
.url(initiateUrl)
.post(configBody)
.addHeader("Authorization", "Bearer $apiKey")
.build()
val transcriptionResponse = client.newCall(transcriptionRequest).execute()
if (transcriptionResponse.isSuccessful) {
println("Transcription initiated successfully: ${transcriptionResponse.body()!!.string()}")
} else {
println("Failed to initiate transcription: ${transcriptionResponse.code()}")
}
} else {
println("File upload failed: ${uploadResponse.code()}")
}
} else {
println("Failed to get upload URL: ${response.code()}")
}
}
import Foundation
let apiKey = "your_api_key" // Replace with your actual API key
let url = URL(string: "https://api.tor.app/developer/transcription/local_file/get_upload_url")!
// Step 1: Obtain the Upload URL
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try! JSONEncoder().encode(["file_name": "your_file_name"])
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data, let response = response as? HTTPURLResponse, response.statusCode == 200 {
let json = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
let uploadUrl = json["upload_url"] as! String
let publicUrl = json["public_url"] as! String
print("Upload URL obtained: \(uploadUrl)")
print("Public URL obtained: \(publicUrl)")
// Step 2: Upload the Local File
var uploadRequest = URLRequest(url: URL(string: uploadUrl)!)
uploadRequest.httpMethod = "PUT"
let fileData = try! Data(contentsOf: URL(fileURLWithPath: "path/to/your/file.mp3"))
uploadRequest.httpBody = fileData
let uploadTask = URLSession.shared.dataTask(with: uploadRequest) { uploadData, uploadResponse, uploadError in
if let uploadResponse = uploadResponse as? HTTPURLResponse, uploadResponse.statusCode == 200 {
print("File uploaded successfully")
// Step 3: Initiate Transcription
var initiateRequest = URLRequest(url: URL(string: "https://api.tor.app/developer/transcription/local_file/initiate_transcription")!)
initiateRequest.httpMethod = "POST"
initiateRequest.addValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
initiateRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
initiateRequest.httpBody = try! JSONEncoder().encode(["url": publicUrl, "language": "en-US", "service": "Standard"])
let transcriptionTask = URLSession.shared.dataTask(with: initiateRequest) { transcriptionData, transcriptionResponse, transcriptionError in
if let transcriptionResponse = transcriptionResponse as? HTTPURLResponse, transcriptionResponse.statusCode == 202 {
let transcriptionJson = try! JSONSerialization.jsonObject(with: transcriptionData!, options: []) as! [String: Any]
print("Transcription initiated successfully: \(transcriptionJson["message"] ?? "")")
print("Order ID: \(transcriptionJson["order_id"] ?? "")")
} else {
print("Failed to initiate transcription")
}
}
transcriptionTask.resume()
} else {
print("File upload failed")
}
}
uploadTask.resume()
} else {
print("Failed to get upload URL")
}
}
task.resume()
import 'dart:convert';
import 'dart:io';
void main() async {
final apiKey = 'your_api_key'; // Replace with your actual API key
final url = Uri.parse('https://api.tor.app/developer/transcription/local_file/get_upload_url');
// Step 1: Obtain the Upload URL
final request = await HttpClient().postUrl(url);
request.headers
..set('Content-Type', 'application/json')
..set('Authorization', 'Bearer $apiKey');
request.add(utf8.encode(jsonEncode({'file_name': 'your_file_name'})));
final response = await request.close();
if (response.statusCode == 200) {
final jsonResponse = await response.transform(utf8.decoder).join();
final data = jsonDecode(jsonResponse);
final uploadUrl = data['upload_url'];
final publicUrl = data['public_url'];
print('Upload URL obtained: $uploadUrl');
print('Public URL obtained: $publicUrl');
// Step 2: Upload the Local File
final uploadRequest = await HttpClient().putUrl(Uri.parse(uploadUrl));
final file = File('path/to/your/file.mp3');
uploadRequest.add(await file.readAsBytes());
final uploadResponse = await uploadRequest.close();
if (uploadResponse.statusCode == 200) {
print('File uploaded successfully');
// Step 3: Initiate Transcription
final transcriptionRequest = await HttpClient().postUrl(Uri.parse('https://api.tor.app/developer/transcription/local_file/initiate_transcription'));
transcriptionRequest.headers.set('Authorization', 'Bearer $apiKey');
transcriptionRequest.add(utf8.encode(jsonEncode({
'url': publicUrl,
'language': 'en-US',
'service': 'Standard',
})));
final transcriptionResponse = await transcriptionRequest.close();
if (transcriptionResponse.statusCode == 202) {
final transcriptionJson = await transcriptionResponse.transform(utf8.decoder).join();
print('Transcription initiated successfully: $transcriptionJson');
} else {
print('Failed to initiate transcription');
}
} else {
print('File upload failed');
}
} else {
print('Failed to get upload URL');
}
}
π Introducing Trigger Word for Transcription Line Breaks
Enhance your transcription experience with our latest feature - Trigger Word for Line Breaks! Now, you can specify a word that, when encountered during the transcription process, will automatically insert a new line in the transcript. This feature is perfect for creating clear and organized transcripts, especially for dialogue-heavy content such as interviews, meetings, and podcasts. Simply provide your desired trigger word in config parameters, and our advanced transcription service will take care of the rest, ensuring that your transcripts are easy to read and navigate.
config = json.dumps(
{
"url": public_url, # Passing public_url to initiate transcription
"language": "en-US",
"service": "Standard",
# "folder_id": "your_folder_id",
"triggering_word": "example",
}
)
Updated 10 days ago