The sentiment and emotion analysis model analyzes the transcript, detecting the general sentiment which is conveyed in each sentence (positive, neutral or negative) as well as any emotion that is being expressed.
Usage
To enable sentiment and emotion analysis, set the "sentiment_analysis"
parameter to true
{
"audio_url" : "<your audio url>"
"sentiment_analysis" : true
}
async function makeFetchRequest ( url : string , options : any ) {
const response = await fetch ( url , options );
return response . json ();
}
async function pollForResult ( resultUrl : string , headers : any ) {
while ( true ) {
console . log ( "Polling for results..." );
const pollResponse = await makeFetchRequest ( resultUrl , { headers });
if ( pollResponse . status === "done" ) {
console . log ( "- Transcription done: \n " );
const audioToLlmResults = pollResponse . result . sentiment_analysis ;
console . log ( audioToLlmResults );
break ;
} else {
console . log ( "Transcription status : " , pollResponse . status );
await new Promise (( resolve ) => setTimeout ( resolve , 1000 ));
}
}
}
async function startTranscription () {
const gladiaKey = "YOUR_GLADIA_API_KEY" ;
const requestData = {
audio_url: "YOUR_AUDIO_URL" ,
sentiment_analysis: true
};
const gladiaUrl = "https://api.gladia.io/v2/pre-recorded/" ;
const headers = {
"x-gladia-key" : gladiaKey ,
"Content-Type" : "application/json" ,
};
console . log ( "- Sending initial request to Gladia API..." );
const initialResponse = await makeFetchRequest ( gladiaUrl , {
method: "POST" ,
headers ,
body: JSON . stringify ( requestData ),
});
console . log ( "Initial response with Transcription ID :" , initialResponse );
if ( initialResponse . result_url ) {
await pollForResult ( initialResponse . result_url , headers );
}
}
startTranscription ();
Result
Your transcription result will contain a sentiment_analysis
key which will contain an array of all sentences in the audio, and for each one the conveyed sentiment and expressed emotion. See possible values below.
When diarization
is enabled, the sentiment analysis output will contain the speaker
as well, allowing you to analyze each speaker separately.
{
"transcription" :{ ... },
"sentiment_analysis" : {
"success" : true ,
"is_empty" : false ,
"results" : [
{
"text" : "Jonathan, it says you are trained in technology." ,
"sentiment" : "neutral" ,
"emotion" : "neutral" ,
"start" : 0.45158000000000004 ,
"end" : 2.364 ,
"channel" : 0 ,
"speaker" : 0 ,
},
{
"text" : "That's very good." ,
"sentiment" : "positive" ,
"emotion" : "positive_surprise" ,
"start" : 2.54438 ,
"end" : 3.5432300000000003 ,
"channel" : 0 ,
"speaker" : 0 ,
}
],
"exec_time" : 1.127103805541992 ,
"error" : null
}
}
Possible values
Sentiments
positive
negative
neutral
mixed
unknown
Emotions
adoration
amusement
anger
awe
confusion
contempt
contentment
desire
disappointment
disgust
distress
ecstatic
elation
embarrassment
fear
interest
pain
realization
relief
sadness
negative_surprise
positive_surprise
sympathy
triumph
neutral