وثائق API

ادمج التفريغ النصي من AudioToTextAI في تطبيقاتك عبر واجهة RESTful API لدينا.

التوثيق

جميع طلبات API تتطلب التحقق باستخدام مفتاح API. تضمن مفتاح API الخاص بك في البريد الإلكتروني. Authorization العنوان:

Authorization: Bearer YOUR_API_KEY

يمكنك أن تجد مفتاح API الخاص بك في إعدادات الحساب.

إبقي مفتاحك API سراً! لا تنشرها أبداً في شفرة جانب العميل أو المستودعات العامة.

تفريغ الصوت نصيًا

POST /api/v1/transcribe/

تحميل ملف صوتي للنسخ. API سوف يعود وظيفة هوية التي يمكنك استخدامها لاستفتاء للنتائج.

هيئة الطلب (بيانات متعددة الأجزاء/استمارة)
البارامترات النوع وصف المشروع
file * الملف ملف صوتي (MP3 أو WAV أو M4A أو FLAC أو OGG أو ملفات فيديو)
model سلسلة النموذج الذي سيستخدم: whisper-large-v3 (الافتراض) أو whisper-turbo
language سلسلة رمز اللغة ISO 639- 1 (مثل "en"، "es"). اتركه فارغا للكشف الآلي.
timestamps بوليان ضم الختم الزمني للقطاع (الافتراضي: صحيح)
word_timestamps بوليان تضمن ختما زمنيا على مستوى الكلمات (افتراضي: غير صحيح)
summary بوليان توليد موجز للذكاء الاصطناعي (الافتراض: غير صحيح)
vocabulary صفيفة مصطلحات مخصصة لتحسين الدقة (مصفوفة JSON أو فاصلة بفاصلة)
مثال طلب
curl -X POST https://audiototextai.com/api/v1/transcribe/ \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@audio.mp3" \
  -F "summary=true" \
  -F "language=en"
الرد
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "processing",
  "estimated_credits": 5.5
}

نسخ من URL

POST /api/v1/transcribe/url/

نسخ الصوت من عنوان URL. يدعم مباشرة URLs الصوت/فيديو و YouTube روابط.

جسد الطلب (JSON)
{
  "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "summary": true
}
مثال طلب
curl -X POST https://audiototextai.com/api/v1/transcribe/url/ \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/podcast.mp3", "summary": true}'

الحصول على نتائج النسخ

GET /api/v1/transcribe/{id}/

استرجاع حالة ونتائج عمل نسخ.

بارامترات الاستفسار
البارامترات النوع وصف المشروع
segments بوليان تضمن أجزاء مفصلة مع أختام زمنية (الافتراض: غير صحيح)
الرد (التجهيز)
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "processing",
  "progress": 45
}
الرد (اكتمل)
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "completed",
  "transcript": "Hello and welcome to today's podcast...",
  "duration_seconds": 1847.5,
  "language": "en",
  "credits_used": 31.2,
  "summary": "This podcast discusses the future of AI...",
  "topics": ["artificial intelligence", "technology", "future"],
  "segments": [
    {
      "start": 0.0,
      "end": 5.2,
      "text": "Hello and welcome to today's podcast.",
      "confidence": 0.98
    }
  ]
}

قائمة اللغات المدعومة

GET /api/v1/languages/

احصل على قائمة بجميع اللغات المدعومة للنسخ.

الرد
{
  "languages": [
    {"code": "", "name": "Auto-detect"},
    {"code": "en", "name": "English"},
    {"code": "es", "name": "Spanish"},
    {"code": "fr", "name": "French"},
    ...
  ]
}

حواجز شبكة الويب

بالنسبة للنسخ الطويل الأجل، يمكنك تقديم عنوان URL للحصول على النتائج عند الانتهاء من المعالجة.

تضاف الفقرة التالية: webhook_url إضافة بارامترات لطلب النسخ:

curl -X POST https://audiototextai.com/api/v1/transcribe/ \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@audio.mp3" \
  -F "webhook_url=https://yourapp.com/transcription-complete"

عندما ينتهي النسخ، سنرسل النتائج إلى موقعك على الويب:

POST https://yourapp.com/transcription-complete
Content-Type: application/json

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "completed",
  "transcript": "...",
  ...
}

معالجة الأخطاء

ويستخدم هذا البرنامج رموز حالة HTTP القياسية ويعيد تفاصيل الأخطاء في شكل JSON.

الحالة وصف المشروع
400 طلب خاطئ: بارامترات غير صحيحة أو حقول مطلوبة مفقودة
401 غير مأذون به: مفتاح API غير صحيح أو مفقود
402 الدفع مطلوب: الرصيد غير كافٍ
404 لم يوجد:
500 خطأ في الخادم: حدث خطأ ما في الطرف الخاص بنا
شكل رد الخطأ
{
  "error": "insufficient_credits",
  "message": "You have 10 credits remaining but this transcription requires 30 credits."
}

أمثلة على المدونات

Python
import requests

API_KEY = "your-api-key"
BASE_URL = "https://audiototextai.com/api/v1"

# Upload and transcribe
with open("audio.mp3", "rb") as f:
    response = requests.post(
        f"{BASE_URL}/transcribe/",
        headers={"Authorization": f"Bearer {API_KEY}"},
        files={"file": f},
        data={"summary": "true"}
    )
    job = response.json()
    print(f"Job ID: {job['id']}")

# Poll for results
import time
while True:
    result = requests.get(
        f"{BASE_URL}/transcribe/{job['id']}/",
        headers={"Authorization": f"Bearer {API_KEY}"},
        params={"segments": "true"}
    ).json()

    if result["status"] == "completed":
        print(result["transcript"])
        break
    elif result["status"] == "failed":
        print(f"Error: {result['error_message']}")
        break

    time.sleep(5)
JavaScript (Node.js)
const fs = require('fs');
const axios = require('axios');
const FormData = require('form-data');

const API_KEY = 'your-api-key';
const BASE_URL = 'https://audiototextai.com/api/v1';

async function transcribe(filePath) {
    const form = new FormData();
    form.append('file', fs.createReadStream(filePath));
    form.append('summary', 'true');

    const { data: job } = await axios.post(
        `${BASE_URL}/transcribe/`,
        form,
        {
            headers: {
                'Authorization': `Bearer ${API_KEY}`,
                ...form.getHeaders()
            }
        }
    );

    console.log(`Job ID: ${job.id}`);

    // Poll for results
    while (true) {
        const { data: result } = await axios.get(
            `${BASE_URL}/transcribe/${job.id}/`,
            { headers: { 'Authorization': `Bearer ${API_KEY}` } }
        );

        if (result.status === 'completed') {
            return result;
        } else if (result.status === 'failed') {
            throw new Error(result.error_message);
        }

        await new Promise(r => setTimeout(r, 5000));
    }
}

transcribe('./audio.mp3').then(console.log);