Ignite 2024: Bidirectional real-time audio streaming with Azure Communication Services

Ignite 2024: Bidirectional real-time audio streaming with Azure Communication Services

Today at Microsoft Ignite, we’re excited to announce the upcoming preview of bidirectional audio streaming for Azure Communication Services Call Automation SDK, which unlocks new prospects for builders and companies. This functionality leads to seamless, low-latency, real-time communication when built-in with providers like Azure Open AI and the real-time voice APIs, considerably enhancing how companies can construct and deploy conversational AI options.

 

With the arrival of latest AI applied sciences, firms are growing options to scale back buyer wait occasions and enhance the general buyer expertise. To obtain this, many companies are turning to AI-powered brokers. These AI-based brokers have to be able to having conversations with clients in a human-like method whereas sustaining very low latencies to make sure clean interactions. This is very crucial within the voice channel, the place any delay can considerably impression the fluidity and pure really feel of the dialog.

 

With bidirectional streaming, companies can now elevate their voice options to low-latency, human-like, interactive conversational AI brokers. Our bidirectional streaming APIs allow builders to stream audio from an ongoing name on Azure Communication Services to their net server in real-time.

 

On the server, highly effective language fashions interpret the caller’s question and stream the responses again to the caller. All that is achieved whereas sustaining low latency, making certain the caller appears like they’re chatting with a human. One such instance of this is able to be to take the audio streams and processing them via Azure Open AI’s real-time voice API after which streaming the responses again into the decision.

 

With the combination of bidirectional streaming into Azure Communication Services Call Automation SDK, builders have new instruments to innovate:

  • Leverage conversational AI Solutions: Develop refined buyer assist digital brokers that may work together with clients in real-time, offering speedy responses and options.
  • Personalized buyer experiences: By harnessing real-time information, companies can provide extra personalised and dynamic buyer interactions in real-time, resulting in elevated satisfaction and loyalty.
  • Reduce wait occasions for purchasers: By utilizing bidirectional audio streams together with Large Language Models (LLMs) you’ll be able to construct digital brokers that may be the primary level of contact for purchasers lowering the necessity for purchasers ready for a human agent being out there.

With the developments in voice based mostly LLMs, builders need to make the most of providers like bidirectional streaming and ship audio straight between the caller and the LLM. Today we’ll present you how one can begin audio streaming via Azure Communication Services.

 

 

Developers can begin bidirectional streaming on the time of answering the decision by offering the WebSocket URL.

//Answer name with bidirectional streaming 
websocketUri = appBaseUrl.Replace("https", "wss") + "/ws";
var choices = new AnswerCallChoices(incomingCallContext, callbackUri)
{
    MediaStreamingChoices = new MediaStreamingChoices(
        transportUri: new Uri(websocketUri),
        contentType: MediaStreamingContent material.Audio,
        audioChannelType: MediaStreamingAudioChannel.Mixed,
        startMediaStreaming: true)
    {
        AllowBidirectional = true,
        AudioFormat = AudioFormat.Pcm24KMono
    }
};

 

At the identical time, it is best to open your reference to Azure Open AI real-time voice API. Once the WebSocket connection is setup, Azure Communication Services begins streaming audio to your webserver. From there you’ll be able to relay the audio to Azure Open AI voice and vice versa. Once the LLM causes over the content material offered within the audio it streams audio to your service which you’ll be able to stream again into the Azure Communication Services name. (More details about methods to set this up might be made out there after Ignite)

 

//Receiving streaming information from Azure Communication Services over websocket 
non-public async Task BeginReceivingFromAcsMediaWebSocket()
{
    if (m_webSocket == null) return;

    strive
    {
        whereas (m_webSocket.State == WebSocketState.Open || m_webSocket.State == WebSocketState.Closed)
        {
            byte[] receiveBuffer = new byte[2048];
            WebSocketReceiveResult receiveResult = await m_webSocket.ReceiveAsync(new ArraySegment<byte>(receiveBuffer), m_cts.Token);

            if (receiveResult.MessageType == WebSocketMessageType.Close) proceed;
            
            var information = Encoding.UTF8.GetString(receiveBuffer).TrimEnd('');
            if(StreamingData.Parse(information) is AudioData audioData)
            {
                utilizing var ms = new MemoryStream(audioData.Data);
                await m_aiServiceHandler.SendAudioToExternalAI(ms);               
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Exception -> {ex}");
    }
}

 

Streaming audio information again into Azure Communication Services

//create and serialize streaming information 
non-public void ConvertToAcsAudioPacketAndForward( byte[] audioData )
{
    var audio = new OutStreamingData(MediaKind.AudioData)
    {
        AudioData = new AudioData(audioData)
    };
    // Serialize the JSON object to a string
    string jsonString = System.Text.Json.JsonSerializer.Serialize<OutStreamingData>(audio);

   // Queue the async operation for later execution
    strive
      {
           m_channel.Writer.TryWrite(async () => await m_mediaStreaming.SendMessageAsync(information));
      }
      catch (Exception ex)
      {
            Console.WriteLine($""Exception acquired on ObtainAudioForOutBound {ex}");
      }
}

 

//Send encoded information over the websocket to Azure Communication Services 
public async Task SendMessageAsync(string message)
{
    if (m_webSocket?.State == WebSocketState.Open)
    {
        byte[] jsonBytes = Encoding.UTF8.GetBytes(message);

        // Send the PCM audio chunk over WebSocket
        await m_webSocket.SendAsync(new ArraySegment<byte>(jsonBytes), WebSocketMessageType.Text, endOfMessage: true, CancellationToken.None);
    }
}

 

To cut back developer overhead when integrating with voice-based LLMs, Azure Communication Services helps a brand new pattern price of 24Khz, eliminating the necessity for builders to resample audio information and serving to protect audio high quality within the course of

 

Next steps  

The SDK and documentation might be out there one within the subsequent few weeks after this announcement, providing instruments and data to combine bidirectional streaming and make the most of voice-based LLMs in your functions. Stay tuned to our weblog for updates!

HI-FI News

by way of Azure Feeds https://azurefeeds.com

November 19, 2024 at 06:00PM