通話レコーディングのクイックスタート

このクイックスタートで音声とビデオの通話の通話レコーディングを始めることができます。 通話レコーディング API を使い始めるには、通話を用意する必要があります。 エンド ユーザーの通話エクスペリエンスを作成するために、Calling Client SDKCall Automation について理解しておいてください。

サンプル コード

サンプル アプリは GitHub からダウンロードできます

前提条件

  • アクティブなサブスクリプションを含む Azure アカウントが必要です。
  • Communication Services リソースをデプロイします。 リソースの接続文字列をメモします。
  • Azure Event Grid を使ってイベントをサブスクライブします。
  • .NET SDK をダウンロードします。

開始する前に

通話レコーディング API で記録を開始するには、serverCallId のみを使います。 シナリオに応じて、serverCallId のフェッチに使用できるメソッドがいくつかあります。

Call Automation のシナリオ

  • Call Automation を使う場合、serverCallId を取得するには 2 つのオプションがあります。
    1. 通話が作成されると、通話が確立した後に CallConnected イベントのプロパティとして serverCallId が返されます。 Call Automation SDK から CallConnected を取得する方法を参照してください。
    2. 呼び出しに応答するか、通話が作成されると、AnswerCallResult または CreateCallResult API 応答それぞれのプロパティとして serverCallId が返されます。

Calling SDK のシナリオ

  • Calling Client SDK を使う場合、通話に対して getServerCallId メソッドを使うことで serverCallId を取得できます。 この例を使って Calling Client SDK から serverCallId を取得する方法を学習します。

それでは簡単な手順から始めましょう。

1. Call Automation クライアントを作成する

Call Recording API は、Azure Communication Services の Call Automation ライブラリの一部です。 したがって、Call Automation クライアントを作成する必要があります。 Call Automation クライアントを作成するには、Communication Services の接続文字列を使用し、それを CallAutomationClient オブジェクトに渡します。

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

2. "StartAsync" API を使用して StartRecordingOptions でレコーディング セッションを開始する

通話の開始時に受け取った serverCallId を使います。

  • RecordingContent は、レコーディング コンテンツ タイプを渡すために使用されます。 オーディオを使用する
  • RecordingChannel は、レコーディング チャネルの種類を渡すために使用されます。 ミックスまたは非ミックスを使います。
  • 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. レコーディングを開始する - Bring Your Own Azure Blob Store

レコーディングが完了したら、レコーディング ファイルを保存するように定義された独自の 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' API を使用して一時停止モードを有効にしてセッションのレコーディングを開始する

Note

レコーディング ファイルを生成するには、レコーディングを再開する必要があります。

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. 非ミックスのみ - チャネル 0 のユーザーを指定する

非ミキシング オーディオ レコーディング ファイルを生成するには、AudioChannelParticipantOrdering 機能を使用して、チャネル 0 に記録するユーザーを指定できます。 参加者の残りの部分は、話すときにチャネルに割り当てられます。 RecordingChannel.Unmixed を使用し、AudioChannelParticipantOrdering を使用しない場合、Call Recording によって最初に話している参加者にチャネル 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. 非ミックスのみ - チャネル アフィニティを指定する

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 API 応答には、レコーディング セッションの recordingId が含まれています。

3. "StopAsync" API を使用してレコーディング セッションを停止する

recordingId の応答で受け取った StartAsync を使います。

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

4. "PauseAsync" API を使用してレコーディング セッションを一時停止する

recordingId の応答で受け取った StartAsync を使います。

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

5. "ResumeAsync" API を使用してレコーディング セッションを再開する

recordingId の応答で受け取った StartAsync を使います。

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

6. 'DownloadToAsync' API を使ってレコーディング ファイルをダウンロードする

記録されたメディアをダウンロードする準備ができたときにサービスに通知するために、Azure Event Grid Web hook または他のトリガーされたアクションを使用する必要があります。

Event Grid の通知 Microsoft.Communication.RecordingFileStatusUpdated は、録音を取得する準備ができたときに発行されます。通常は、録音プロセスが完了 (たとえば、会議が終了して録音が停止) してから 1、2 分後になります。 録音のイベント通知には contentLocationmetadataLocation が含まれます。これらは、録音されたメディアと録音メタデータ ファイルの両方を取得するために使用できます。

イベント スキーマの例を次に示します。

{
    "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 API を使用します。

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

レコーディング用の downloadLocation は、recordingChunkcontentLocation 属性からフェッチできます。 DownloadToAsync メソッドは、指定されたファイル名にコンテンツをダウンロードします。

7. "DeleteAsync" API を使用してレコーディング コンテンツを削除する

レコーディング コンテンツ (記録されたメディア、メタデータなど) を削除するには、DeleteAsync API を使用します。

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

サンプル コード

サンプル アプリは GitHub からダウンロードできます

前提条件

  • アクティブなサブスクリプションを含む Azure アカウントが必要です。
  • Communication Services リソースをデプロイします。 リソースの接続文字列をメモします。
  • Azure Event Grid を使ってイベントをサブスクライブします。
  • Java SDK をダウンロードします。

開始する前に

通話レコーディング API で記録を開始するには、serverCallId のみを使います。 シナリオに応じて、serverCallId のフェッチに使用できるメソッドがいくつかあります。

Call Automation のシナリオ

  • Call Automation を使う場合、serverCallId を取得するには 2 つのオプションがあります。
    1. 通話が作成されると、通話が確立した後に CallConnected イベントのプロパティとして serverCallId が返されます。 Call Automation SDK から CallConnected を取得する方法を参照してください。
    2. 呼び出しに応答するか、通話が作成されると、AnswerCallResult または CreateCallResult API 応答それぞれのプロパティとして serverCallId が返されます。

Calling SDK のシナリオ

  • Calling Client SDK を使う場合、通話に対して getServerCallId メソッドを使うことで serverCallId を取得できます。 この例を使って Calling Client SDK から serverCallId を取得する方法を学習します。

それでは簡単な手順から始めましょう。

1. Call Automation クライアントを作成する

Call Recording API は、Azure Communication Services の Call Automation ライブラリの一部です。 したがって、Call Automation クライアントを作成する必要があります。 Call Automation クライアントを作成するには、Communication Services の接続文字列を使用し、それを CallAutomationClient オブジェクトに渡します。

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

2. "startWithResponse" API を使用して StartRecordingOptions でレコーディング セッションを開始する

通話の開始時に受け取った serverCallId を使います。

  • RecordingContent は、レコーディング コンテンツ タイプを渡すために使用されます。 AUDIO を使用する
  • RecordingChannel は、レコーディング チャネルの種類を渡すために使用されます。 ミックスまたは非ミックスを使います。
  • 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. レコーディングを開始する - Bring Your Own Azure Blob Store

レコーディングが完了したら、独自の 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' API を使用して一時停止モードを有効にしてセッションのレコーディングを開始する

Note

レコーディング ファイルを生成するには、レコーディングを再開する必要があります。

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. 非ミックスのみ - チャネル 0 のユーザーを指定する

非ミキシング オーディオ レコーディング ファイルを生成するには、AudioChannelParticipantOrdering 機能を使用して、チャネル 0 に記録するユーザーを指定できます。 参加者の残りの部分は、話すときにチャネルに割り当てられます。 RecordingChannel.Unmixed を使用し、AudioChannelParticipantOrdering を使用しない場合、Call Recording によって最初に話している参加者にチャネル 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. 非ミックスのみ - チャネル アフィニティを指定する

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 API 応答には、レコーディング セッションの recordingId が含まれています。

3. "stopWithResponse" API を使用してレコーディング セッションを停止する

recordingId の応答で受け取った startWithResponse を使います。

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

4. "pauseWithResponse" API を使用してレコーディング セッションを一時停止する

recordingId の応答で受け取った startWithResponse を使います。

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

5. "resumeWithResponse" API を使用してレコーディング セッションを再開する

recordingId の応答で受け取った startWithResponse を使います。

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

6. 'downloadToWithResponse' API を使ってレコーディング ファイルをダウンロードする

記録されたメディアをダウンロードする準備ができたときにサービスに通知するために、Azure Event Grid Web hook または他のトリガーされたアクションを使用する必要があります。

Event Grid の通知 Microsoft.Communication.RecordingFileStatusUpdated は、録音を取得する準備ができたときに発行されます。通常は、録音プロセスが完了 (たとえば、会議が終了して録音が停止) してから 1、2 分後になります。 録音のイベント通知には contentLocationmetadataLocation が含まれます。これらは、録音されたメディアと録音メタデータ ファイルの両方を取得するために使用できます。

イベント スキーマの例を次に示します。

{
    "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
}

記録されたメディアをダウンロードするには、CallRecording クラスの downloadToWithResponse メソッドを使用します。 downloadToWithResponse メソッドでサポートされているパラメーターを次に示します。

  • contentLocation: コンテンツが置かれている Azure Communication Services URL。
  • destinationPath: ファイルの場所。
  • parallelDownloadOptions: 並列ダウンロードの動作方法を変更するための省略可能な ParallelDownloadOptions オブジェクト。
  • overwrite: True にすると、ファイルが存在する場合、それは上書きされます。
  • 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);

レコーディング ファイルのコンテンツの場所とドキュメント ID は、recordingChunk ごとに、contentLocation および documentId フィールドからそれぞれ取得できます。

7. "deleteWithResponse" API を使用してレコーディング コンテンツを削除する。

記録されたメディアを削除するには、CallRecording クラスの deleteWithResponse メソッドを使用します。 deleteWithResponse メソッドでサポートされているパラメーターを次に示します。

  • deleteLocation: 削除するコンテンツが配置されている Azure Communication Services の URL。
  • context: 要求コンテキストを表すコンテキスト。
Response<Void> deleteResponse = callAutomationClient.getCallRecording().deleteWithResponse(deleteLocation, context);

レコーディングの削除場所は、Event Grid イベントの deleteLocation フィールドからフェッチできます。

サンプル コード

サンプル アプリは GitHub からダウンロードできます

前提条件

  • アクティブなサブスクリプションを含む Azure アカウントが必要です。
  • Communication Services リソースをデプロイします。 リソースの接続文字列をメモします。
  • Azure Event Grid を使ってイベントをサブスクライブします。
  • Python 3.7 以降。

開始する前に

通話レコーディング API で記録を開始するには、serverCallId のみを使います。 シナリオに応じて、serverCallId のフェッチに使用できるメソッドがいくつかあります。

Call Automation のシナリオ

  • Call Automation を使う場合、serverCallId を取得するには 2 つのオプションがあります。
    1. 通話が作成されると、通話が確立した後に CallConnected イベントのプロパティとして serverCallId が返されます。 Call Automation SDK から CallConnected を取得する方法を参照してください。
    2. 呼び出しに応答するか、通話が作成されると、AnswerCallResult または CreateCallResult API 応答それぞれのプロパティとして serverCallId が返されます。

Calling SDK のシナリオ

  • Calling Client SDK を使う場合、通話に対して server_call_id 変数を使うことで serverCallId を取得できます。 この例を使って Calling Client SDK から serverCallId を取得する方法を学習します。

それでは簡単な手順から始めましょう。

1. Call Automation クライアントを作成する

Call Recording API は、Azure Communication Services の Call Automation ライブラリの一部です。 したがって、Call Automation クライアントを作成する必要があります。 Call Automation クライアントを作成するには、Communication Services の接続文字列を使用し、それを CallAutomationClient オブジェクトに渡します。

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

2. start_recording API でレコーディング セッションを開始する

通話の開始時に受け取った serverCallId を使います。

  • RecordingContent は、レコーディング コンテンツ タイプを渡すために使用されます。 オーディオを使用する
  • RecordingChannel は、レコーディング チャネルの種類を渡すために使用されます。 ミックスまたは非ミックスを使います。
  • 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. レコーディングを開始する - Bring Your Own Azure Blob Store

レコーディングが完了したら、レコーディング ファイルを保存するように定義された独自の 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' API を使用して一時停止モードを有効にしてセッションのレコーディングを開始する

Note

レコーディング ファイルを生成するには、レコーディングを再開する必要があります。

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. 非ミックスのみ - チャネル 0 のユーザーを指定する

非ミキシング オーディオ レコーディング ファイルを生成するには、AudioChannelParticipantOrdering 機能を使用して、チャネル 0 に記録するユーザーを指定できます。 参加者の残りの部分は、話すときにチャネルに割り当てられます。 RecordingChannel.Unmixed を使用し、AudioChannelParticipantOrdering を使用しない場合、Call Recording によって最初に話している参加者にチャネル 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. 非ミックスのみ - チャネル アフィニティを指定する

_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 API 応答には、レコーディング セッションの recordingId が含まれています。

3. 'stop_recording' API を使用してレコーディング セッションを停止する

recording_id の応答で受け取った start_recording を使います。

stop_recording = call_automation_client.stop_recording(recording_id = recording_id)

4. 'pause_recording' API を使用してレコーディング セッションを一時停止する

recording_id の応答で受け取った start_recording を使います。

pause_recording = call_automation_client.pause_recording(recording_id = recording_id)

5. 'resume_recording' API を使用してレコーディング セッションを再開する

recording_id の応答で受け取った start_recording を使います。

resume_recording = call_automation_client.resume_recording(recording_id = recording_id)

6. 'download_recording' API を使用してレコーディング ファイルをダウンロードする

記録されたメディアをダウンロードする準備ができたときにサービスに通知するために、Azure Event Grid Web hook または他のトリガーされたアクションを使用する必要があります。

Event Grid の通知 Microsoft.Communication.RecordingFileStatusUpdated は、録音を取得する準備ができたときに発行されます。通常は、録音プロセスが完了 (たとえば、会議が終了して録音が停止) してから 1、2 分後になります。 録音のイベント通知には contentLocationmetadataLocation が含まれます。これらは、録音されたメディアと録音メタデータ ファイルの両方を取得するために使用できます。

イベント スキーマの例を次に示します。

{
    "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 API を使用します。

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 は、recordingChunkcontentLocation 属性からフェッチできます。 download_recording メソッドは、コンテンツをバイトにダウンロードします。

7. 'delete_recording' API を使用してレコーディング コンテンツを削除する

レコーディング コンテンツ (記録されたメディア、メタデータなど) を削除するには、delete_recording API を使用します。

response = call_automation_client.delete_recording(delete_location);

サンプル コード

サンプル アプリは GitHub からダウンロードできます

前提条件

  • アクティブなサブスクリプションを含む Azure アカウントが必要です。
  • Communication Services リソースをデプロイします。 リソースの接続文字列をメモします。
  • Azure Event Grid を使ってイベントをサブスクライブします。
  • Node.js アクティブ LTS およびメンテナンス LTS バージョン (8.11.1 および 10.14.1 を推奨)

開始する前に

通話レコーディング API で記録を開始するには、serverCallId のみを使います。 シナリオに応じて、serverCallId のフェッチに使用できるメソッドがいくつかあります。

Call Automation のシナリオ

  • Call Automation を使う場合、serverCallId を取得するには 2 つのオプションがあります。
    1. 通話が作成されると、通話が確立した後に CallConnected イベントのプロパティとして serverCallId が返されます。 Call Automation SDK から CallConnected を取得する方法を参照してください。
    2. 呼び出しに応答するか、通話が作成されると、AnswerCallResult または CreateCallResult API 応答それぞれのプロパティとして serverCallId が返されます。

Calling SDK のシナリオ

  • Calling Client SDK を使う場合、通話に対して getServerCallId メソッドを使うことで serverCallId を取得できます。 この例を使って Calling Client SDK から serverCallId を取得する方法を学習します。

それでは簡単な手順から始めましょう。

1. Call Automation クライアントを作成する

Call Recording API は、Azure Communication Services の Call Automation ライブラリの一部です。 したがって、Call Automation クライアントを作成する必要があります。 Call Automation クライアントを作成するには、Communication Services の接続文字列を使用し、それを CallAutomationClient オブジェクトに渡します。

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

2. "StartAsync" API を使用して StartRecordingOptions でレコーディング セッションを開始する

通話の開始時に受け取った serverCallId を使います。

  • RecordingContent は、レコーディング コンテンツ タイプを渡すために使用されます。 オーディオを使用する
  • RecordingChannel は、レコーディング チャネルの種類を渡すために使用されます。 ミックスまたは非ミックスを使います。
  • 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. レコーディングを開始する - Bring Your Own Azure Blob Store

レコーディングが完了したら、レコーディング ファイルを保存するように定義された独自の 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' API を使用して一時停止モードを有効にしてセッションのレコーディングを開始する

Note

レコーディング ファイルを生成するには、レコーディングを再開する必要があります。

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. 非ミックスのみ - チャネル 0 のユーザーを指定する

非ミキシング オーディオ レコーディング ファイルを生成するには、AudioChannelParticipantOrdering 機能を使用して、チャネル 0 に記録するユーザーを指定できます。 参加者の残りの部分は、話すときにチャネルに割り当てられます。 RecordingChannel.Unmixed を使用し、AudioChannelParticipantOrdering を使用しない場合、Call Recording によって最初に話している参加者にチャネル 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. 非ミックスのみ - チャネル アフィニティを指定する

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 API 応答には、レコーディング セッションの recordingId が含まれています。

3. 'stop' API を使用してレコーディング セッションを停止する

recordingId の応答で受け取った start を使います。

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

4. 'pause' API を使用してレコーディング セッションを一時停止する

recordingId の応答で受け取った start を使います。

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

5. "ResumeAsync" API を使用してレコーディング セッションを再開する

recordingId の応答で受け取った start を使います。

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

6. 'DownloadToAsync' API を使ってレコーディング ファイルをダウンロードする

記録されたメディアをダウンロードする準備ができたときにサービスに通知するために、Azure Event Grid Web hook または他のトリガーされたアクションを使用する必要があります。

Event Grid の通知 Microsoft.Communication.RecordingFileStatusUpdated は、録音を取得する準備ができたときに発行されます。通常は、録音プロセスが完了 (たとえば、会議が終了して録音が停止) してから 1、2 分後になります。 録音のイベント通知には contentLocationmetadataLocation が含まれます。これらは、録音されたメディアと録音メタデータ ファイルの両方を取得するために使用できます。

イベント スキーマの例を次に示します。

{
    "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 API を使用します。

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

レコーディング用の downloadLocation は、recordingChunkcontentLocation 属性からフェッチできます。 DownloadToAsync メソッドは、指定されたファイル名にコンテンツをダウンロードします。

7. "DeleteAsync" API を使用してレコーディング コンテンツを削除する

レコーディング コンテンツ (記録されたメディア、メタデータなど) を削除するには、delete API を使用します。

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

リソースをクリーンアップする

Communication Services サブスクリプションをクリーンアップして解除する場合は、リソースまたはリソース グループを削除できます。 リソース グループを削除すると、それに関連付けられている他のリソースも削除されます。 詳細については、リソースのクリーンアップに関する記事を参照してください。

次の手順

詳細については、次の記事を参照してください。