# Sentiment Analysis

:::card{title="Deepgram API Playground" href="https://playground.deepgram.com/?endpoint=listen&sentiment=true&language=en&model=nova-3"}
Try this feature out in our API Playground.
:::

`sentiment` _boolean_ Default: `false`

Pre-recorded Streaming\:Nova English (all available regions)

Deepgram’s Sentiment Analysis feature recognizes the sentiment of the entire transcript and detects shifts in sentiment throughout the transcript.

A `sentiment` of `positive`, `negative`, or `neutral` along with a `sentiment_score` is identified for each segment of the transcript, and an `average` of the entire transcript’s sentiment is also provided along with the average `sentiment_score`.

This sentiment feature produces sentiment analysis at every level of transcription requested, so you’ll get sentiment values for every word, sentence, utterance, and paragraph, in addition to the top-level sentiment for the entire transcription.

:::callout{intent="info"}
The break point for a `sentiment_score` becoming positive or negative is `+-0.333333333...`.
:::

## Enable Feature

To enable Sentiment, use the following parameter in the query string when you call Deepgram’s `/listen` endpoint:

`sentiment=true`

To transcribe audio from a file on your computer, run the following curl command in a terminal or your favorite API client.

```bash
curl \
  --request POST \
  --header 'Authorization: Token YOUR_DEEPGRAM_API_KEY' \
  --header 'Content-Type: audio/wav' \
  --data-binary @youraudio.wav \
  --url 'https://api.deepgram.com/v1/listen?sentiment=true'
```

:::callout{intent="warning"}
Replace `YOUR_DEEPGRAM_API_KEY` with your [Deepgram API Key](https://console.deepgram.com/signup?jump=keys).
:::

### Query Parameters

| Parameter   | Values | Type    | Description                                                                |
| ----------- | ------ | ------- | -------------------------------------------------------------------------- |
| `sentiment` | `true` | boolean | Enables sentiment analysis                                                 |
| `language`  | `en`   | string  | The language of your input audio (Only English is supported at this time.) |

## Analyze Response

When the file is finished processing, you’ll receive a JSON response that has the following basic structure:

```json
"metadata": {...},
  "results": {
    "channels": [
      {
        "alternatives": [...]
      }
    ],
    "sentiments": {
      "segments": [
        {
          "text": "Hi there. I love my current phone, but want a new one.",
          "start_word": 0,
          "end_word": 11,
          "sentiment": "positive",
          "sentiment_score": 0.4443286657333374
        },
        {
          "text": "Can I upgrade my phone?",
          "start_word": 12,
          "end_word": 16,
          "sentiment": "neutral",
          "sentiment_score": 0.1317894160747528
        }
      ],
      "average": {
        "sentiment": "positive",
        "sentiment_score": 0.35909067500721326
      }
    }
  }
}
```

The `sentiment` values added to objects are:

- `sentiment`: The sentiment of the associated text (‘positive’ | ‘negative’ | ‘neutral’).
- `sentiment_score`: A floating point value between -1 and 1 representing the sentiment of the associated span of text. -1 being the most negative sentiment, and 1 being the most positive sentiment.

***

### Response Properties

| Property                                   | Description                                                                                                                                                                            |
| ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `channels.alternatives.words[i].sentiment` | The sentiment rating and score for the associated word.                                                                                                                                |
| `sentiments.segments`                      | Spans of text covering your entire transcript that show when the sentiment shifts throughout the transcribed audio.                                                                    |
| `sentiments.segments[i].sentiment`         | A rating for the given span of text. Can be either `positive`, `neutral`, or `negative`.                                                                                               |
| `sentiments.segments[i].sentiment_score`   | A floating point value between -1 and 1 representing the sentiment of the associated span of text, with -1 being the most negative sentiment, and 1 being the most positive sentiment. |
| `sentiments.average`                       | The average sentiment for the entire transcription.                                                                                                                                    |

### API Warning Response

#### Warning

If you request Sentiment Analysis with an unsupported language by specifying a language code such as `sentiment=true&language=es` or `sentiment=true&detect_language=true` where the detected language is unsupported, you will get the warning message below.

```json
"warnings": [
  {
    "parameter": "sentiment",
    "type": "unsupported_language",
    "message": "Sentiment is only supported for English."
  }
]
```

| Warning Name           | Warning Message                                                  |
| ---------------------- | ---------------------------------------------------------------- |
| `unsupported_language` | Feature isn’t supported with the specified or detected language. |

**Example Warning**

Here is an example of the JSON structure of a request with warning object.

```json
{
 "metadata": {
...
       },
     "warnings": [
       {
         "parameter": "sentiment",
         "type": "unsupported_language",
         "message": "Sentiment is only supported for English."
       }
     ]
   },
 "results": {
       "channels": [
            {
                "alternatives": [...]
            }
        ], 

    }
}
```

## Related pages

- [Feature Overview](./self-hosted-deployments-6-stt-intelligence-feature-overview.md)
- [Entity Detection](./self-hosted-deployments-6-detect-entities.md)
- [Intent Recognition](./self-hosted-deployments-6-intent-recognition.md)
- [Summarization](./self-hosted-deployments-6-summarization.md)
- [Topic Detection](./self-hosted-deployments-6-topic-detection.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
