Analyze The Sentiment Of A Customer Call using LeMUR

In this guide, we’ll show you how to use AssemblyAI’s LeMUR (Leveraging Large Language Models to Understand Recognized Speech) framework to process an audio file and then use LeMUR’s Question & Answer feature to automatically detect sentiment analysis from customer calls as “positive”, “negative”, or “neutral”. In addition, we will glean additional insights beyond these three sentiments and learn the reasoning behind these detected sentiments.

Quickstart

1import assemblyai as aai
2
3aai.settings.api_key = "YOUR_API_KEY"
4
5transcriber = aai.Transcriber()
6transcript = transcriber.transcribe("./meeting.mp3") # You can also provide a URL to a publicly available audio file
7
8agent_context = "The agent is trying to get the customer to go through with the update to their car."
9customer_context = "The customer is calling to check how much it would cost to update the map in his car."
10
11answer_format = "<answer in one sentence> <reason in one sentence>"
12
13questions = [
14 aai.LemurQuestion(
15 question="What was the overall sentiment of the call?",
16 context=customer_context,
17 answer_format=answer_format,
18 ),
19 aai.LemurQuestion(
20 question="What was the sentiment of the agent in this call?",
21 context=agent_context,
22 answer_format=answer_format,
23 ),
24 aai.LemurQuestion(
25 question="What was the sentiment of the customer in this call?",
26 context=customer_context,
27 answer_format=answer_format,
28 ),
29 aai.LemurQuestion(
30 question="What quote best demonstrates the customer's level of interest?",
31 context=customer_context,
32 answer_format=answer_format,
33 ),
34 aai.LemurQuestion(
35 question="Provide a quote from the agent that demonstrates their level of enthusiasm.",
36 context=agent_context,
37 answer_format=answer_format,
38 ),
39]
40
41result = transcript.lemur.question(questions, final_model=aai.LemurModel.claude3_5_sonnet)
42
43for qa in result.response:
44 print(qa.question)
45 print(qa.answer)

Get Started

Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for an AssemblyAI account and get your API key from your dashboard.

LeMUR features are currently only available to paid users at two pricing tiers: LeMUR and LeMUR Basic. See pricing for more detail.

Step-by-Step Instructions

In this guide, we will ask five questions to learn about the sentiment of the customer and agent. You can adjust the questions to suit your project’s needs.

Import the assemblyai package and set your API key.

1import assemblyai as aai
2
3aai.settings.api_key = "your_api_key"

Use the Transcriber object’s transcribe method and pass in the audio file’s path as a parameter. The transcribe method will save the results of the transcription to the Transcriber object’s transcript attribute.

1transcriber = aai.Transcriber()
2transcript = transcriber.transcribe("./meeting.mp3")

Define your LeMUR request context parameters for the Question & Answer feature.

1agent_context = "The agent is trying to get the customer to go through with the update to their car."
2customer_context = "The customer is calling to check how much it would cost to update the map in his car."

Define your answer_format and questions parameters for the Question & Answer feature.

1answer_format = "<answer in one sentence> <reason in one sentence>"
2
3questions = [
4 aai.LemurQuestion(
5 question="What was the overall sentiment of the call?",
6 context=customer_context,
7 answer_format=answer_format,
8 ),
9 aai.LemurQuestion(
10 question="What was the sentiment of the agent in this call?",
11 context=agent_context,
12 answer_format=answer_format,
13 ),
14 aai.LemurQuestion(
15 question="What was the sentiment of the customer in this call?",
16 context=customer_context,
17 answer_format=answer_format,
18 ),
19 aai.LemurQuestion(
20 question="What quote best demonstrates the customer's level of interest?",
21 context=customer_context,
22 answer_format=answer_format,
23 ),
24 aai.LemurQuestion(
25 question="Provide a quote from the agent that demonstrates their level of enthusiasm.",
26 context=agent_context,
27 answer_format=answer_format,
28 ),
29]

Run the question method on transcript and print the result to your terminal.

1result = transcript.lemur.question(questions, final_model=aai.LemurModel.claude3_5_sonnet)
2
3for qa in result.response:
4 print(qa.question)
5 print(qa.answer)

The output will look similar to the example below.