Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 128 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ aai.settings.api_key = f"{ASSEMBLYAI_API_KEY}"
### **Core Examples**

<details>
<summary>Transcribe a Local Audio File</summary>
<summary>Transcribe a local audio file</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -116,7 +116,7 @@ transcript = transcriber.transcribe(upload_url)
</details>

<details>
<summary>Export Subtitles of an Audio File</summary>
<summary>Export subtitles of an audio file</summary>

```python
import assemblyai as aai
Expand All @@ -134,7 +134,7 @@ print(transcript.export_subtitles_vtt())
</details>

<details>
<summary>List all Sentences and Paragraphs</summary>
<summary>List all sentences and paragraphs</summary>

```python
import assemblyai as aai
Expand All @@ -154,7 +154,7 @@ for paragraph in paragraphs:
</details>

<details>
<summary>Search for Words in a Transcript</summary>
<summary>Search for words in a transcript</summary>

```python
import assemblyai as aai
Expand All @@ -171,7 +171,7 @@ for match in matches:
</details>

<details>
<summary>Add Custom Spellings on a Transcript</summary>
<summary>Add custom spellings on a transcript</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -265,96 +265,91 @@ while page.page_details.before_id_of_prev_url is not None:
### **LeMUR Examples**

<details>
<summary>Use LeMUR to Summarize Multiple Transcripts</summary>
<summary>Use LeMUR to summarize an audio file</summary>

```python
import assemblyai as aai

audio_file = "https://assembly.ai/sports_injuries.mp3"

transcriber = aai.Transcriber()
transcript_group = transcriber.transcribe_group(
[
"https://example.org/customer1.mp3",
"https://example.org/customer2.mp3",
],
)
transcript = transcriber.transcribe(audio_file)

result = transcript_group.lemur.summarize(
context="Customers asking for cars",
answer_format="TLDR"
prompt = "Provide a brief summary of the transcript."

result = transcript.lemur.task(
prompt, final_model=aai.LemurModel.claude3_5_sonnet
)

print(result.response)
```

</details>

<details>
<summary>Use LeMUR to Ask Questions on a Single Transcript</summary>
Or use the specialized Summarization endpoint that requires no prompt engineering and facilitates more deterministic and structured outputs:

```python
import assemblyai as aai

transcriber = aai.Transcriber()
transcript = transcriber.transcribe("https://example.org/customer.mp3")

# ask some questions
questions = [
aai.LemurQuestion(question="What car was the customer interested in?"),
aai.LemurQuestion(question="What price range is the customer looking for?"),
]
audio_url = "https://assembly.ai/meeting.mp4"
transcript = aai.Transcriber().transcribe(audio_url)

result = transcript.lemur.question(questions)
result = transcript.lemur.summarize(
final_model=aai.LemurModel.claude3_5_sonnet,
context="A GitLab meeting to discuss logistics",
answer_format="TLDR"
)

for q in result.response:
print(f"Question: {q.question}")
print(f"Answer: {q.answer}")
print(result.response)
```

</details>

<details>
<summary>Use LeMUR to Ask for Action Items from a Single Transcript</summary>
<summary>Use LeMUR to ask questions about your audio data</summary>

```python
import assemblyai as aai

audio_file = "https://assembly.ai/sports_injuries.mp3"

transcriber = aai.Transcriber()
transcript = transcriber.transcribe("https://example.org/customer.mp3")
transcript = transcriber.transcribe(audio_file)

result = transcript.lemur.action_items(
context="Customers asking for help with resolving their problem",
answer_format="Three bullet points",
prompt = "What is a runner's knee?"

result = transcript.lemur.task(
prompt, final_model=aai.LemurModel.claude3_5_sonnet
)

print(result.response)
```


</details>

<details>
<summary>Use LeMUR to Ask Anything with a Custom Prompt</summary>
Or use the specialized Q&A endpoint that requires no prompt engineering and facilitates more deterministic and structured outputs:

```python
import assemblyai as aai

transcriber = aai.Transcriber()
transcript = transcriber.transcribe("https://example.org/customer.mp3")

result = transcript.lemur.task(
"You are a helpful coach. Provide an analysis of the transcript "
"and offer areas to improve with exact quotes. Include no preamble. "
"Start with an overall summary then get into the examples with feedback.",
)
# ask some questions
questions = [
aai.LemurQuestion(question="What car was the customer interested in?"),
aai.LemurQuestion(question="What price range is the customer looking for?"),
]

print(result.response)
result = transcript.lemur.question(
final_model=aai.LemurModel.claude3_5_sonnet,
questions=questions)

for q in result.response:
print(f"Question: {q.question}")
print(f"Answer: {q.answer}")
```

</details>


<details>
<summary>Use LeMUR to with Input Text</summary>
<summary>Use LeMUR with customized input text</summary>

```python
import assemblyai as aai
Expand All @@ -375,7 +370,32 @@ result = aai.Lemur().task(
"You are a helpful coach. Provide an analysis of the transcript "
"and offer areas to improve with exact quotes. Include no preamble. "
"Start with an overall summary then get into the examples with feedback.",
input_text=text
input_text=text,
final_model=aai.LemurModel.claude3_5_sonnet
)

print(result.response)
```

</details>

<details>
<summary>Apply LeMUR to multiple transcripts</summary>

```python
import assemblyai as aai

transcriber = aai.Transcriber()
transcript_group = transcriber.transcribe_group(
[
"https://example.org/customer1.mp3",
"https://example.org/customer2.mp3",
],
)

result = transcript_group.lemur.task(
context="These are calls of customers asking for cars. Summarize all calls and create a TLDR.",
final_model=aai.LemurModel.claude3_5_sonnet
)

print(result.response)
Expand Down Expand Up @@ -417,7 +437,7 @@ print(deletion_result)
### **Audio Intelligence Examples**

<details>
<summary>PII Redact a Transcript</summary>
<summary>PII Redact a transcript</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -514,7 +534,7 @@ config=aai.TranscriptionConfig(

</details>
<details>
<summary>Detect Sensitive Content in a Transcript</summary>
<summary>Detect sensitive content in a transcript</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -562,7 +582,7 @@ config=aai.TranscriptionConfig(

</details>
<details>
<summary>Analyze the Sentiment of Sentences in a Transcript</summary>
<summary>Analyze the sentiment of sentences in a transcript</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -597,7 +617,7 @@ for sentiment_result in transcript.sentiment_analysis:

</details>
<details>
<summary>Identify Entities in a Transcript</summary>
<summary>Identify entities in a transcript</summary>

```python
import assemblyai as aai
Expand All @@ -618,7 +638,7 @@ for entity in transcript.entities:

</details>
<details>
<summary>Detect Topics in a Transcript (IAB Classification)</summary>
<summary>Detect topics in a transcript (IAB Classification)</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -646,7 +666,7 @@ for label, relevance in transcript.iab_categories.summary.items():

</details>
<details>
<summary>Identify Important Words and Phrases in a Transcript</summary>
<summary>Identify important words and phrases in a transcript</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -677,7 +697,7 @@ for result in transcript.auto_highlights.results:
[Read more about our Real-Time service.](https://www.assemblyai.com/docs/Guides/real-time_streaming_transcription)

<details>
<summary>Stream your Microphone in Real-Time</summary>
<summary>Stream your microphone in real-time</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -733,7 +753,7 @@ transcriber.close()
</details>

<details>
<summary>Transcribe a Local Audio File in Real-Time</summary>
<summary>Transcribe a local audio file in real-time</summary>

```python
import assemblyai as aai
Expand Down Expand Up @@ -835,12 +855,32 @@ transcriber = aai.RealtimeTranscriber(

---

## Playgrounds
### **Change the default settings**

Visit one of our Playgrounds:
You'll find the `Settings` class with all default values in [types.py](./assemblyai/types.py).

- [LeMUR Playground](https://www.assemblyai.com/playground/v2/source)
- [Transcription Playground](https://www.assemblyai.com/playground)
<details>
<summary>Change the default timeout and polling interval</summary>

```python
import assemblyai as aai

# The HTTP timeout in seconds for general requests, default is 30.0
aai.settings.http_timeout = 60.0

# The polling interval in seconds for long-running requests, default is 3.0
aai.settings.polling_interval = 10.0
```

</details>

---

## Playground

Visit our Playground to try our all of our Speech AI models and LeMUR for free:

- [Playground](https://www.assemblyai.com/playground)

# Advanced

Expand Down Expand Up @@ -897,6 +937,32 @@ The asynchronous approach allows the application to continue running while the t

You can identify those two approaches by the `_async` suffix in the `Transcriber`'s method name (e.g. `transcribe` vs `transcribe_async`).

## Getting the HTTP status code

There are two ways of accessing the HTTP status code:

- All custom AssemblyAI Error classes have a `status_code` attribute.
- The latest HTTP response is stored in `aai.Client.get_default().latest_response` after every API call. This approach works also if no Exception is thrown.

```python
transcriber = aai.Transcriber()

# Option 1: Catch the error
try:
transcript = transcriber.submit("./example.mp3")
except aai.AssemblyAIError as e:
print(e.status_code)

# Option 2: Access the latest response through the client
client = aai.Client.get_default()

try:
transcript = transcriber.submit("./example.mp3")
except:
print(client.last_response)
print(client.last_response.status_code)
```

## Polling Intervals

By default we poll the `Transcript`'s status each `3s`. In case you would like to adjust that interval:
Expand Down
2 changes: 1 addition & 1 deletion assemblyai/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.35.1"
__version__ = "0.36.0"
Loading
Loading