Skip to content

Commit 8538c5b

Browse files
authored
Update play-audio-with-ai-java.md
add deserialization code snippets
1 parent 5ccf37f commit 8538c5b

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

articles/communication-services/how-tos/call-automation/includes/play-audio-with-ai-java.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ You can test creating your own audio file using our [Speech synthesis with Audio
7171

7272
## (Optional) Connect your Azure Cognitive Service to your Azure Communication Service
7373

74-
If you would like to use Text-To-Speech capabilities, then it's required for you to connect your Azure Cognitive Service to your Azure Communication Service.
75-
76-
``` code
77-
az communication bind-cognitive-service --name “{Azure Communication resource name}” --resource-group “{Azure Communication resource group}” --resource-id “{Cognitive service resource id}” --subscription{subscription Name of Cognitive service} –identity{Cognitive Services Identity}
78-
79-
```
74+
If you would like to use Text-To-Speech capabilities, then it's required for you to connect your [Azure Cognitive Service to your Azure Communication Service](../../../concepts/call-automation/azure-communication-services-azure-cognitive-services-integration.md).
8075

8176
## Update App.java with code
8277

@@ -171,27 +166,30 @@ assertEquals(202, playResponse.getStatusCode()); // The request was accepted
171166

172167
Your application receives action lifecycle event updates on the callback URL that was provided to Call Automation service at the time of answering the call. An example of a successful play event update.
173168

174-
```json
175-
[{
176-
"id": "704a7a96-4d74-4ebe-9cd0-b7cc39c3d7b1",
177-
"source": "calling/callConnections/<callConnectionId>/PlayCompleted",
178-
"type": "Microsoft.Communication.PlayCompleted",
179-
"data": {
180-
"resultInfo": {
181-
"code": 200,
182-
"subCode": 0,
183-
"message": "Action completed successfully."
184-
},
185-
"type": "playCompleted",
186-
"callConnectionId": "<callConnectionId>",
187-
"serverCallId": "<serverCallId>",
188-
"correlationId": "<correlationId>"
189-
},
190-
"time": "2022-08-12T03:13:25.0252763+00:00",
191-
"specversion": "1.0",
192-
"datacontenttype": "application/json",
193-
"subject": "calling/callConnections/<callConnectionId>/PlayCompleted"
194-
}]
169+
### Example of how you can deserialize the *PlayCompleted* event:
170+
171+
``` java
172+
if (callEvent instanceof PlayCompleted) {
173+
CallAutomationEventWithReasonCodeBase playCompleted= (CallAutomationEventWithReasonCodeBase) callEvent;
174+
Reasoncode reasonCode = playCompleted.getReasonCode();
175+
ResultInformation = playCompleted.getResultInformation();
176+
//Play audio completed, Take some action on completed event.
177+
// Hang up call
178+
callConnection.hangUp(true);
179+
}
180+
```
181+
182+
### Example of how you can deserialize the *PlayFailed* event:
183+
184+
``` java
185+
if (callEvent instanceof PlayFailed) {
186+
CallAutomationEventWithReasonCodeBase playFailed = (CallAutomationEventWithReasonCodeBase) callEvent;
187+
Reasoncode reasonCode = playFailed.getReasonCode();
188+
ResultInformation = playFailed.getResultInformation();
189+
//Play audio failed, Take some action on failed event.
190+
// Hang up call
191+
callConnection.hangUp(true);
192+
}
195193
```
196194

197195
To learn more about other supported events, visit the [Call Automation overview document](../../../concepts/call-automation/call-automation.md#call-automation-webhook-events).
@@ -205,3 +203,16 @@ var callConnection = callAutomationAsyncClient.getCallConnectionAsync(<callConne
205203
var cancelResponse = callConnection.getCallMediaAsync().cancelAllMediaOperationsWithResponse().block();
206204
assertEquals(202, cancelResponse.getStatusCode()); // The request was accepted
207205
```
206+
207+
### Example of how you can deserialize the *PlayCanceled* event:
208+
209+
``` java
210+
if (callEvent instanceof PlayCanceled {
211+
CallAutomationEventWithReasonCodeBase playCanceled= (CallAutomationEventWithReasonCodeBase) callEvent;
212+
Reasoncode reasonCode = playCanceled.getReasonCode();
213+
ResultInformation = playCanceled.getResultInformation();
214+
//Play audio completed, Take some action on canceled event.
215+
// Hang up call
216+
callConnection.hangUp(true);
217+
}
218+
```

0 commit comments

Comments
 (0)