Skip to content

Commit f80076b

Browse files
committed
chore(lint): apply automatic linting fixes to examples
- Fix import ordering (ruff isort) - Remove trailing whitespace - Remove trailing blank lines - Format code according to project standards
1 parent e8f3e4b commit f80076b

20 files changed

+141
-179
lines changed

examples/01-authentication-api-key.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@
2020
# client = DeepgramClient(api_key="your-api-key-here")
2121

2222
print("Client initialized with API key")
23-

examples/02-authentication-access-token.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@
2525
# client = DeepgramClient()
2626

2727
print("Client initialized with access token")
28-

examples/04-transcription-prerecorded-url.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
url="https://dpgr.am/spacewalk.wav",
2020
model="nova-3",
2121
)
22-
22+
2323
print("Transcription received:")
2424
if response.results and response.results.channels:
2525
transcript = response.results.channels[0].alternatives[0].transcript
2626
print(transcript)
27-
27+
2828
# For async version:
2929
# from deepgram import AsyncDeepgramClient
3030
# client = AsyncDeepgramClient()
3131
# response = await client.listen.v1.media.transcribe_url(...)
32-
32+
3333
# With access token:
3434
# client = DeepgramClient(access_token="your-access-token")
35-
35+
3636
# With additional query parameters:
3737
# response = client.listen.v1.media.transcribe_url(
3838
# url="https://dpgr.am/spacewalk.wav",
@@ -43,7 +43,6 @@
4343
# }
4444
# }
4545
# )
46-
46+
4747
except Exception as e:
4848
print(f"Error: {e}")
49-

examples/05-transcription-prerecorded-file.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import os
8+
89
from dotenv import load_dotenv
910

1011
load_dotenv()
@@ -17,17 +18,17 @@
1718
# Path to audio file
1819
script_dir = os.path.dirname(os.path.abspath(__file__))
1920
audio_path = os.path.join(script_dir, "fixtures", "audio.wav")
20-
21+
2122
print(f"Reading audio file: {audio_path}")
2223
with open(audio_path, "rb") as audio_file:
2324
audio_data = audio_file.read()
24-
25+
2526
print("Sending transcription request...")
2627
response = client.listen.v1.media.transcribe_file(
2728
request=audio_data,
2829
model="nova-3",
2930
)
30-
31+
3132
# For large files, you can stream the file instead of loading it all into memory:
3233
# def read_file_in_chunks(file_path, chunk_size=8192):
3334
# with open(file_path, "rb") as f:
@@ -40,17 +41,16 @@
4041
# request=read_file_in_chunks(audio_path),
4142
# model="nova-3",
4243
# )
43-
44+
4445
print("Transcription received:")
4546
if response.results and response.results.channels:
4647
transcript = response.results.channels[0].alternatives[0].transcript
4748
print(transcript)
48-
49+
4950
# For async version:
5051
# from deepgram import AsyncDeepgramClient
5152
# client = AsyncDeepgramClient()
5253
# response = await client.listen.v1.media.transcribe_file(...)
53-
54+
5455
except Exception as e:
5556
print(f"Error: {e}")
56-

examples/06-transcription-prerecorded-callback.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
callback="https://your-callback-url.com/webhook",
2121
model="nova-3",
2222
)
23-
23+
2424
# This returns a "listen accepted" response, not the full transcription
2525
# The actual transcription will be sent to your callback URL
2626
print(f"Request accepted. Request ID: {response.request_id}")
2727
print("Transcription will be sent to your callback URL when ready.")
28-
28+
2929
# For async version:
3030
# from deepgram import AsyncDeepgramClient
3131
# client = AsyncDeepgramClient()
3232
# response = await client.listen.v1.media.transcribe_url(..., callback="...")
33-
33+
3434
except Exception as e:
3535
print(f"Error: {e}")
36-

examples/07-transcription-live-websocket.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
This example shows how to stream audio for real-time transcription using WebSocket.
55
"""
66

7-
import os
87
from typing import Union
98

109
from dotenv import load_dotenv
@@ -26,17 +25,18 @@
2625

2726
try:
2827
with client.listen.v1.connect(model="nova-3") as connection:
28+
2929
def on_message(message: ListenV1SocketClientResponse) -> None:
3030
msg_type = getattr(message, "type", "Unknown")
3131
print(f"Received {msg_type} event")
32-
32+
3333
# Extract transcription from Results events
3434
if isinstance(message, ListenV1Results):
3535
if message.channel and message.channel.alternatives:
3636
transcript = message.channel.alternatives[0].transcript
3737
if transcript:
3838
print(f"Transcript: {transcript}")
39-
39+
4040
connection.on(EventType.OPEN, lambda _: print("Connection opened"))
4141
connection.on(EventType.MESSAGE, on_message)
4242
connection.on(EventType.CLOSE, lambda _: print("Connection closed"))
@@ -48,15 +48,14 @@ def on_message(message: ListenV1SocketClientResponse) -> None:
4848
# with open(audio_path, "rb") as audio_file:
4949
# audio_data = audio_file.read()
5050
# connection.send_listen_v_1_media(audio_data)
51-
51+
5252
connection.start_listening()
53-
53+
5454
# For async version:
5555
# from deepgram import AsyncDeepgramClient
5656
# async with client.listen.v1.connect(model="nova-3") as connection:
5757
# # ... same event handlers ...
5858
# await connection.start_listening()
59-
59+
6060
except Exception as e:
6161
print(f"Error: {e}")
62-

examples/09-voice-agent.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
load_dotenv()
1212

1313
from deepgram import DeepgramClient
14-
from deepgram.core.events import EventType
1514
from deepgram.agent.v1.types import (
1615
AgentV1Agent,
1716
AgentV1AudioConfig,
@@ -24,6 +23,7 @@
2423
AgentV1SpeakProviderConfig,
2524
AgentV1Think,
2625
)
26+
from deepgram.core.events import EventType
2727

2828
AgentV1SocketClientResponse = Union[str, bytes]
2929

@@ -53,7 +53,7 @@
5353
model="gpt-4o-mini",
5454
temperature=0.7,
5555
),
56-
prompt='You are a helpful AI assistant.',
56+
prompt="You are a helpful AI assistant.",
5757
),
5858
speak=AgentV1SpeakProviderConfig(
5959
provider=AgentV1DeepgramSpeakProvider(
@@ -74,7 +74,7 @@ def on_message(message: AgentV1SocketClientResponse) -> None:
7474
else:
7575
msg_type = getattr(message, "type", "Unknown")
7676
print(f"Received {msg_type} event")
77-
77+
7878
agent.on(EventType.OPEN, lambda _: print("Connection opened"))
7979
agent.on(EventType.MESSAGE, on_message)
8080
agent.on(EventType.CLOSE, lambda _: print("Connection closed"))
@@ -85,16 +85,15 @@ def on_message(message: AgentV1SocketClientResponse) -> None:
8585
# with open("audio.wav", "rb") as audio_file:
8686
# audio_data = audio_file.read()
8787
# agent.send_agent_v_1_media(audio_data)
88-
88+
8989
agent.start_listening()
90-
90+
9191
# For async version:
9292
# from deepgram import AsyncDeepgramClient
9393
# async with client.agent.v1.connect() as agent:
9494
# # ... same configuration ...
9595
# await agent.send_agent_v_1_settings(settings)
9696
# await agent.start_listening()
97-
97+
9898
except Exception as e:
9999
print(f"Error: {e}")
100-

examples/11-text-to-speech-streaming.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212

1313
from deepgram import DeepgramClient
1414
from deepgram.core.events import EventType
15-
from deepgram.speak.v1.types import SpeakV1Text, SpeakV1Flush, SpeakV1Close
15+
from deepgram.speak.v1.types import SpeakV1Close, SpeakV1Flush, SpeakV1Text
1616

1717
SpeakV1SocketClientResponse = Union[str, bytes]
1818

1919
client = DeepgramClient()
2020

2121
try:
2222
with client.speak.v1.connect(model="aura-2-asteria-en", encoding="linear16", sample_rate=24000) as connection:
23+
2324
def on_message(message: SpeakV1SocketClientResponse) -> None:
2425
if isinstance(message, bytes):
2526
print("Received audio data")
@@ -29,7 +30,7 @@ def on_message(message: SpeakV1SocketClientResponse) -> None:
2930
else:
3031
msg_type = getattr(message, "type", "Unknown")
3132
print(f"Received {msg_type} event")
32-
33+
3334
connection.on(EventType.OPEN, lambda _: print("Connection opened"))
3435
connection.on(EventType.MESSAGE, on_message)
3536
connection.on(EventType.CLOSE, lambda _: print("Connection closed"))
@@ -40,19 +41,19 @@ def on_message(message: SpeakV1SocketClientResponse) -> None:
4041
# For better control with bidirectional communication, use the async version
4142
text_message = SpeakV1Text(text="Hello, this is a text to speech example.")
4243
connection.send_speak_v_1_text(text_message)
43-
44+
4445
# Flush to ensure all text is processed
4546
flush_message = SpeakV1Flush()
4647
connection.send_speak_v_1_flush(flush_message)
47-
48+
4849
# Close the connection when done
4950
close_message = SpeakV1Close()
5051
connection.send_speak_v_1_close(close_message)
51-
52+
5253
# Start listening - this blocks until the connection closes
5354
# All messages should be sent before calling this in sync mode
5455
connection.start_listening()
55-
56+
5657
# For async version:
5758
# from deepgram import AsyncDeepgramClient
5859
# async with client.speak.v1.connect(...) as connection:
@@ -61,7 +62,6 @@ def on_message(message: SpeakV1SocketClientResponse) -> None:
6162
# await connection.send_speak_v_1_flush(SpeakV1Flush())
6263
# await connection.send_speak_v_1_close(SpeakV1Close())
6364
# await listen_task
64-
65+
6566
except Exception as e:
6667
print(f"Error: {e}")
67-

examples/12-text-intelligence.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
topics=True,
2323
intents=True,
2424
)
25-
25+
2626
print("Analysis received:")
2727
print(f"Sentiment: {response.sentiment}")
2828
if response.summary:
@@ -31,12 +31,11 @@
3131
print(f"Topics: {response.topics}")
3232
if response.intents:
3333
print(f"Intents: {response.intents}")
34-
34+
3535
# For async version:
3636
# from deepgram import AsyncDeepgramClient
3737
# client = AsyncDeepgramClient()
3838
# response = await client.read.v1.text.analyze(...)
39-
39+
4040
except Exception as e:
4141
print(f"Error: {e}")
42-

examples/13-management-projects.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,32 @@
1717
print("Listing all projects...")
1818
projects = client.manage.v1.projects.list()
1919
print(f"Found {len(projects.projects)} projects")
20-
20+
2121
if projects.projects:
2222
project_id = projects.projects[0].project_id
2323
print(f"Using project: {project_id}")
24-
24+
2525
# Get a specific project
26-
print(f"\nGetting project details...")
26+
print("\nGetting project details...")
2727
project = client.manage.v1.projects.get(project_id=project_id)
2828
print(f"Project name: {project.name}")
29-
29+
3030
# Update project name
31-
print(f"\nUpdating project name...")
32-
updated = client.manage.v1.projects.update(
33-
project_id=project_id,
34-
name="Updated Project Name"
35-
)
31+
print("\nUpdating project name...")
32+
updated = client.manage.v1.projects.update(project_id=project_id, name="Updated Project Name")
3633
print(f"Updated project name: {updated.name}")
37-
34+
3835
# Note: Delete and leave operations are commented out for safety
3936
# Delete a project:
4037
# client.manage.v1.projects.delete(project_id=project_id)
41-
38+
4239
# Leave a project:
4340
# client.manage.v1.projects.leave(project_id=project_id)
44-
41+
4542
# For async version:
4643
# from deepgram import AsyncDeepgramClient
4744
# client = AsyncDeepgramClient()
4845
# projects = await client.manage.v1.projects.list()
49-
46+
5047
except Exception as e:
5148
print(f"Error: {e}")
52-

0 commit comments

Comments
 (0)