Create Custom Vocabulary
π Create Your Own Custom Vocabulary
Improve transcription accuracy by creating a Custom Vocabulary. This feature is only enabled for English. By using this feature you can define some frequently used words/word groups in your transcriptions to increase transcription accuracy when those words are used.
import requests
import json
# URL of your Lambda function that generates the presigned URL
url = "https://api.tor.app/developer/custom_vocabulary"
api_key = "your_api_key" # Replace with your actual API key
# Prepare the parameters dictionary
body = {
"language": "en-US", # Only English is available for now.
}
# Set up the headers, including the API key
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}", # Use the variable here
"Accept": "application/json",
}
# Make the GET request to the API
response = requests.post(url, json=body, headers=headers)
# Check the response status code
if response.status_code == 200:
response_data = response.json()
print("Success:", response_data)
presigned_url = response_data["url"]
# List of words or phrases to be written to the file
words = [
"Transkriptor",
"Speech To Text",
"Chat With Your Transcription",
"Recognise Speakers",
]
# File path for the new file
file_path = "custom_words.txt"
# Write words to a .txt file
with open(file_path, "w") as file:
file.write(", ".join(words))
# Upload the file using the presigned URL
with open(file_path, "rb") as f:
upload_response = requests.put(presigned_url, data=f.read())
if upload_response.status_code == 200:
print("File uploaded successfully.")
else:
print("Failed to upload file:", upload_response.text)
else:
print("Failed with status code", response.status_code, response.text)
const axios = require('axios');
const fs = require('fs');
const apiKey = 'your_api_key'; // Replace with your actual API key
const url = "https://api.tor.app/developer/custom_vocabulary";
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
'Accept': 'application/json'
};
const body = {
language: "en-US"
};
axios.post(url, body, { headers })
.then(async (response) => {
console.log("Success:", response.data);
const presignedUrl = response.data.url;
const words = ["Transkriptor", "Speech To Text", "Chat With Your Transcription", "Recognise Speakers"];
const filePath = "custom_words.txt";
fs.writeFileSync(filePath, words.join(", "));
const fileData = fs.readFileSync(filePath);
const uploadResponse = await axios.put(presignedUrl, fileData, { headers: { 'Content-Type': 'text/plain' } });
if (uploadResponse.status === 200) {
console.log("File uploaded successfully.");
} else {
console.log("Failed to upload file:", uploadResponse.data);
}
})
.catch(error => {
console.error("Failed:", error.response ? error.response.data : error.message);
});
import okhttp3.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class CustomVocabulary {
private static final String API_KEY = "your_api_key";
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient();
String url = "https://api.tor.app/developer/custom_vocabulary";
String jsonBody = "{\"language\":\"en-US\"}";
RequestBody body = RequestBody.create(jsonBody, MediaType.parse("application/json"));
Request request = new Request.Builder()
.url(url)
.post(body)
.addHeader("Authorization", "Bearer " + API_KEY)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String presignedUrl = new JSONObject(response.body().string()).getString("url");
String[] words = {"Transkriptor", "Speech To Text", "Chat With Your Transcription", "Recognise Speakers"};
File file = new File("custom_words.txt");
try (FileWriter writer = new FileWriter(file)) {
writer.write(String.join(", ", words));
}
RequestBody fileBody = RequestBody.create(file, MediaType.parse("text/plain"));
Request uploadRequest = new Request.Builder().url(presignedUrl).put(fileBody).build();
try (Response uploadResponse = client.newCall(uploadRequest).execute()) {
if (uploadResponse.isSuccessful()) {
System.out.println("File uploaded successfully.");
} else {
System.out.println("Failed to upload file: " + uploadResponse.body().string());
}
}
} else {
System.out.println("Failed: " + response.body().string());
}
}
}
}
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class CustomVocabulary
{
private static readonly string apiKey = "your_api_key";
public static async Task Main()
{
var client = new HttpClient();
var url = "https://api.tor.app/developer/custom_vocabulary";
var body = new { language = "en-US" };
var jsonBody = new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
client.DefaultRequestHeaders.Add("Accept", "application/json");
var response = await client.PostAsync(url, jsonBody);
if (response.IsSuccessStatusCode)
{
var responseData = await response.Content.ReadAsStringAsync();
var presignedUrl = JsonDocument.Parse(responseData).RootElement.GetProperty("url").GetString();
var words = new[] { "Transkriptor", "Speech To Text", "Chat With Your Transcription", "Recognise Speakers" };
var filePath = "custom_words.txt";
await File.WriteAllTextAsync(filePath, string.Join(", ", words));
using var fileStream = File.OpenRead(filePath);
var uploadResponse = await client.PutAsync(presignedUrl, new StreamContent(fileStream));
if (uploadResponse.IsSuccessStatusCode)
{
Console.WriteLine("File uploaded successfully.");
}
else
{
Console.WriteLine("Failed to upload file: " + await uploadResponse.Content.ReadAsStringAsync());
}
}
else
{
Console.WriteLine("Failed: " + await response.Content.ReadAsStringAsync());
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
)
const apiKey = "your_api_key"
func main() {
url := "https://api.tor.app/developer/custom_vocabulary"
body := map[string]string{"language": "en-US"}
bodyBytes, _ := json.Marshal(body)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(bodyBytes))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
responseData := make(map[string]string)
json.NewDecoder(resp.Body).Decode(&responseData)
presignedUrl := responseData["url"]
words := "Transkriptor, Speech To Text, Chat With Your Transcription, Recognise Speakers"
filePath := "custom_words.txt"
err := ioutil.WriteFile(filePath, []byte(words), 0644)
if err != nil {
fmt.Println("Failed to write file:", err)
return
}
file, _ := os.Open(filePath)
defer file.Close()
req, _ = http.NewRequest("PUT", presignedUrl, file)
req.Header.Set("Content-Type", "text/plain")
uploadResp, err := client.Do(req)
if err != nil {
fmt.Println("Error uploading file:", err)
} else if uploadResp.StatusCode == 200 {
fmt.Println("File uploaded successfully.")
} else {
body, _ := ioutil.ReadAll(uploadResp.Body)
fmt.Println("Failed to upload file:", string(body))
}
} else {
fmt.Println("Failed with status code", resp.StatusCode)
}
}
require 'net/http'
require 'json'
require 'uri'
api_key = "your_api_key"
url = URI("https://api.tor.app/developer/custom_vocabulary")
headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{api_key}",
"Accept" => "application/json"
}
body = { "language" => "en-US" }
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url, headers)
request.body = body.to_json
response = http.request(request)
if response.code.to_i == 200
response_data = JSON.parse(response.body)
presigned_url = response_data["url"]
words = "Transkriptor, Speech To Text, Chat With Your Transcription, Recognise Speakers"
file_path = "custom_words.txt"
File.write(file_path, words)
uri = URI(presigned_url)
upload_request = Net::HTTP::Put.new(uri)
upload_request.body = File.read(file_path)
upload_request["Content-Type"] = "text/plain"
upload_response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
http.request(upload_request)
end
if upload_response.code.to_i == 200
puts "File uploaded successfully."
else
puts "Failed to upload file: #{upload_response.body}"
end
else
puts "Failed with status code #{response.code}"
end
<?php
$apiKey = "your_api_key"; // Replace with your actual API key
$url = "https://api.tor.app/developer/custom_vocabulary";
$headers = [
"Authorization: Bearer $apiKey",
"Content-Type: application/json",
"Accept: application/json"
];
$body = json_encode(["language" => "en-US"]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$responseData = json_decode($response, true);
if (isset($responseData["url"])) {
$presignedUrl = $responseData["url"];
$words = "Transkriptor, Speech To Text, Chat With Your Transcription, Recognise Speakers";
$filePath = "custom_words.txt";
file_put_contents($filePath, $words);
$file = fopen($filePath, "r");
$uploadCh = curl_init();
curl_setopt($uploadCh, CURLOPT_URL, $presignedUrl);
curl_setopt($uploadCh, CURLOPT_PUT, 1);
curl_setopt($uploadCh, CURLOPT_INFILE, $file);
curl_setopt($uploadCh, CURLOPT_INFILESIZE, filesize($filePath));
curl_setopt($uploadCh, CURLOPT_HTTPHEADER, ["Content-Type: text/plain"]);
$uploadResponse = curl_exec($uploadCh);
curl_close($uploadCh);
fclose($file);
echo "File uploaded successfully.\n";
} else {
echo "Failed: " . json_encode($responseData) . "\n";
}
?>
import okhttp3.*
import java.io.File
import java.io.FileWriter
fun main() {
val apiKey = "your_api_key" // Replace with your actual API key
val url = "https://api.tor.app/developer/custom_vocabulary"
val client = OkHttpClient()
val headers = Headers.Builder()
.add("Authorization", "Bearer $apiKey")
.add("Content-Type", "application/json")
.add("Accept", "application/json")
.build()
val body = RequestBody.create(MediaType.parse("application/json"), """{"language": "en-US"}""")
val request = Request.Builder().url(url).post(body).headers(headers).build()
client.newCall(request).execute().use { response ->
if (response.isSuccessful) {
val presignedUrl = JSONObject(response.body()?.string()).getString("url")
val words = "Transkriptor, Speech To Text, Chat With Your Transcription, Recognise Speakers"
val file = File("custom_words.txt").apply {
writeText(words)
}
val uploadRequest = Request.Builder()
.url(presignedUrl)
.put(RequestBody.create(MediaType.parse("text/plain"), file))
.build()
client.newCall(uploadRequest).execute().use { uploadResponse ->
if (uploadResponse.isSuccessful) {
println("File uploaded successfully.")
} else {
println("Failed to upload file: ${uploadResponse.body()?.string()}")
}
}
} else {
println("Failed to get presigned URL: ${response.body()?.string()}")
}
}
}
import Foundation
let apiKey = "your_api_key" // Replace with your actual API key
let url = URL(string: "https://api.tor.app/developer/custom_vocabulary")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
let body = ["language": "en-US"]
request.httpBody = try! JSONSerialization.data(withJSONObject: body)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data,
let jsonResponse = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
let presignedUrlString = jsonResponse["url"] as? String,
let presignedUrl = URL(string: presignedUrlString) {
let words = "Transkriptor, Speech To Text, Chat With Your Transcription, Recognise Speakers"
let filePath = FileManager.default.temporaryDirectory.appendingPathComponent("custom_words.txt")
try! words.write(to: filePath, atomically: true, encoding: .utf8)
var uploadRequest = URLRequest(url: presignedUrl)
uploadRequest.httpMethod = "PUT"
uploadRequest.addValue("text/plain", forHTTPHeaderField: "Content-Type")
let uploadTask = URLSession.shared.uploadTask(with: uploadRequest, fromFile: filePath) { data, response, error in
if let response = response as? HTTPURLResponse, response.statusCode == 200 {
print("File uploaded successfully.")
} else {
print("Failed to upload file.")
}
}
uploadTask.resume()
} else {
print("Failed to get presigned URL.")
}
}
task.resume()
import 'dart:convert';
import 'dart:io';
void main() async {
const apiKey = 'your_api_key'; // Replace with your actual API key
final url = Uri.parse("https://api.tor.app/developer/custom_vocabulary");
final headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer $apiKey',
'Accept': 'application/json'
};
final body = jsonEncode({"language": "en-US"});
final httpClient = HttpClient();
final request = await httpClient.postUrl(url)
..headers.set('Content-Type', 'application/json')
..headers.set('Authorization', 'Bearer $apiKey')
..add(utf8.encode(body));
final response = await request.close();
if (response.statusCode == 200) {
final responseData = await response.transform(utf8.decoder).join();
final presignedUrl = jsonDecode(responseData)["url"];
final words = "Transkriptor, Speech To Text, Chat With Your Transcription, Recognise Speakers";
final filePath = File("custom_words.txt");
await filePath.writeAsString(words);
final uploadRequest = await httpClient.putUrl(Uri.parse(presignedUrl));
uploadRequest.headers.set('Content-Type', 'text/plain');
uploadRequest.add(await filePath.readAsBytes());
final uploadResponse = await uploadRequest.close();
if (uploadResponse.statusCode == 200) {
print("File uploaded successfully.");
} else {
print("Failed to upload file.");
}
} else {
print("Failed to get presigned URL with status code: ${response.statusCode}");
}
}
Response
200 OK - Presigned URL Generated Successfully
{
"message": "Presigned URL generated successfully",
"url": "https://s3.amazonaws.com/app-options/custom_phrases/example_hashed_id/en_phrases.txt?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=1432075984&Signature=veryLongSignatureValue%3D"
}
500 Internal Server Error - Error Generating Presigned URL
{
"Error generating presigned URL"
}
Updated about 1 month ago