Sentiment Analysis
Sentiment analysis, also known as sentiment detection, is the process of determining the emotional tone or attitude expressed in a piece of text. It can identify whether the sentiment is positive, negative, or neutral.
For a call transcript, sentiment analysis can be useful to find insights into customer satisfaction, analyse trends to make data-driven decisions and also to enhance training for customer service executives.
File Transcription Job with Sentiment Analysis
- API
- Python SDK
Copy and paste the below curl request on your terminal to start a transcription using the API. Fill the variables with the appropriate values, as mentioned in the overview.
curl --location 'https://voice.neuralspace.ai/api/v1/jobs' \
--header 'Authorization: {{API_KEY}}' \
--form 'files=@"{{LOCAL_AUDIO_FILE_PATH}}"' \
--form 'config="{\"file_transcription\":{\"language_id\":\"{{LANG}}\", \"mode\":\"{{MODE}}\"},
\"sentiment_detect\":true}"'
In the above request, sentiment_detect
is an extra configuration that is being passed. It also returns a response similar to the regular file transcription API as seen in overview.
{
"success": true,
"message": "Job created successfully",
"data": {
"jobId": "281f8662-cdc3-4c76-82d0-e7d14af52c46"
}
}
Once installation steps for the package are complete, execute the below mentioned python code snippet:
import neuralspace as ns
vai = ns.VoiceAI()
# or,
# vai = ns.VoiceAI(api_key='YOUR_API_KEY')
# Setup job configuration
config = {
"file_transcription": {
"language_id": "en",
"mode": "advanced",
},
"sentiment_detect": True
}
# Create a new file transcription job
job_id = vai.transcribe(file='path/to/audio.wav', config=config)
print(job_id)
Here, the sentiment_detect
config is in addition to those mentioned in the overview page. The response looks similar as well:
6abe4f35-8220-4981-95c7-3b040d9b86d1
Fetch Transcription and Sentiment Analysis Results
- API
- Python SDK
When you pass the jobId
(received in response to the transcription API) to the API below, it fetches the status and results of the job.
curl --location 'https://voice.neuralspace.ai/api/v1/jobs/{{jobId}}' \
--header 'Authorization: {{API_KEY}}'
Using the jobId
(received in response to the transcription API) the snippet below can be executed to fetch the status and results of the job.
result = vai.get_job_status(jobId)
print(result)
The response of the request above appears as follows:
{
...
"data": {
...
"result": {
...
"sentiment_detection": {
"overall": "neutral",
"segments": [
{
"startTime": 6.6909375,
"endTime": 10.302187500000002,
"text": "We've been at this for hours now. Have you found anything useful in any of those books?",
"speaker": "SPEAKER_02",
"sentiment": "negative"
},
{
"startTime": 10.690312500000001,
"endTime": 14.588437500000001,
"text": "Not a single thing, Lewis. I'm sure that there must be something in this library.",
"speaker": "SPEAKER_01",
"sentiment": "neutral"
},
{
"startTime": 14.740312500000002,
"endTime": 16.545937499999997,
"text": "It's not like there's nothing left to be discovered.",
"speaker": "SPEAKER_01",
"sentiment": "neutral"
},
{
"startTime": 17.2378125,
"endTime": 21.5071875,
"text": "Well, I have to say that I'm tired of searching. I'm gonna take a little break.",
"speaker": "SPEAKER_02",
"sentiment": "neutral"
}
]
}
}
}
}
In the response above, an overall sentiment is returned. Segment-wise sentiments, if speaker diarization is enabled, would be returned like above as well.
- If you have selected the speaker diarization feature while creating the job, you will also receive a segment-wise list of sentiments in addition to overall sentiment. This list of segments is unavailable when speaker diarization is not enabled, and only an overall sentiment for the whole audio file is returned.
Troubleshooting and FAQ
Negative? Check out our FAQ page. If you still need help, feel free to reach out to us directly at support@neuralspace.ai or join our Slack community.