You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- An Azure Communication Services resource. See [Create an Azure Communication Services resource](../../../quickstarts/create-communication-resource.md?tabs=windows&pivots=platform-azp).
17
17
- A new web service application created using the [Call Automation SDK](../../../quickstarts/call-automation/callflows-for-customer-interactions.md).
- A websocket server that can receive media streams.
19
+
- A websocket server that can send and receive media streams.
20
20
21
21
## Set up a websocket server
22
22
Azure Communication Services requires your server application to set up a WebSocket server to stream audio in real-time. WebSocket is a standardized protocol that provides a full-duplex communication channel over a single TCP connection.
23
-
You can optionally use Azure services Azure WebApps that allows you to create an application to receive audio streams over a websocket connection. Follow this [quickstart](https://azure.microsoft.com/blog/introduction-to-websockets-on-windows-azure-web-sites/).
24
23
25
-
## Establish a call
26
-
Establish a call and provide streaming details
24
+
You can review documentation [here](https://azure.microsoft.com/blog/introduction-to-websockets-on-windows-azure-web-sites/) to learn more about WebSockets and how to use them.
25
+
26
+
## Receiving and Sending audio streaming data
27
+
There are multiple ways to start receiving audio stream, which can be configured using the `startMediaStreaming` flag in the `mediaStreamingOptions` setup. You can also specify the desired sample rate used for receiving or sending audio data using the `audioFormat` parameter. Currently supported formats are PCM 24K mono and PCM 16K mono, with the default being PCM 16K mono.
28
+
29
+
To enable bidirectional audio streaming, where you're sending audio data into the call, you can enable the `EnableBidirectional` flag. For more details, refer to the [API specifications](https://learn.microsoft.com/rest/api/communication/callautomation/answer-call/answer-call?view=rest-communication-callautomation-2024-06-15-preview&tabs=HTTP#mediastreamingoptions).
30
+
31
+
### Start streaming audio to your webserver at time of answering the call
32
+
Enable automatic audio streaming when the call is established by setting the flag `startMediaStreaming: true`.
33
+
34
+
This setting ensures that audio streaming starts automatically as soon as the call is connected.
When Azure Communication Services receives the URL for your WebSocket server, it establishes a connection to it. Once the connection is successfully made, streaming is initiated.
55
+
56
+
### Start streaming audio to your webserver while a call is in progress
57
+
To start media streaming during the call, you can use the API. To do so, set the `startMediaStreaming` parameter to `false` (which is the default), and later in the call, you can use the start API to enable media streaming.
When Azure Communication Services receives the URL for your WebSocket server, it creates a connection to it. Once Azure Communication Services successfully connects to your WebSocket server and streaming is started, it will send through the first data packet, which contains metadata about the incoming media packets.
52
-
53
-
The metadata packet will look like this:
54
-
```
55
-
{
56
-
"kind": <string> // What kind of data this is, e.g. AudioMetadata, AudioData.
57
-
"audioMetadata": {
58
-
"subscriptionId": <string>, // unique identifier for a subscription request
To stop receiving audio streams during a call, you can use the **Stop streaming API**. This allows you to stop the audio streaming at any point in the call. There are two ways that audio streaming can be stopped;
89
+
1.**Triggering the Stop streaming API:** Use the API to stop receiving audio streaming data while the call is still active.
90
+
2.**Automatic stop on call disconnect:** Audio streaming automatically stops when the call is disconnected.
The first packet you receive contains metadata about the stream, including audio settings such as encoding, sample rate, and other configuration details.
After sending the metadata packet, Azure Communication Services (ACS) will begin streaming audio media to your WebSocket server.
151
+
152
+
```json
153
+
{
154
+
"kind": "AudioData",
155
+
"audioData": {
156
+
"timestamp": "2024-11-15T19:16:12.925Z",
157
+
"participantRawID": "8:acs:3d20e1de-0f28-41c5…",
158
+
"data": "5ADwAOMA6AD0A…",
159
+
"silent": false
160
+
}
161
+
}
162
+
```
163
+
164
+
## Sending audio streaming data to Azure Communication Services
165
+
If bidirectional streaming is enabled using the `EnableBidirectional` flag in the `MediaStreamingOptions`, you can stream audio data back to Azure Communication Services, which plays the audio into the call.
166
+
167
+
Once Azure Communication Services begins streaming audio to your WebSocket server, you can relay the audio to your AI services. After your AI service processes the audio content, you can stream the audio back to the on-going call in Azure Communication Services.
168
+
169
+
The example demonstrates how another service, such as Azure OpenAI or other voice-based Large Language Models, processes and transmits the audio data back into the call.
You can also control the playback of audio in the call when streaming back to Azure Communication Services, based on your logic or business flow. For example, when voice activity is detected and you want to stop the queued up audio, you can send a stop message via the WebSocket to stop the audio from playing in the call.
0 commit comments