التشغيل السريع لتسجيل المكالمات

تساعدك هذه البداية السريعة على بدء استخدام تسجيل المكالمات للمكالمات الصوتية ومكالمات الفيديو. لبدء استخدام واجهات برمجة التطبيقات لتسجيل المكالمات، يجب أن يكون لديك مكالمة في مكانها. تأكد من أنك على دراية باستدعاء SDK للعميل و/أو أتمتة المكالمات لإنشاء تجربة اتصال المستخدم النهائي.

نموذج التعليمات البرمجية

يمكنك تنزيل نموذج التطبيق من GitHub

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

  • تحتاج إلى حساب "Azure" مع اشتراك مفعل.
  • نشر مورد Communication Service. سجل سلسلة الاتصال المورد الخاص بك.
  • الاشتراك في الأحداث عبر Azure Event Grid.
  • تنزيل .NET SDK

قبل أن تبدأ

تستخدم واجهات برمجة تطبيقات تسجيل المكالمات حصريا serverCallIdلبدء التسجيل. هناك طريقتان يمكنك استخدامهما لجلب serverCallId اعتمادا على السيناريو الخاص بك:

سيناريوهات أتمتة المكالمات

  • عند استخدام أتمتة المكالمات، لديك خياران للحصول على serverCallId:
    1. بمجرد إنشاء مكالمة، serverCallId يتم إرجاع كخاصية للحدث CallConnected بعد إنشاء مكالمة. تعرف على كيفية الحصول على مكالمة الاتصال حدث من SDK لأتمتة المكالمات.
    2. بمجرد الرد على المكالمة أو إنشاء serverCallId مكالمة، يتم إرجاع كخاصية للاستجابات AnswerCallResult أو CreateCallResult API على التوالي.

استدعاء سيناريوهات SDK

  • عند استخدام Calling Client SDK، يمكنك استرداد serverCallId باستخدام الأسلوب في getServerCallId الاستدعاء. استخدم هذا المثال لمعرفة كيفية الحصول على serverCallId من Calling Client SDK.

لنبدأ ببعض الخطوات البسيطة!

1. إنشاء عميل أتمتة المكالمات

تعد واجهات برمجة تطبيقات تسجيل المكالمات جزءا من مكتبات Azure Communication Services Call Automation . وبالتالي، من الضروري إنشاء عميل أتمتة المكالمات. لإنشاء عميل أتمتة المكالمات، يمكنك استخدام سلسلة الاتصال Communication Services وتمريره إلى CallAutomationClient الكائن.

CallAutomationClient callAutomationClient = new CallAutomationClient("<ACSConnectionString>");

2. بدء تسجيل جلسة العمل باستخدام StartRecordingOptions باستخدام واجهة برمجة تطبيقات 'StartAsync'

استخدم المستلم أثناء serverCallId بدء المكالمة.

  • يتم استخدام RecordingContent لتمرير نوع محتوى التسجيل. استخدام الصوت
  • يتم استخدام قناة التسجيل لتمرير نوع قناة التسجيل. استخدم مختلط أو غير مختلط.
  • RecordingFormat يستخدم لتمرير تنسيق التسجيل. استخدم wav.
StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator("<ServerCallId>")) 
{
    RecordingContent = RecordingContent.Audio,
    RecordingChannel = RecordingChannel.Unmixed,
    RecordingFormat = RecordingFormat.Wav,
    RecordingStateCallbackUri = new Uri("<CallbackUri>");
};
Response<RecordingStateResult> response = await callAutomationClient.GetCallRecording()
.StartAsync(recordingOptions);

2.1. بدء التسجيل - إحضار مخزن Azure Blob الخاص بك

ابدأ التسجيل باستخدام Azure Blob Storage الخاص بك المحدد لتخزين ملف التسجيل بمجرد اكتمال التسجيل.

StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator("<ServerCallId>"))
{
   RecordingContent = RecordingContent.Audio,
   RecordingChannel = RecordingChannel.Unmixed,
   RecordingFormat = RecordingFormat.Wav,
   RecordingStateCallbackUri = new Uri("<CallbackUri>"),
   RecordingStorage = RecordingStorage.CreateAzureBlobContainerRecordingStorage(new Uri("<YOUR_STORAGE_CONTAINER_URL>"))
};
Response<RecordingStateResult> response = await callAutomationClient.GetCallRecording()
.StartAsync(recordingOptions);

2.2. بدء تسجيل جلسة العمل مع تمكين وضع الإيقاف المؤقت باستخدام واجهة برمجة تطبيقات 'StartAsync'

إشعار

يجب استئناف التسجيلات لإنشاء ملف التسجيل.

StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator("<ServerCallId>")) 
{
    RecordingContent = RecordingContent.Audio,
    RecordingChannel = RecordingChannel.Unmixed,
    RecordingFormat = RecordingFormat.Wav,
    PauseOnStart = true,
    RecordingStateCallbackUri = new Uri("<CallbackUri>");
};
Response<RecordingStateResult> response = await callAutomationClient.GetCallRecording()
.StartAsync(recordingOptions);

2.3. ل Unmixed فقط - حدد مستخدما على القناة 0

لإنتاج ملفات تسجيل صوتية غير ممزجة، يمكنك استخدام AudioChannelParticipantOrdering الوظيفة لتحديد المستخدم الذي تريد تسجيله على القناة 0. يتم تعيين بقية المشاركين إلى قناة أثناء التحدث. إذا كنت تستخدم RecordingChannel.Unmixed ولكن لا تستخدم AudioChannelParticipantOrdering، يقوم تسجيل المكالمات بتعيين القناة 0 إلى أول مشارك يتحدث.

StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator("<ServerCallId>")) 
{
    RecordingContent = RecordingContent.Audio,
    RecordingChannel = RecordingChannel.Unmixed,
    RecordingFormat = RecordingFormat.Wav,
    RecordingStateCallbackUri = new Uri("<CallbackUri>"),
    AudioChannelParticipantOrdering = { new CommunicationUserIdentifier("<ACS_USER_MRI>") }
    
};
Response<RecordingStateResult> response = await callAutomationClient.GetCallRecording().StartAsync(recordingOptions);

2.4. فقط ل Unmixed - حدد ترابط القناة

var channelAffinity = new ChannelAffinity(new CommunicationUserIdentifier("<ACS_USER_MRI>")) { Channel = 0};
StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator("<ServerCallId>"))
{
   RecordingContent = RecordingContent.Audio,
   RecordingChannel = RecordingChannel.Unmixed,
   RecordingFormat = RecordingFormat.Wav,
   RecordingStateCallbackUri = new Uri("<CallbackUri>"),
   ChannelAffinity = new List<ChannelAffinity>{ channelAffinity }
};
Response<RecordingStateResult> response = await callAutomationClient.GetCallRecording().StartAsync(recordingOptions);

StartAsync تحتوي استجابة واجهة برمجة التطبيقات على recordingId جلسة التسجيل.

3. إيقاف تسجيل جلسة العمل باستخدام واجهة برمجة تطبيقات "StopAsync"

استخدم المستلم recordingId استجابة ل StartAsync.

var stopRecording = await callAutomationClient.GetCallRecording().StopAsync(recordingId);

4. إيقاف جلسة التسجيل مؤقتا باستخدام واجهة برمجة تطبيقات "PauseAsync"

استخدم المستلم recordingId استجابة ل StartAsync.

var pauseRecording = await callAutomationClient.GetCallRecording ().PauseAsync(recordingId);

5. استئناف تسجيل الجلسة باستخدام واجهة برمجة تطبيقات "ResumeAsync"

استخدم المستلم recordingId استجابة ل StartAsync.

var resumeRecording = await callAutomationClient.GetCallRecording().ResumeAsync(recordingId);

6. تنزيل ملف التسجيل باستخدام واجهة برمجة تطبيقات "DownloadToAsync"

يجب استخدام رابط ويب Azure Event Grid أو أي إجراء آخر تم تشغيله لإعلام الخدمات عندما تكون الوسائط المسجلة جاهزة للتنزيل.

يتم نشر إعلام Microsoft.Communication.RecordingFileStatusUpdated Event Grid عندما يكون التسجيل جاهزا للاسترداد، عادة بعد بضع دقائق من اكتمال عملية التسجيل (على سبيل المثال، انتهى الاجتماع، توقف التسجيل). تسجيل إخطارات الأحداث تشمل contentLocation وmetadataLocation، والتي تستخدم لاسترداد كل من الوسائط المسجلة وملف تسجيل البيانات الوصفية.

مثال على مخطط الحدث:

{
    "id": string, // Unique guid for event
    "topic": string, // /subscriptions/{subscription-id}/resourceGroups/{group-name}/providers/Microsoft.Communication/communicationServices/{communication-services-resource-name}
    "subject": string, // /recording/call/{call-id}/serverCallId/{serverCallId}
    "data": {
        "recordingStorageInfo": {
            "recordingChunks": [
                {
                    "documentId": string, // Document id for the recording chunk
                    "contentLocation": string, //Azure Communication Services URL where the content is located
                    "metadataLocation": string, // Azure Communication Services URL where the metadata for this chunk is located
                    "deleteLocation": string, // Azure Communication Services URL to use to delete all content, including recording and metadata.
                    "index": int, // Index providing ordering for this chunk in the entire recording
                    "endReason": string, // Reason for chunk ending: "SessionEnded", "ChunkMaximumSizeExceeded”, etc.
                }
            ]
        },
        "recordingStartTime": string, // ISO 8601 date time for the start of the recording
        "recordingDurationMs": int, // Duration of recording in milliseconds
        "sessionEndReason": string // Reason for call ending: "CallEnded", "InitiatorLeft”, etc.
    },
    "eventType": string, // "Microsoft.Communication.RecordingFileStatusUpdated"
    "dataVersion": string, // "1.0"
    "metadataVersion": string, // "1"
    "eventTime": string // ISO 8601 date time for when the event was created
}

استخدام DownloadToAsync واجهة برمجة التطبيقات لتحميل الوسائط المسجلة.

var recordingDownloadUri = new Uri(contentLocation);
var response = await callAutomationClient.GetCallRecording().DownloadToAsync(recordingDownloadUri, fileName);

downloadLocation يمكن جلب للتسجيل من سمة contentLocation .recordingChunk DownloadToAsync يقوم الأسلوب بتنزيل المحتوى في اسم الملف المتوفر.

7. حذف محتوى التسجيل باستخدام واجهة برمجة تطبيقات "DeleteAsync"

استخدام DeleteAsync واجهة برمجة التطبيقات لحذف محتوى التسجيل (على سبيل المثال، الوسائط المسجلة وبيانات التعريف)

var recordingDeleteUri = new Uri(deleteLocation);
var response = await callAutomationClient.GetCallRecording().DeleteAsync(recordingDeleteUri);

نموذج التعليمات البرمجية

يمكنك تنزيل نموذج التطبيق من GitHub

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

  • تحتاج إلى حساب "Azure" مع اشتراك مفعل.
  • نشر مورد Communication Service. سجل سلسلة الاتصال المورد الخاص بك.
  • الاشتراك في الأحداث عبر Azure Event Grid.
  • تنزيل Java SDK

قبل أن تبدأ

تستخدم واجهات برمجة تطبيقات تسجيل المكالمات حصريا serverCallIdلبدء التسجيل. هناك طريقتان يمكنك استخدامهما لجلب serverCallId اعتمادا على السيناريو الخاص بك:

سيناريوهات أتمتة المكالمات

  • عند استخدام أتمتة المكالمات، لديك خياران للحصول على serverCallId:
    1. بمجرد إنشاء مكالمة، serverCallId يتم إرجاع كخاصية للحدث CallConnected بعد إنشاء مكالمة. تعرف على كيفية الحصول على مكالمة الاتصال حدث من SDK لأتمتة المكالمات.
    2. بمجرد الرد على المكالمة أو إنشاء serverCallId مكالمة، يتم إرجاع كخاصية للاستجابات AnswerCallResult أو CreateCallResult API على التوالي.

استدعاء سيناريوهات SDK

  • عند استخدام Calling Client SDK، يمكنك استرداد serverCallId باستخدام الأسلوب في getServerCallId الاستدعاء. استخدم هذا المثال لمعرفة كيفية الحصول على serverCallId من Calling Client SDK.

لنبدأ ببعض الخطوات البسيطة!

1. إنشاء عميل أتمتة المكالمات

تعد واجهات برمجة تطبيقات تسجيل المكالمات جزءا من مكتبات Azure Communication Services Call Automation . وبالتالي، من الضروري إنشاء عميل أتمتة المكالمات. لإنشاء عميل أتمتة المكالمات، ستستخدم سلسلة الاتصال Communication Services وتمريره إلى CallAutomationClient الكائن.

CallAutomationClient callAutomationClient = new CallAutomationClientBuilder()
            .connectionString("<acsConnectionString>")
            .buildClient();

2. بدء تسجيل جلسة العمل باستخدام StartRecordingOptions باستخدام واجهة برمجة تطبيقات 'startWithResponse'

استخدم المستلم أثناء serverCallId بدء المكالمة.

  • يتم استخدام RecordingContent لتمرير نوع محتوى التسجيل. استخدام الصوت
  • يتم استخدام قناة التسجيل لتمرير نوع قناة التسجيل. استخدم MIXED أو UNMIXED.
  • RecordingFormat يستخدم لتمرير تنسيق التسجيل. استخدام WAV.
StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator("<serverCallId>"))
                    .setRecordingChannel(RecordingChannel.UNMIXED)
                    .setRecordingFormat(RecordingFormat.WAV)
                    .setRecordingContent(RecordingContent.AUDIO)
                    .setRecordingStateCallbackUrl("<recordingStateCallbackUrl>");

Response<RecordingStateResult> response = callAutomationClient.getCallRecording()
.startWithResponse(recordingOptions, null);

2.1. بدء التسجيل - إحضار مخزن Azure Blob الخاص بك

ابدأ جلسة تسجيل باستخدام Azure Blob Storage الخاص بك لتخزين ملف التسجيل بمجرد اكتمال التسجيل.

       StartRecordingOptions recordingOptions = new StartRecordingOptions(callLocator)
       .setRecordingChannel(RecordingChannel.MIXED)
       .setRecordingContent(RecordingContent.AUDIO_VIDEO)
       .setRecordingFormat(RecordingFormat.MP4)
       .setRecordingStorage(new AzureBlobContainerRecordingStorage("<YOUR_STORAGE_CONTAINER_URL>"));
 
       // //start recording
       RecordingStateResult result = callRecording.start(recordingOptions);

2.2. بدء تسجيل جلسة العمل مع تمكين وضع الإيقاف المؤقت باستخدام واجهة برمجة تطبيقات 'StartAsync'

إشعار

يجب استئناف التسجيلات لإنشاء ملف التسجيل.

StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator("<serverCallId>"))
                    .setRecordingChannel(RecordingChannel.UNMIXED)
                    .setRecordingFormat(RecordingFormat.WAV)
                    .setRecordingContent(RecordingContent.AUDIO)
                    .setRecordingStateCallbackUrl("<recordingStateCallbackUrl>")
                    .setPauseOnStart(true)
                    .setAudioChannelParticipantOrdering(List.of(new CommunicationUserIdentifier("<participantMri>")));

Response<RecordingStateResult> response = callAutomationClient.getCallRecording()
.startWithResponse(recordingOptions, null);

2.3. ل Unmixed فقط - حدد مستخدما على القناة 0

لإنتاج ملفات تسجيل صوتية غير ممزجة، يمكنك استخدام AudioChannelParticipantOrdering الوظيفة لتحديد المستخدم الذي تريد تسجيله على القناة 0. سيتم تعيين بقية المشاركين إلى قناة أثناء التحدث. إذا كنت تستخدم RecordingChannel.Unmixed ولكن لا تستخدم AudioChannelParticipantOrdering، فسيعين تسجيل المكالمات القناة 0 للمشارك الأول الذي يتحدث.

StartRecordingOptions recordingOptions = new StartRecordingOptions(new ServerCallLocator("<serverCallId>"))
                    .setRecordingChannel(RecordingChannel.UNMIXED)
                    .setRecordingFormat(RecordingFormat.WAV)
                    .setRecordingContent(RecordingContent.AUDIO)
                    .setRecordingStateCallbackUrl("<recordingStateCallbackUrl>")
                    .setAudioChannelParticipantOrdering(List.of(new CommunicationUserIdentifier("<participantMri>")));

Response<RecordingStateResult> response = callAutomationClient.getCallRecording()
.startWithResponse(recordingOptions, null);

2.4. فقط ل Unmixed - حدد ترابط القناة

ChannelAffinity channelAffinity = new ChannelAffinity()
.setParticipant(new PhoneNumberIdentifier("RECORDING_ID"))
.setChannel(0);
List<ChannelAffinity> channelAffinities = Arrays.asList(channelAffinity);

StartRecordingOptions startRecordingOptions = new StartRecordingOptions(new ServerCallLocator(SERVER_CALL_ID))
   .setRecordingChannel(RecordingChannel.UNMIXED)
   .setRecordingFormat(RecordingFormat.WAV)
   .setRecordingContent(RecordingContent.AUDIO)
   .setRecordingStateCallbackUrl("<recordingStateCallbackUrl>")
   .setChannelAffinity(channelAffinities);
Response<RecordingStateResult> response = callAutomationClient.getCallRecording()
.startRecordingWithResponse(recordingOptions, null);

startWithResponse تحتوي استجابة واجهة برمجة التطبيقات على recordingId جلسة التسجيل.

3. إيقاف تسجيل جلسة العمل باستخدام واجهة برمجة تطبيقات 'stopWithResponse'

استخدم المستلم recordingId استجابة ل startWithResponse.

Response<Void> response = callAutomationClient.getCallRecording()
               .stopWithResponse(response.getValue().getRecordingId(), null);

4. إيقاف جلسة التسجيل مؤقتا باستخدام واجهة برمجة تطبيقات 'pauseWithResponse'

استخدم المستلم recordingId استجابة ل startWithResponse.

Response<Void> response = callAutomationClient.getCallRecording()
              .pauseWithResponse(response.getValue().getRecordingId(), null);

5. استئناف تسجيل الجلسة باستخدام واجهة برمجة تطبيقات "resumeWithResponse"

استخدم المستلم recordingId استجابة ل startWithResponse.

Response<Void> response = callAutomationClient.getCallRecording()
               .resumeWithResponse(response.getValue().getRecordingId(), null);

6. تنزيل ملف التسجيل باستخدام واجهة برمجة تطبيقات "downloadToWithResponse"

يجب استخدام رابط ويب Azure Event Grid أو أي إجراء آخر تم تشغيله لإعلام الخدمات عندما تكون الوسائط المسجلة جاهزة للتنزيل.

يتم نشر إعلام Microsoft.Communication.RecordingFileStatusUpdated Event Grid عندما يكون التسجيل جاهزا للاسترداد، عادة بعد بضع دقائق من اكتمال عملية التسجيل (على سبيل المثال، انتهى الاجتماع، توقف التسجيل). تسجيل إخطارات الأحداث تشمل contentLocation وmetadataLocation، والتي تستخدم لاسترداد كل من الوسائط المسجلة وملف تسجيل البيانات الوصفية.

فيما يلي مثال على مخطط الحدث.

{
    "id": string, // Unique guid for event
    "topic": string, // /subscriptions/{subscription-id}/resourceGroups/{group-name}/providers/Microsoft.Communication/communicationServices/{communication-services-resource-name}
    "subject": string, // /recording/call/{call-id}/serverCallId/{serverCallId}
    "data": {
        "recordingStorageInfo": {
            "recordingChunks": [
                {
                    "documentId": string, // Document id for the recording chunk
                    "contentLocation": string, //Azure Communication Services URL where the content is located
                    "metadataLocation": string, // Azure Communication Services URL where the metadata for this chunk is located
                    "deleteLocation": string, // Azure Communication Services URL to use to delete all content, including recording and metadata.
                    "index": int, // Index providing ordering for this chunk in the entire recording
                    "endReason": string, // Reason for chunk ending: "SessionEnded", "ChunkMaximumSizeExceeded”, etc.
                }
            ]
        },
        "recordingStartTime": string, // ISO 8601 date time for the start of the recording
        "recordingDurationMs": int, // Duration of recording in milliseconds
        "sessionEndReason": string // Reason for call ending: "CallEnded", "InitiatorLeft”, etc.
    },
    "eventType": string, // "Microsoft.Communication.RecordingFileStatusUpdated"
    "dataVersion": string, // "1.0"
    "metadataVersion": string, // "1"
    "eventTime": string // ISO 8601 date time for when the event was created
}

استخدم الأسلوب downloadToWithResponse من الفئة CallRecording لتنزيل الوسائط المسجلة. فيما يلي المعلمات المدعومة للأسلوب downloadToWithResponse:

  • contentLocation: عنوان URL لخدمات اتصالات Azure حيث يوجد المحتوى.
  • destinationPath: موقع الملف.
  • parallelDownloadOptions: كائن ParallelDownloadOptions اختياري لتعديل كيفية عمل التنزيل المتوازي.
  • overwrite: صحيح للكتابة فوق الملف إذا كان موجودًا.
  • context: سياق يمثل سياق الطلب.
Boolean overwrite = true;
ParallelDownloadOptions parallelDownloadOptions = null;
Context context = null;

String filePath = String.format(".\\%s.%s", documentId, fileType);
Path destinationPath = Paths.get(filePath);

Response<Void> downloadResponse = callAutomationClient.getCallRecording().downloadToWithResponse(contentLocation, destinationPath, parallelDownloadOptions, overwrite, context);

يمكن جلب موقع المحتوى ومعرفات المستندات لملفات التسجيل من الحقلين contentLocation وdocumentIdعلى التوالي لكل منهماrecordingChunk.

7. حذف محتوى التسجيل باستخدام واجهة برمجة تطبيقات 'deleteWithResponse'.

استخدم deleteWithResponse أسلوب CallRecording الفئة لحذف الوسائط المسجلة. فيما يلي المعلمات المدعومة للأسلوب deleteWithResponse:

  • deleteLocation: عنوان URL لخدمات اتصالات Azure حيث يوجد المحتوى المراد حذفه.
  • context: سياق يمثل سياق الطلب.
Response<Void> deleteResponse = callAutomationClient.getCallRecording().deleteWithResponse(deleteLocation, context);

يمكن جلب موقع الحذف للتسجيل من deleteLocation حقل حدث Event Grid.

نموذج التعليمات البرمجية

يمكنك تنزيل نموذج التطبيق من GitHub

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

  • تحتاج إلى حساب "Azure" مع اشتراك مفعل.
  • نشر مورد Communication Service. سجل سلسلة الاتصال المورد الخاص بك.
  • الاشتراك في الأحداث عبر Azure Event Grid.
  • Python 3.7+.

قبل أن تبدأ

تستخدم واجهات برمجة تطبيقات تسجيل المكالمات حصريا serverCallIdلبدء التسجيل. هناك طريقتان يمكنك استخدامهما لجلب serverCallId اعتمادا على السيناريو الخاص بك:

سيناريوهات أتمتة المكالمات

  • عند استخدام أتمتة المكالمات، لديك خياران للحصول على serverCallId:
    1. بمجرد إنشاء مكالمة، serverCallId يتم إرجاع كخاصية للحدث CallConnected بعد إنشاء مكالمة. تعرف على كيفية الحصول على مكالمة الاتصال حدث من SDK لأتمتة المكالمات.
    2. بمجرد الرد على المكالمة أو إنشاء serverCallId مكالمة، يتم إرجاع كخاصية للاستجابات AnswerCallResult أو CreateCallResult API على التوالي.

استدعاء سيناريوهات SDK

  • عند استخدام Calling Client SDK، يمكنك استرداد serverCallId باستخدام server_call_id المتغير في الاستدعاء. استخدم هذا المثال لمعرفة كيفية الحصول على serverCallId من Calling Client SDK.

لنبدأ ببعض الخطوات البسيطة!

1. إنشاء عميل أتمتة المكالمات

تعد واجهات برمجة تطبيقات تسجيل المكالمات جزءا من مكتبات Azure Communication Services Call Automation . وبالتالي، من الضروري إنشاء عميل أتمتة المكالمات. لإنشاء عميل أتمتة المكالمات، ستستخدم سلسلة الاتصال Communication Services وتمريره إلى CallAutomationClient الكائن.

call_automation_client = CallAutomationClient.from_connection_string("<ACSConnectionString>")

2. بدء تسجيل جلسة start_recording API

استخدم المستلم أثناء serverCallId بدء المكالمة.

  • يتم استخدام RecordingContent لتمرير نوع محتوى التسجيل. استخدام الصوت
  • يتم استخدام قناة التسجيل لتمرير نوع قناة التسجيل. استخدم مختلط أو غير مختلط.
  • RecordingFormat يستخدم لتمرير تنسيق التسجيل. استخدم wav.
response = call_automation_client.start_recording(call_locator=ServerCallLocator(server_call_id),
            recording_content_type = RecordingContent.Audio,
            recording_channel_type = RecordingChannel.Unmixed,
            recording_format_type = RecordingFormat.Wav,
            recording_state_callback_url = "<CallbackUri>")

2.1. بدء التسجيل - إحضار مخزن Azure Blob الخاص بك

ابدأ التسجيل باستخدام Azure Blob Storage الخاص بك المحدد لتخزين ملف التسجيل بمجرد اكتمال التسجيل.

response = call_automation_client.start_recording(call_locator=ServerCallLocator(server_call_id),
                   recording_content_type = RecordingContent.Audio,
                   recording_channel_type = RecordingChannel.Unmixed,
                   recording_format_type = RecordingFormat.Wav,
                   recording_state_callback_url = "<CallbackUri>",
                   recording_storage = AzureBlobContainerRecordingStorage(container_url="<YOUR_STORAGE_CONTAINER_URL>"))

2.2. بدء تسجيل جلسة العمل مع تمكين وضع الإيقاف المؤقت باستخدام واجهة برمجة تطبيقات 'StartAsync'

إشعار

يجب استئناف التسجيلات لإنشاء ملف التسجيل.

response = call_automation_client.start_recording(call_locator=ServerCallLocator(server_call_id),
            recording_content_type = RecordingContent.Audio,
            recording_channel_type = RecordingChannel.Unmixed,
            recording_format_type = RecordingFormat.Wav,
            pause_on_start = true,
            recording_state_callback_url = "<CallbackUri>")

2.3. ل Unmixed فقط - حدد مستخدما على القناة 0

لإنتاج ملفات تسجيل صوتية غير ممزجة، يمكنك استخدام AudioChannelParticipantOrdering الوظيفة لتحديد المستخدم الذي تريد تسجيله على القناة 0. سيتم تعيين بقية المشاركين إلى قناة أثناء التحدث. إذا كنت تستخدم RecordingChannel.Unmixed ولكن لا تستخدم AudioChannelParticipantOrdering، فسيعين تسجيل المكالمات القناة 0 للمشارك الأول الذي يتحدث.

response =  call_automation_client.start_recording(call_locator=ServerCallLocator(server_call_id),
            recording_content_type = RecordingContent.Audio,
            recording_channel_type = RecordingChannel.Unmixed,
            recording_format_type = RecordingFormat.Wav,
            recording_state_callback_url = "<CallbackUri>",
            audio_channel_participant_ordering=[CommunicationUserIdentifier(id="<ACS_USER_MRI>")])

2.4. فقط ل Unmixed - حدد ترابط القناة

_channel_affinity = ChannelAffinity(target_participant=CommunicationUserIdentifier("<ACS_USER_MRI>"), channel=0)

response =  call_automation_client.start_recording(call_locator=ServerCallLocator(server_call_id),
            recording_content_type = RecordingContent.Audio,
            recording_channel_type = RecordingChannel.Unmixed,
            recording_format_type = RecordingFormat.Wav,
            recording_state_callback_url = "<CallbackUri>",
            channel_affinity=[_channel_affinity])

StartAsync تحتوي استجابة واجهة برمجة التطبيقات على recordingId جلسة التسجيل.

3. إيقاف تسجيل جلسة العمل باستخدام واجهة برمجة تطبيقات "stop_recording"

استخدم المستلم recording_id استجابة ل start_recording.

stop_recording = call_automation_client.stop_recording(recording_id = recording_id)

4. إيقاف جلسة التسجيل مؤقتا باستخدام واجهة برمجة تطبيقات "pause_recording"

استخدم المستلم recording_id استجابة ل start_recording.

pause_recording = call_automation_client.pause_recording(recording_id = recording_id)

5. استئناف تسجيل الجلسة باستخدام واجهة برمجة التطبيقات "resume_recording"

استخدم المستلم recording_id استجابة ل start_recording.

resume_recording = call_automation_client.resume_recording(recording_id = recording_id)

6. تنزيل ملف التسجيل باستخدام واجهة برمجة تطبيقات "download_recording"

يجب استخدام رابط ويب Azure Event Grid أو أي إجراء آخر تم تشغيله لإعلام الخدمات عندما تكون الوسائط المسجلة جاهزة للتنزيل.

يتم نشر إعلام Microsoft.Communication.RecordingFileStatusUpdated Event Grid عندما يكون التسجيل جاهزا للاسترداد، عادة بعد بضع دقائق من اكتمال عملية التسجيل (على سبيل المثال، انتهى الاجتماع، توقف التسجيل). تسجيل إخطارات الأحداث تشمل contentLocation وmetadataLocation، والتي تستخدم لاسترداد كل من الوسائط المسجلة وملف تسجيل البيانات الوصفية.

فيما يلي مثال على مخطط الحدث.

{
    "id": string, // Unique guid for event
    "topic": string, // /subscriptions/{subscription-id}/resourceGroups/{group-name}/providers/Microsoft.Communication/communicationServices/{communication-services-resource-name}
    "subject": string, // /recording/call/{call-id}/serverCallId/{serverCallId}
    "data": {
        "recordingStorageInfo": {
            "recordingChunks": [
                {
                    "documentId": string, // Document id for the recording chunk
                    "contentLocation": string, //Azure Communication Services URL where the content is located
                    "metadataLocation": string, // Azure Communication Services URL where the metadata for this chunk is located
                    "deleteLocation": string, // Azure Communication Services URL to use to delete all content, including recording and metadata.
                    "index": int, // Index providing ordering for this chunk in the entire recording
                    "endReason": string, // Reason for chunk ending: "SessionEnded", "ChunkMaximumSizeExceeded”, etc.
                }
            ]
        },
        "recordingStartTime": string, // ISO 8601 date time for the start of the recording
        "recordingDurationMs": int, // Duration of recording in milliseconds
        "sessionEndReason": string // Reason for call ending: "CallEnded", "InitiatorLeft”, etc.
    },
    "eventType": string, // "Microsoft.Communication.RecordingFileStatusUpdated"
    "dataVersion": string, // "1.0"
    "metadataVersion": string, // "1"
    "eventTime": string // ISO 8601 date time for when the event was created
}

استخدام download_recording واجهة برمجة التطبيقات لتحميل الوسائط المسجلة.

response = recording_data = call_automation_client.download_recording(content_location)

with open("<file_name>", "wb") as binary_file:
    binary_file.write(recording_data.read())

downloadLocation يمكن جلب للتسجيل من سمة contentLocation .recordingChunk download_recording أسلوب تنزيل المحتوى إلى وحدات البايت.

7. حذف محتوى التسجيل باستخدام واجهة برمجة التطبيقات "delete_recording"

استخدام delete_recording واجهة برمجة التطبيقات لحذف محتوى التسجيل (على سبيل المثال، الوسائط المسجلة وبيانات التعريف)

response = call_automation_client.delete_recording(delete_location);

نموذج التعليمات البرمجية

يمكنك تنزيل نموذج التطبيق من GitHub

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

  • تحتاج إلى حساب "Azure" مع اشتراك مفعل.
  • نشر مورد Communication Service. سجل سلسلة الاتصال المورد الخاص بك.
  • الاشتراك في الأحداث عبر Azure Event Grid.
  • Node.js إصدارات LTS والصيانة النشطة LTS (8.11.1 و10.14.1 مستحسن)

قبل أن تبدأ

تستخدم واجهات برمجة تطبيقات تسجيل المكالمات حصريا serverCallIdلبدء التسجيل. هناك طريقتان يمكنك استخدامهما لجلب serverCallId اعتمادا على السيناريو الخاص بك:

سيناريوهات أتمتة المكالمات

  • عند استخدام أتمتة المكالمات، لديك خياران للحصول على serverCallId:
    1. بمجرد إنشاء مكالمة، serverCallId يتم إرجاع كخاصية للحدث CallConnected بعد إنشاء مكالمة. تعرف على كيفية الحصول على مكالمة الاتصال حدث من SDK لأتمتة المكالمات.
    2. بمجرد الرد على المكالمة أو إنشاء serverCallId مكالمة، يتم إرجاع كخاصية للاستجابات AnswerCallResult أو CreateCallResult API على التوالي.

استدعاء سيناريوهات SDK

  • عند استخدام Calling Client SDK، يمكنك استرداد serverCallId باستخدام الأسلوب في getServerCallId الاستدعاء. استخدم هذا المثال لمعرفة كيفية الحصول على serverCallId من Calling Client SDK.

لنبدأ ببعض الخطوات البسيطة!

1. إنشاء عميل أتمتة المكالمات

تعد واجهات برمجة تطبيقات تسجيل المكالمات جزءا من مكتبات Azure Communication Services Call Automation . وبالتالي، من الضروري إنشاء عميل أتمتة المكالمات. لإنشاء عميل أتمتة المكالمات، ستستخدم سلسلة الاتصال Communication Services وتمريره إلى CallAutomationClient الكائن.

const callAutomationClient = new CallAutomationClient.CallAutomationClient("<ACSConnectionString>");

2. بدء تسجيل جلسة العمل باستخدام StartRecordingOptions باستخدام واجهة برمجة تطبيقات 'StartAsync'

استخدم المستلم أثناء serverCallId بدء المكالمة.

  • يتم استخدام RecordingContent لتمرير نوع محتوى التسجيل. استخدام الصوت
  • يتم استخدام قناة التسجيل لتمرير نوع قناة التسجيل. استخدم مختلط أو غير مختلط.
  • RecordingFormat يستخدم لتمرير تنسيق التسجيل. استخدم wav.
var locator: CallLocator = { id: "<ServerCallId>", kind: "serverCallLocator" };

var options: StartRecordingOptions =
{
  callLocator: locator,
  recordingContent: "audio",
  recordingChannel:"unmixed",
  recordingFormat: "wav",
  recordingStateCallbackEndpointUrl: "<CallbackUri>"
};
var response = await callAutomationClient.getCallRecording().start(options);

2.1. بدء التسجيل - إحضار مخزن Azure Blob الخاص بك

ابدأ التسجيل باستخدام Azure Blob Storage الخاص بك المحدد لتخزين ملف التسجيل بمجرد اكتمال التسجيل.

const recordingStorageKind: RecordingStorageKind = "azureBlobStorage"
const recordingStorage: RecordingStorage = { 
       recordingStorageKind: recordingStorageKind, 
       recordingDestinationContainerUrl: "<YOUR_STORAGE_CONTAINER_URL>"
   }
var options: StartRecordingOptions = {
       callLocator: callLocator,
       recordingContent: "audio",
       recordingChannel:"unmixed",
       recordingFormat: "wav",
       recordingStateCallbackEndpointUrl: "<CallbackUri>",
       recordingStorage: recordingStorage
   };
var response = await callAutomationClient.getCallRecording().start(options);

2.2. بدء تسجيل جلسة العمل مع تمكين وضع الإيقاف المؤقت باستخدام واجهة برمجة تطبيقات 'StartAsync'

إشعار

يجب استئناف التسجيلات لإنشاء ملف التسجيل.

var locator: CallLocator = { id: "<ServerCallId>", kind: "serverCallLocator" };

var options: StartRecordingOptions =
{
  callLocator: locator,
  recordingContent: "audio",
  recordingChannel:"unmixed",
  recordingFormat: "wav",
  pauseOnStart: true
  recordingStateCallbackEndpointUrl: "<CallbackUri>",
  audioChannelParticipantOrdering:[{communicationUserId: "<ACS_USER_MRI>"}]
};
var response = await callAutomationClient.getCallRecording().start(options);

2.3. ل Unmixed فقط - حدد مستخدما على القناة 0

لإنتاج ملفات تسجيل صوتية غير ممزجة، يمكنك استخدام AudioChannelParticipantOrdering الوظيفة لتحديد المستخدم الذي تريد تسجيله على القناة 0. سيتم تعيين بقية المشاركين إلى قناة أثناء التحدث. إذا كنت تستخدم RecordingChannel.Unmixed ولكن لا تستخدم AudioChannelParticipantOrdering، فسيعين تسجيل المكالمات القناة 0 للمشارك الأول الذي يتحدث.

var locator: CallLocator = { id: "<ServerCallId>", kind: "serverCallLocator" };

var options: StartRecordingOptions =
{
  callLocator: locator,
  recordingContent: "audio",
  recordingChannel:"unmixed",
  recordingFormat: "wav",
  recordingStateCallbackEndpointUrl: "<CallbackUri>",
  audioChannelParticipantOrdering:[{communicationUserId: "<ACS_USER_MRI>"}]
};
var response = await callAutomationClient.getCallRecording().start(options);

2.4. فقط ل Unmixed - حدد ترابط القناة

var options: StartRecordingOptions =
{
  callLocator: locator,
  recordingContent: "audio",
  recordingChannel:"unmixed",
  recordingFormat: "wav",
  recordingStateCallbackEndpointUrl: "<CallbackUri>",
  ChannelAffinity:
  [
    {
      channel:0,
      targetParticipant:{communicationUserId: "<ACS_USER_MRI>"}
    }
  ]
};
var response = await callAutomationClient.getCallRecording().start(options);

StartAsync تحتوي استجابة واجهة برمجة التطبيقات على recordingId جلسة التسجيل.

3. إيقاف تسجيل جلسة العمل باستخدام واجهة برمجة تطبيقات "إيقاف"

استخدم المستلم recordingId استجابة ل start.

var stopRecording = await callAutomationClient.getCallRecording().stop(recordingId);

4. إيقاف جلسة التسجيل مؤقتا باستخدام "إيقاف مؤقت" لواجهة برمجة التطبيقات

استخدم المستلم recordingId استجابة ل start.

var pauseRecording = await callAutomationClient.getCallRecording().pause(recordingId);

5. استئناف تسجيل الجلسة باستخدام واجهة برمجة تطبيقات "ResumeAsync"

استخدم المستلم recordingId استجابة ل start.

var resumeRecording = await callAutomationClient.getCallRecording().resume(recordingId);

6. تنزيل ملف التسجيل باستخدام واجهة برمجة تطبيقات "DownloadToAsync"

يجب استخدام رابط ويب Azure Event Grid أو أي إجراء آخر تم تشغيله لإعلام الخدمات عندما تكون الوسائط المسجلة جاهزة للتنزيل.

يتم نشر إعلام Microsoft.Communication.RecordingFileStatusUpdated Event Grid عندما يكون التسجيل جاهزا للاسترداد، عادة بعد بضع دقائق من اكتمال عملية التسجيل (على سبيل المثال، انتهى الاجتماع، توقف التسجيل). تسجيل إخطارات الأحداث تشمل contentLocation وmetadataLocation، والتي تستخدم لاسترداد كل من الوسائط المسجلة وملف تسجيل البيانات الوصفية.

فيما يلي مثال على مخطط الحدث.

{
    "id": string, // Unique guid for event
    "topic": string, // /subscriptions/{subscription-id}/resourceGroups/{group-name}/providers/Microsoft.Communication/communicationServices/{communication-services-resource-name}
    "subject": string, // /recording/call/{call-id}/serverCallId/{serverCallId}
    "data": {
        "recordingStorageInfo": {
            "recordingChunks": [
                {
                    "documentId": string, // Document id for the recording chunk
                    "contentLocation": string, //Azure Communication Services URL where the content is located
                    "metadataLocation": string, // Azure Communication Services URL where the metadata for this chunk is located
                    "deleteLocation": string, // Azure Communication Services URL to use to delete all content, including recording and metadata.
                    "index": int, // Index providing ordering for this chunk in the entire recording
                    "endReason": string, // Reason for chunk ending: "SessionEnded", "ChunkMaximumSizeExceeded”, etc.
                }
            ]
        },
        "recordingStartTime": string, // ISO 8601 date time for the start of the recording
        "recordingDurationMs": int, // Duration of recording in milliseconds
        "sessionEndReason": string // Reason for call ending: "CallEnded", "InitiatorLeft”, etc.
    },
    "eventType": string, // "Microsoft.Communication.RecordingFileStatusUpdated"
    "dataVersion": string, // "1.0"
    "metadataVersion": string, // "1"
    "eventTime": string // ISO 8601 date time for when the event was created
}

استخدام downloadToPath واجهة برمجة التطبيقات لتحميل الوسائط المسجلة.

var response = await callAutomationClient.getCallRecording().downloadToPath(contentLocation, fileName);

downloadLocation يمكن جلب للتسجيل من سمة contentLocation .recordingChunk DownloadToAsync أسلوب تنزيل المحتوى في اسم الملف المتوفر.

7. حذف محتوى التسجيل باستخدام واجهة برمجة تطبيقات "DeleteAsync"

استخدام delete واجهة برمجة التطبيقات لحذف محتوى التسجيل (على سبيل المثال، الوسائط المسجلة وبيانات التعريف)

var response = await callAutomationClient.getCallRecording().delete(deleteLocation);

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

إذا كنت ترغب في تنظيف وإزالة اشتراك Communication Services، يمكنك حذف المورد أو مجموعة الموارد. يؤدي حذف مجموعة الموارد إلى حذف أية موارد أخرى مقترنة بها أيضًا. تعرّف على المزيد حول تنظيف الموارد.

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

لمزيد من المعلومات، راجع المقالات التالية: