Skip to content

Commit ce899c7

Browse files
s0h3ylAssemblyAI
andauthored
fix: add missing properties to Transcript class (#7)
Co-authored-by: AssemblyAI <[email protected]>
1 parent e08b1df commit ce899c7

File tree

12 files changed

+87
-52
lines changed

12 files changed

+87
-52
lines changed

assemblyai/__init__.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
from .transcriber import Transcriber, Transcript, TranscriptGroup
21
from .client import Client
32
from .lemur import Lemur
4-
3+
from .transcriber import Transcriber, Transcript, TranscriptGroup
54
from .types import (
65
AssemblyAIError,
7-
Settings,
8-
TranscriptError,
9-
TranscriptStatus,
10-
TranscriptionConfig,
11-
Utterance,
12-
UtteranceWord,
136
LanguageCode,
14-
Paragraph,
15-
Sentence,
16-
LemurModel,
177
LemurError,
8+
LemurModel,
189
LemurQuestion,
1910
LemurQuestionResult,
20-
SummarizationModel,
11+
Paragraph,
12+
PIIRedactionPolicy,
2113
PIISubstitutionPolicy,
2214
RawTranscriptionConfig,
15+
Sentence,
16+
Settings,
17+
SummarizationModel,
2318
SummarizationType,
19+
Timestamp,
20+
TranscriptError,
21+
TranscriptionConfig,
22+
TranscriptStatus,
23+
Utterance,
24+
UtteranceWord,
25+
Word,
2426
WordBoost,
2527
WordSearchMatch,
26-
Word,
27-
Timestamp,
28-
PIIRedactionPolicy,
2928
)
3029

31-
3230
settings = Settings()
3331
"""Global settings object that applies to all classes that use the `Client` class."""
3432

assemblyai/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from typing import Optional, List, BinaryIO
2-
3-
from . import types
1+
from typing import BinaryIO, List, Optional
42

53
import httpx
64

5+
from . import types
6+
77

88
def _get_error_message(response: httpx.Response) -> str:
99
"""

assemblyai/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import threading
2-
from typing import Optional, ClassVar
2+
from typing import ClassVar, Optional
3+
4+
import httpx
35
from typing_extensions import Self
46

57
from . import types
68

7-
import httpx
8-
99

1010
class Client:
1111
_default: ClassVar[Optional["Client"]] = None

assemblyai/lemur.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Optional, List, Union, Dict, Any
1+
from typing import Any, Dict, List, Optional, Union
22

3-
from . import api, types
3+
from . import api
44
from . import client as _client
5+
from . import types
56

67

78
class _LemurImpl:

assemblyai/transcriber.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from __future__ import annotations
2+
3+
import concurrent.futures
24
import os
35
import time
6+
from typing import Dict, Iterator, List, Optional, Union
47
from urllib.parse import urlparse
5-
import concurrent.futures
6-
from typing import Dict, Iterator, Optional, List, Union
8+
79
from typing_extensions import Self
810

9-
from . import lemur, types, api
11+
from . import api
1012
from . import client as _client
13+
from . import lemur, types
1114

1215

1316
class _TranscriptImpl:
@@ -213,6 +216,45 @@ def error(self) -> Optional[str]:
213216

214217
return self._impl.transcript.error
215218

219+
@property
220+
def words(self) -> Optional[List[types.Word]]:
221+
"The list of words in the transcript"
222+
223+
return self._impl.transcript.words
224+
225+
@property
226+
def utterances(self) -> Optional[List[types.Utterance]]:
227+
"""
228+
When `dual_channel` or `speaker_labels` is enabled,
229+
a list of utterances in the transcript.
230+
"""
231+
232+
return self._impl.transcript.utterances
233+
234+
@property
235+
def confidence(self) -> Optional[float]:
236+
"The confidence our model has in the transcribed text, between 0 and 1"
237+
238+
return self._impl.transcript.confidence
239+
240+
@property
241+
def audio_duration(self) -> Optional[float]:
242+
"The duration of the audio in seconds"
243+
244+
return self._impl.transcript.audio_duration
245+
246+
@property
247+
def webhook_status_code(self) -> Optional[int]:
248+
"The status code we received from your server when delivering your webhook"
249+
250+
return self._impl.transcript.webhook_status_code
251+
252+
@property
253+
def webhook_auth(self) -> Optional[bool]:
254+
"Whether the webhook was sent with an HTTP authentication header"
255+
256+
return self._impl.transcript.webhook_auth
257+
216258
@property
217259
def lemur(self) -> lemur.Lemur:
218260
"""

assemblyai/types.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from enum import Enum
2-
3-
from typing import Optional, Dict, Any, List, Tuple, Union, Sequence
4-
from typing_extensions import Self
2+
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
53

64
from pydantic import BaseModel, BaseSettings, Extra
5+
from typing_extensions import Self
76

87

98
class AssemblyAIError(Exception):
@@ -1271,7 +1270,7 @@ class BaseTranscript(BaseModel):
12711270
# iab_categories: bool = False
12721271
# "Enable Topic Detection."
12731272

1274-
custom_spelling: Optional[List[dict]]
1273+
custom_spelling: Optional[List[Dict[str, str]]]
12751274
"Customize how words are spelled and formatted using to and from values"
12761275

12771276
disfluencies: Optional[bool]
@@ -1347,7 +1346,7 @@ class TranscriptResponse(BaseTranscript):
13471346
audio_duration: Optional[float]
13481347
"The duration of your media file, in seconds"
13491348

1350-
webhook_status_code: Optional[str]
1349+
webhook_status_code: Optional[int]
13511350
"The status code we received from your server when delivering your webhook"
13521351
webhook_auth: Optional[bool]
13531352
"Whether the webhook was sent with an HTTP authentication header"

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from pathlib import Path
22

3-
from setuptools import setup, find_packages
3+
from setuptools import find_packages, setup
44

55
long_description = (Path(__file__).parent / "README.md").read_text()
66

77

88
setup(
99
name="assemblyai",
10-
version="0.4.0",
10+
version="0.4.1",
1111
description="AssemblyAI Python SDK",
1212
author="AssemblyAI",
1313
author_email="[email protected]",

tests/unit/factories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from functools import partial
7-
from typing import Any, Dict, Callable
7+
from typing import Any, Callable, Dict
88

99
import factory
1010
import factory.base

tests/unit/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import inspect
22

3-
import assemblyai as aai
4-
53
import pytest
64

5+
import assemblyai as aai
6+
77

88
def test_configuration_are_none_by_default():
99
"""

tests/unit/test_lemur.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import httpx
2-
from pytest_httpx import HTTPXMock
31
import uuid
42

3+
import httpx
4+
import pytest
5+
from pytest_httpx import HTTPXMock
56

67
import assemblyai as aai
78
from tests.unit import factories
89

9-
import pytest
10-
11-
1210
aai.settings.api_key = "test"
1311

1412

0 commit comments

Comments
 (0)