# Real-time analysis (streaming)

**Emotion-Logic's real-time API offers instant emotion detection for live interactions, making it ideal for voice-controlled devices, customer support, or any situation requiring immediate emotional understanding. With the real-time API, you can process streaming audio data and receive emotion detection results as events occur, enhancing responsiveness and user engagement.**

Streaming (real-time) analysis is based on socket.io (Web Socket) and consists of several events that are sent from the client to the Docker container and vice versa.   
Socket.io clients are supported by many programming languages.

Please refer to the full client implementation in the "stream-analysis-sample.js" file (NodeJS).

The analysis flow for a single call is as follows:

<div class="page" id="bkmrk-the-client-connects-" title="Page 9"><div class="section"><div class="layoutArea"><div class="column">1. The client connects to the Docker container.
2. The client sends a "handshake" event containing audio metadata.
3. The Docker container sends a "handshake-done" event, indicating that it is ready to start receiving the audio stream, or provides an error indication related to the "handshake" event.
4. The client begins sending "audio-stream" events with audio buffers.
5. The Docker container sends an "audio-analysis" event whenever it completes a new analysis.
6. The client disconnects when the stream (call) is finished.

</div></div></div></div>***All code samples in this document are in NodeJS, but any socket.io client library should work for this purpose.***

## Connecting the analysis server

Connecting the analysis server is a standard client-side websockets connection

[![59.png](https://docs.ado-tech.com/uploads/images/gallery/2025-03/scaled-1680-/NduEBSPwoeuRtynf-59.png)](https://docs.ado-tech.com/uploads/images/gallery/2025-03/NduEBSPwoeuRtynf-59.png)

## Handshake Event

Sent by: client

Event payload

<div class="page" id="bkmrk-parameter-is-mandato" title="Page 10"><div class="section"><div class="layoutArea"><div class="column"><div class="page" title="Page 10"><div class="section"><div class="layoutArea"><div class="column"><table border="1"><colgroup><col></col><col></col><col></col></colgroup><tbody><tr><td>**Parameter**</td><td>**Is Mandatory**</td><td>**Comments**</td></tr><tr><td>isPCM</td><td>Yes</td><td>Boolean, “true” if the stream is PCM format. Currently, this param must be true</td></tr><tr><td>channels</td><td>Yes</td><td>A number, to indicate the number of channels. May be “1” or “2”</td></tr><tr><td>backgroundNoise</td><td>Yes</td><td>A number represents the background noise in the recording. The higher the number the higher the background noise. Standard recording should have value of 1000</td></tr><tr><td>bitRate</td><td>Yes</td><td>A number represents the audio bit-rate. Currently 8 and 16 are supported</td></tr><tr><td>sampleRate</td><td>Yes</td><td>The audio sample rate. Supported values are:  
6000, 8000, 11025, 16000, 22050, 44100, 48000</td></tr><tr><td>outputType</td><td>No</td><td>Can be “json” ot “text”. Default is “json”</td></tr></tbody></table>

</div></div></div></div></div></div></div></div>## Handshake Done

The docker sends this event as a response to a “handshake” event. On success, the payload will contain the streamId, on error it will hold the error data.

Event name: handshake-done

Sent by: analysis server

Event payload:

<div class="page" id="bkmrk-parameter-comments-s" title="Page 11"><div class="section"><div class="layoutArea"><div class="column"><div class="page" title="Page 10"><div class="section"><div class="layoutArea"><div class="column"><table border="1"><colgroup><col></col><col></col></colgroup><tbody><tr><td>**Parameter**</td><td>**Comments**</td></tr><tr><td>success</td><td>Boolean, "true” handshake succeed</td></tr><tr><td>errorCode</td><td>an error code, in case the handshake failed (success == false)</td></tr><tr><td>error</td><td>an error message, in case the handshake failed (success == false)</td></tr></tbody></table>

</div></div></div></div></div></div></div></div>[![60.png](https://docs.ado-tech.com/uploads/images/gallery/2025-03/scaled-1680-/HXL5WritUnQ6a4vF-60.png)](https://docs.ado-tech.com/uploads/images/gallery/2025-03/HXL5WritUnQ6a4vF-60.png)

## Audio Stream

After a successful handshake, the client starts sending audio-buffers to the docker. The docker will asynchronously send the analysis results to the client.

Event: audio-stream

Sent by: client

Event payload: An audio buffer

[![61.png](https://docs.ado-tech.com/uploads/images/gallery/2025-03/scaled-1680-/BLoKgxuAUTkfW1kr-61.png)](https://docs.ado-tech.com/uploads/images/gallery/2025-03/BLoKgxuAUTkfW1kr-61.png)

## Audio Analysis

As the client sends audio buffers, the docker starts analyzing it. Whenever the docker build a new segment, it pushes the segment analysis to the client using the “audio-analysis” event.

Event: audio-analysis

Sent by: docker

Event payload: Segment analysis data. Please refer to [API Response](https://emlo.cloud/documentation/api-response "API Response") for analysis details.

[![61.png](https://docs.ado-tech.com/uploads/images/gallery/2025-03/scaled-1680-/BLoKgxuAUTkfW1kr-61.png)](https://docs.ado-tech.com/uploads/images/gallery/2025-03/BLoKgxuAUTkfW1kr-61.png)

## Fetch analysis report

At the end on the call, it is possible to send a "fetch-analysis-call" event to the docker.

The docker will respond with an "analysis-report-ready" event containing the call report (same report as accepted on a file-analysis call).

Event: fetch-analysis-call

Event parameters

<div class="page" id="bkmrk-parameter-is-mandato-1" title="Page 10"><div class="section"><div class="layoutArea"><div class="column"><table border="1"><colgroup><col></col><col></col><col></col></colgroup><tbody><tr><td>**Parameter**</td><td>**Is Mandatory**</td><td> </td></tr><tr><td>outputFormat</td><td>No</td><td>May be "json" (default) or "text"</td></tr><tr><td>fetchSegments</td><td>No</td><td>May be true (default) or false</td></tr></tbody></table>

</div></div></div></div>## Analysis report ready

After sending a "fetch analysis report" event, the analysis server respond and "analysis report ready" event.

The response will contain the same analysis report as provided by a regular file analysis.

Event: analysis-report-ready

Sent by: analysis server

[![63.png](https://docs.ado-tech.com/uploads/images/gallery/2025-03/scaled-1680-/7skpBkwvlixmC1LD-63.png)](https://docs.ado-tech.com/uploads/images/gallery/2025-03/7skpBkwvlixmC1LD-63.png)