Sentiment analysis on messages

Sentiment Analysis is the process of determining whether each message/line in a conversation is positive, negative, or neutral. Sentiment analysis on messages combines natural language processing and machine learning procedures to allot sentiment scores to the message.

Note that Sentiment Analysis currently only supports the en-US (English US) language.

For sentiment analysis of messages, you need to process your conversation with Symbl and then use the conversationId you received from the Get messages response and pass the sentiment parameter to get the transcript with the sentiment, polarity, and score.

Step 1: Process a conversation

Use the Async API in text, audio, or video version to process your conversation.

This example shows how to process an audio file (in .wav format) via the Async API Process Audio. You can use the same basic steps to process video and text conversations. For more information, see Async API.

Note that you must wait for the job to finish processing before generating Conversation Intelligence. If you make a request from the Conversations API while the job is processing, you might receive incomplete insights. You can find out if a job is still processing by passing the jobId in the Get job status request.

Authentication

Before using this API, you must generate your authentication token (AUTH_TOKEN) as described in Authentication.

Example API Endpoint

POST <https://api.symbl.ai/v1/process/audio>

Request header

Remember to include your Bearer token in the Authorization header to make the API request.

curl --location --request POST "https://api.symbl.ai/v1/process/audio \
--header 'Content-Type: audio/wav' \
--header "Authorization: Bearer $AUTH_TOKEN" \
--data-binary '@/file/location/audio.wav'
Header NameRequiredValue
AuthorizationRequiredBearer <token> The token you get during Authentication.
Content-TypeOptionalThis optional parameter describes the format and codec of the provided audio data. Accepted values are audio/wav, audio/mpeg, audio/mp3 and audio/wave only. If your audio is in a format other than these, do not use this field.

Response body

{
  "conversationId": "5006340993843200",
  "jobId": "f98171b5-0f24-4582-92bc-325c3fa9473b"
}

This Conversation ID is a unique identifier of the conversation you can pass in Get messages to receive sentiment analysis. For details, see step 2.

The job ID is the unique identifier of the job in progress. Use it to Get job status.

You must wait for processing to be complete before you can proceed to the next step. The time taken for the job to complete depends on the file size.

Step 2: Use conversationId in the Get messages request and pass sentiment=true

Pass the conversationId received in Step 1 using the Get messages. Also, ensure that you pass sentiment=true as a query parameter.

Example endpoint

​​GET <https://api.symbl.ai/v1/conversations/{conversationId}/messages?sentiment=true>

Request header

Remember to include your bearer token in the authorization header.

curl --location --request GET
"https://api.symbl.ai/v1/conversations/{conversationId}/messages?sentiment=true" \
--header 'Content-Type: audio/wav' \
--header "Authorization: Bearer $AUTH_TOKEN" \
--data-binary '@/file/location/audio.wav'
Header NameRequiredValue
AuthorizationRequiredBearer <token> The token you get during Authentication.
Content-TypeOptionalThis optional parameter describes the format and codec of the provided audio data. Accepted values are audio/wav, audio/mpeg, audio/mp3 and audio/wave only. If your audio is in a format other than these, do not use this field.

Response

{
 "messages":[
   {
     "id":"6131375637790720",
     "text":"Okay, so you're talking about that file, which I am sending you.",
     "from":{
      
     },
     "startTime":"2021-04-12T22:10:39.881Z",
     "endTime":"2021-04-12T22:10:43.981Z",
     "conversationId":"6320529160011776",
     "phrases":[
       {
         "type":"action_phrase",
         "text":"sending I you"
       }
     ],
     "sentiment":{
       "polarity":{
         "score":-0.201
       },
       "suggested":"neutral"
     }
   },
   {
     "id":"6605033355345920",
     "text":"Ah There is way I don't think there is way too now.",
     "from":{
      
     },
     "startTime":"2021-04-12T22:10:46.681Z",
     "endTime":"2021-04-12T22:10:53.281Z",
     "conversationId":"6320529160011776",
     "phrases":[
       {
         "type":"action_phrase",
         "text":"think there is way too now"
       }
     ],
     "sentiment":{
       "polarity":{
         "score":-0.201
       },
       "suggested":"neutral"
     }
   },
   ...
 ]

The body parameter is defined in the operation's parameters section and includes objects that describe the body data type and structure. For more information, see Speech-to-Text.

Polarity and Score

Sentiment Analysis is the interpretation of the general thought, feeling, or sense of an object or a situation. In the Response, you’ll notice the sentiment field which shows the sentiment type (positive, negative, and neutral). It is scored using “polarity” values which shows the intensity of the sentiment. It ranges from -1.0 to 1.0, where -1.0 is the most negative sentiment and 1.0 is the most positive sentiment.

Sample Code Snippet:

{
  "sentiment": {
    "polarity": {
      "score": 0.6
    }
  }
}

We have chosen the following polarity ranges for sentiment type, which covers a wide range of conversations.

Polarity sentiment may vary for your use case. We recommend that you define a threshold that works for you, and then adjust the threshold after testing and verifying the results.

PolaritySuggested Sentiment
-1.0 => x > -0.3negative
-0.3 => x <= 0.3neutral
0.3 < x <= 1.0positive