التشغيل السريع: تحويل الكلام إلى نص باستخدام نموذج الهمس Azure OpenAI

في هذا التشغيل السريع، يمكنك استخدام نموذج Azure OpenAI هامس لتحويل الكلام إلى نص.

حد حجم الملف لنموذج Azure OpenAI هامس هو 25 ميغابايت. إذا كنت بحاجة إلى نسخ ملف أكبر من 25 ميغابايت، يمكنك استخدام واجهة برمجة تطبيقات النسخ الدفعي ل Azure الذكاء الاصطناعي Speech.

المتطلبات الأساسية

إشعار

حاليا، يجب إرسال تطبيق للوصول إلى خدمة Azure OpenAI. للتقدم للحصول على حق الوصول، أكمل هذا النموذج.

الإعداد

قم باسترداد المفتاح ونقطة النهاية

لإجراء مكالمة بنجاح مقابل Azure OpenAI، ستحتاج إلى نقطة نهاية ومفتاح.

اسم المتغير القيمة‬
AZURE_OPENAI_ENDPOINT يمكن العثور على هذه القيمة في قسم المفاتيح ونقطة النهاية عند فحص المورد من مدخل Microsoft Azure. بدلاً من ذلك، يمكنك العثور على القيمة في Azure OpenAI Studio>Playground>Code View. مثال على نقطة النهاية هو: https://aoai-docs.openai.azure.com/.
AZURE_OPENAI_API_KEY يمكن العثور على هذه القيمة في قسم المفاتيح ونقطة النهاية عند فحص المورد من مدخل Microsoft Azure. يمكنك استخدام إما KEY1 أو KEY2.

انتقل إلى مجموعة الموارد في مدخل Microsoft Azure. يمكن العثور على نقطة النهاية والمفاتيح في قسم إدارة الموارد. انسخ نقطة النهاية ومفتاح الوصول حيث ستحتاج إلى كليهما لمصادقة استدعاءات واجهة برمجة التطبيقات. يمكنك استخدام إما KEY1 أو KEY2. يسمح لك وجود مفتاحين دائماً بتدوير المفاتيح وإعادة إنشائها بأمان دون التسبب في تعطيل الخدمة.

لقطة شاشة لواجهة مستخدم النظرة العامة لمورد Azure OpenAI في مدخل Azure مع وضع دائرة حول موقع مفاتيح نقطة النهاية باللون الأحمر.

إنشاء متغيرات بيئة ثابتة وتعيينها للمفتاح ونقطة النهاية.

متغيرات البيئة

setx AZURE_OPENAI_API_KEY "REPLACE_WITH_YOUR_KEY_VALUE_HERE" 
setx AZURE_OPENAI_ENDPOINT "REPLACE_WITH_YOUR_ENDPOINT_HERE" 

واجهة برمجة تطبيقات REST

في bash shell، قم بتشغيل الأمر التالي. تحتاج إلى استبدال YourDeploymentName باسم النشر الذي اخترته عند نشر نموذج الهمس. اسم التوزيع ليس بالضرورة هو نفس اسم النموذج. يؤدي إدخال اسم النموذج إلى حدوث خطأ ما لم تختص باسم نشر مطابق لاسم النموذج الأساسي.

curl $AZURE_OPENAI_ENDPOINT/openai/deployments/YourDeploymentName/audio/transcriptions?api-version=2024-02-01 \
 -H "api-key: $AZURE_OPENAI_API_KEY" \
 -H "Content-Type: multipart/form-data" \
 -F file="@./wikipediaOcelot.wav"

سيظهر تنسيق السطر الأول من الأمر مع مثال نقطة نهاية على النحو التالي curl https://aoai-docs.openai.azure.com/openai/deployments/{YourDeploymentName}/audio/transcriptions?api-version=2024-02-01 \.

يمكنك الحصول على ملفات صوتية نموذجية من مستودع Azure الذكاء الاصطناعي Speech SDK في GitHub.

هام

للإنتاج، استخدم طريقة آمنة لتخزين بيانات الاعتماد والوصول إليها مثل Azure Key Vault. لمزيد من المعلومات حول أمان بيانات الاعتماد، راجع مقالة أمان خدمات Azure الذكاء الاصطناعي.

المخرجات

{"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}

PowerShell

قم بتشغيل الأمر التالي. تحتاج إلى استبدال YourDeploymentName باسم النشر الذي اخترته عند نشر نموذج الهمس. اسم التوزيع ليس بالضرورة هو نفس اسم النموذج. يؤدي إدخال اسم النموذج إلى حدوث خطأ ما لم تختص باسم نشر مطابق لاسم النموذج الأساسي.

# Azure OpenAI metadata variables
$openai = @{
    api_key     = $Env:AZURE_OPENAI_API_KEY
    api_base    = $Env:AZURE_OPENAI_ENDPOINT # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
    api_version = '2024-02-01' # this may change in the future
    name        = 'YourDeploymentName' #This will correspond to the custom name you chose for your deployment when you deployed a model.
}

# Header for authentication
$headers = [ordered]@{
    'api-key' = $openai.api_key
}

$form = @{ file = get-item -path './wikipediaOcelot.wav' }

# Send a completion call to generate an answer
$url = "$($openai.api_base)/openai/deployments/$($openai.name)/audio/transcriptions?api-version=$($openai.api_version)"

$response = Invoke-RestMethod -Uri $url -Headers $headers -Form $form -Method Post -ContentType 'multipart/form-data'
return $response.text

يمكنك الحصول على ملفات صوتية نموذجية من مستودع Azure الذكاء الاصطناعي Speech SDK في GitHub.

هام

للإنتاج، استخدم طريقة آمنة لتخزين بيانات الاعتماد الخاصة بك والوصول إليها مثل إدارة PowerShell السرية باستخدام Azure Key Vault. لمزيد من المعلومات حول أمان بيانات الاعتماد، راجع مقالة أمان خدمات Azure الذكاء الاصطناعي.

المخرجات

The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs.

Python

المتطلبات الأساسية

الإعداد

تثبيت مكتبة عميل OpenAI Python باستخدام:

pip install openai
  1. إنشاء ملف Python جديد باسم ⁧⁩quickstart.py. ثم افتحه في المحرر أو IDE المُفضل لديك.

  2. استبدل التعليمات البرمجية التالية بمحتويات quickstart.py. تعديل التعليمات البرمجية لإضافة اسم النشر الخاص بك:

    import os
    from openai import AzureOpenAI
        
    client = AzureOpenAI(
        api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
        api_version="2024-02-01",
        azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
    )
    
    deployment_id = "YOUR-DEPLOYMENT-NAME-HERE" #This will correspond to the custom name you chose for your deployment when you deployed a model."
    audio_test_file = "./wikipediaOcelot.wav"
    
    result = client.audio.transcriptions.create(
        file=open(audio_test_file, "rb"),            
        model=deployment_id
    )
    
    print(result)

قم بتشغيل التطبيق باستخدام الأمر python على ملف التشغيل السريع:

يمكنك الحصول على ملفات صوتية نموذجية من مستودع Azure الذكاء الاصطناعي Speech SDK في GitHub.

هام

للإنتاج، استخدم طريقة آمنة لتخزين بيانات الاعتماد والوصول إليها مثل Azure Key Vault. لمزيد من المعلومات حول أمان بيانات الاعتماد، راجع مقالة أمان خدمات Azure الذكاء الاصطناعي.

المخرجات

{"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}

تنظيف الموارد

إذا كنت ترغب في تنظيف مورد Azure OpenAI وإزالته، يمكنك حذف المورد. قبل حذف المورد، يجب أولا حذف أي نماذج تم نشرها.

الخطوات التالية