Code Examples

Ready-to-use code examples for integrating Speech-to-Text into your applications.

Python

Basic Transcription

import requests

url = "https://yourvoic.com/api/v1/stt/transcribe"
headers = {"X-API-Key": "your_api_key"}

with open("audio.mp3", "rb") as f:
    response = requests.post(url, headers=headers,
        files={"file": f},
        data={
            "model": "cipher-fast",
            "language": "en"  # Specify language for best accuracy
        })

result = response.json()
print(result["text"])

With Word Timestamps

import requests

response = requests.post(
    "https://yourvoic.com/api/v1/stt/cipher/transcribe",
    headers={"X-API-Key": "your_api_key"},
    files={"file": open("audio.mp3", "rb")},
    data={
        "model": "cipher-max",
        "response_format": "verbose_json",
        "timestamp_granularities": "word"
    }
)

result = response.json()
print(f"Text: {result['text']}")

# Print word timestamps
for word in result.get('words', []):
    print(f"{word['word']}: {word['start']}s - {word['end']}s")

With Speaker Diarization

import requests

response = requests.post(
    "https://yourvoic.com/api/v1/stt/lucid/transcribe",
    headers={"X-API-Key": "your_api_key"},
    files={"file": open("meeting.mp3", "rb")},
    data={
        "model": "lucid-multi",
        "language": "en",  # Important: Specify language for Lucid models
        "diarize": "true"
    }
)

result = response.json()
for word in result.get('words', []):
    print(f"Speaker {word['speaker']}: {word['word']}")

With Context Prompt

import requests

response = requests.post(
    "https://yourvoic.com/api/v1/stt/cipher/transcribe",
    headers={"X-API-Key": "your_api_key"},
    files={"file": open("medical_recording.mp3", "rb")},
    data={
        "model": "cipher-max",
        "prompt": "Medical terms: hypertension, myocardial infarction, echocardiogram",
        "response_format": "verbose_json",
        "timestamp_granularities": "word"
    }
)

result = response.json()
print(f"Text: {result['text']}")

JavaScript / Node.js

Using Fetch API

const formData = new FormData();
formData.append('file', audioFile); // audioFile is a File or Blob
formData.append('model', 'cipher-fast');

const response = await fetch('https://yourvoic.com/api/v1/stt/transcribe', {
    method: 'POST',
    headers: {
        'X-API-Key': 'your_api_key'
    },
    body: formData
});

const result = await response.json();
console.log(result.text);

Node.js with form-data

const fs = require('fs');
const FormData = require('form-data');
const axios = require('axios');

const form = new FormData();
form.append('file', fs.createReadStream('audio.mp3'));
form.append('model', 'cipher-fast');

const response = await axios.post(
    'https://yourvoic.com/api/v1/stt/transcribe',
    form,
    {
        headers: {
            ...form.getHeaders(),
            'X-API-Key': 'your_api_key'
        }
    }
);

console.log(response.data.text);

cURL

Basic Transcription

curl -X POST "https://yourvoic.com/api/v1/stt/transcribe" \
  -H "X-API-Key: your_api_key" \
  -F "file=@audio.mp3" \
  -F "model=cipher-fast" \
  -F "language=en"

With Speaker Diarization

curl -X POST "https://yourvoic.com/api/v1/stt/lucid/transcribe" \
  -H "X-API-Key: your_api_key" \
  -F "file=@meeting.mp3" \
  -F "model=lucid-multi" \
  -F "language=en" \
  -F "diarize=true"

With Word Timestamps

curl -X POST "https://yourvoic.com/api/v1/stt/cipher/transcribe" \
  -H "X-API-Key: your_api_key" \
  -F "file=@audio.mp3" \
  -F "model=cipher-max" \
  -F "language=en" \
  -F "response_format=verbose_json" \
  -F "timestamp_granularities=word"

PHP

<?php
$apiKey = 'your_api_key';
$audioFile = '/path/to/audio.mp3';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://yourvoic.com/api/v1/stt/transcribe');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'X-API-Key: ' . $apiKey
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
    'file' => new CURLFile($audioFile),
    'model' => 'cipher-fast'
]);

$response = curl_exec($ch);
curl_close($ch);

$result = json_decode($response, true);
echo $result['text'];
?>