-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtypes.py
2339 lines (1714 loc) · 73.1 KB
/
types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from datetime import datetime
from enum import Enum, EnumMeta
from typing import (
TYPE_CHECKING,
Annotated,
Any,
Dict,
List,
Optional,
Sequence,
Tuple,
Union,
)
from urllib.parse import parse_qs, urlparse
from warnings import warn
if TYPE_CHECKING:
from .transcriber import Transcript
try:
# pydantic v2 import
from pydantic import UUID4, BaseModel, ConfigDict, Field
from pydantic_settings import BaseSettings, SettingsConfigDict
pydantic_v2 = True
except ImportError:
# pydantic v1 import
from pydantic.v1 import UUID4, BaseModel, BaseSettings, ConfigDict, Field
pydantic_v2 = False
from typing_extensions import Self
class AssemblyAIError(Exception):
"""
Base exception for all AssemblyAI errors
"""
def __init__(self, message: str, status_code: Optional[int] = None):
super().__init__(message)
self.status_code = status_code
class TranscriptError(AssemblyAIError):
"""
Error class when a transcription fails
"""
class RedactedAudioIncompleteError(AssemblyAIError):
"""
Error class when a PII-redacted audio URL is requested
before the file has finished processing
"""
class RedactedAudioExpiredError(AssemblyAIError):
"""
Error class when a PII-redacted audio URL is requested
but the file has expired and is no longer available
"""
class RedactedAudioUnavailableError(AssemblyAIError):
"""
Error class when a PII-redacted audio file is requested
but it is not available at the given URL
"""
class LemurError(AssemblyAIError):
"""
Error class when a Lemur request fails
"""
class Sourcable:
"""
A base class for all sourcable objects
Currently, only `Transcript` is sourcable
"""
class Settings(BaseSettings):
"""
Settings for the AssemblyAI client
"""
api_key: Optional[str] = None
"The API key to authenticate with"
http_timeout: float = 30.0
"The default HTTP timeout for general requests"
base_url: str = "https://api.assemblyai.com"
"The base URL for the AssemblyAI API"
polling_interval: float = Field(default=3.0, gt=0.0)
"The default polling interval for long-running requests (e.g. polling the `Transcript`'s status)"
if pydantic_v2:
model_config = SettingsConfigDict(env_prefix="assemblyai_")
else:
class Config:
env_prefix = "assemblyai_"
class TranscriptStatus(str, Enum):
"""
Transcript status
"""
queued = "queued"
processing = "processing"
completed = "completed"
error = "error"
class DeprecatedLanguageCodeMeta(EnumMeta):
def __getattribute__(self, item):
# Deprecate all 20 possible values
languages = [
"de",
"en",
"en_au",
"en_uk",
"en_us",
"es",
"fi",
"fr",
"hi",
"it",
"ja",
"ko",
"nl",
"pl",
"pt",
"ru",
"tr",
"uk",
"vi",
"zh",
]
if item in languages:
warn(
"LanuageCode Enum is deprecated and will be removed in 1.0.0. Use a string instead.",
DeprecationWarning,
stacklevel=2,
)
return EnumMeta.__getattribute__(self, item)
class LanguageCode(str, Enum, metaclass=DeprecatedLanguageCodeMeta):
"""
DeprecationWarning: LanuageCode is deprecated and will be removed in 1.0.0. Use a string instead.
Supported languages for transcribing audio.
"""
de = "de"
"German"
en = "en"
"Global English"
en_au = "en_au"
"Australian English"
en_uk = "en_uk"
"British English"
en_us = "en_us"
"English (US)"
es = "es"
"Spanish"
fi = "fi"
"Finnish"
fr = "fr"
"French"
hi = "hi"
"Hindi"
it = "it"
"Italian"
ja = "ja"
"Japanese"
ko = "ko"
"Korean"
nl = "nl"
"Dutch"
pl = "pl"
"Polish"
pt = "pt"
"Portuguese"
ru = "ru"
"Russian"
tr = "tr"
"Turkish"
uk = "uk"
"Ukrainian"
vi = "vi"
"Vietnamese"
zh = "zh"
"Chinese"
class WordBoost(str, Enum):
low = "low"
default = "default"
high = "high"
class PIIRedactedAudioQuality(str, Enum):
mp3 = "mp3"
wav = "wav"
class EntityType(str, Enum):
"""
Used for AssemblyAI's Entity Detection feature.
See: https://www.assemblyai.com/docs/audio-intelligence/entity-detection
"""
account_number = "account_number"
"Customer account or membership identification number (e.g., Policy No. 10042992; Member ID: HZ-5235-001)"
banking_information = "banking_information"
"Banking information, including account and routing numbers (e.g., Acct. No.: 012345-67)"
blood_type = "blood_type"
"Blood type (e.g., O-, AB positive)"
credit_card_cvv = "credit_card_cvv"
"Credit card verification code (e.g., CVV: 080)"
credit_card_expiration = "credit_card_expiration"
"Expiration date of a credit card (e.g., Expires: July 2023; Exp: 02/28)"
credit_card_number = "credit_card_number"
"Credit card number (e.g., 0123 0123 0123 0123)"
date = "date"
"Specific calendar date (e.g., December 18)"
date_interval = "date_interval"
"Broader time periods, including date ranges, months, seasons, years, and decades (e.g., 2020-2021; 5-9 May; January 1984 )"
date_of_birth = "date_of_birth"
"Date of Birth (e.g., Date of Birth: March 7,1961)"
drivers_license = "drivers_license"
"Driver's license number (e.g., DL# 356933-540)"
drug = "drug"
"Medications, vitamins, or supplements (e.g., Advil, Acetaminophen, Panadol)"
duration = "duration"
"Periods of time, specified as a number and a unit of time (e.g., 8 months; 2 years)"
email_address = "email_address"
"Email address (e.g., [email protected])"
event = "event"
"Name of an event or holiday (e.g., Olympics, Yom Kippur)"
filename = "filename"
"Names of computer files, including the extension or filepath (e.g., Taxes/2012/brad-tax-returns.pdf)"
gender_sexuality = "gender_sexuality"
"Terms indicating gender identity or sexual orientation, including slang terms (e.g., female; bisexual; trans)"
healthcare_number = "healthcare_number"
"Healthcare numbers and health plan beneficiary numbers (e.g., Policy No.: 5584-486-674-YM)"
injury = "injury"
"Bodily injury (e.g., I broke my arm, I have a sprained wrist)"
ip_address = "ip_address"
"Internet IP address, including IPv4 and IPv6 formats (e.g., 192.168.0.1)"
language = "language"
"Name of a natural language (e.g., Spanish, French)"
location = "location"
"Any Location reference including mailing address, postal code, city, state, province, country, or coordinates (e.g., Lake Victoria, 145 Windsor St., 90210)"
marital_status = "marital_status"
"Terms indicating marital status (e.g., Single, common-law, ex-wife, married)"
medical_condition = "medical_condition"
"Name of a medical condition, disease, syndrome, deficit, or disorder (e.g., chronic fatigue syndrome, arrhythmia, depression)"
medical_process = "medical_process"
"Medical process, including treatments, procedures, and tests (e.g., heart surgery, CT scan)"
money_amount = "money_amount"
"Name and/or amount of currency (e.g., 15 pesos, $94.50)"
nationality = "nationality"
"Terms indicating nationality, ethnicity, or race (e.g., American, Asian, Caucasian)"
number_sequence = "number_sequence"
"Numerical PII (including alphanumeric strings) that doesn't fall under other categories"
occupation = "occupation"
"Job title or profession (e.g., professor, actors, engineer, CPA)"
organization = "organization"
"Name of an organization (e.g., CNN, McDonalds, University of Alaska, Northwest General Hospital)"
passport_number = "passport_number"
"Passport numbers, issued by any country (e.g., PA4568332; NU3C6L86S12)"
password = "password"
"Account passwords, PINs, access keys, or verification answers (e.g., 27%alfalfa, temp1234, My mother's maiden name is Smith)"
person_age = "person_age"
"Number associated with an age (e.g., 27, 75)"
person_name = "person_name"
"Name of a person (e.g., Bob, Doug Jones, Dr. Kay Martinez, MD)"
phone_number = "phone_number"
"Telephone or fax number (e.g., +4917643476050)"
physical_attribute = "physical_attribute"
"Distinctive bodily attributes, including terms indicating race (e.g., I'm 190cm tall, He has black hair)"
political_affiliation = "political_affiliation"
"Terms referring to a political party, movement, or ideology (e.g., Republican, Liberal)"
religion = "religion"
"Terms indicating religious affiliation (e.g., Hindu, Catholic)"
statistics = "statistics"
"Medical statistics (e.g., 18%, 18 percent)"
time = "time"
"Expressions indicating clock times (e.g., 19:37:28, 10pm EST)"
url = "url"
"Internet addresses (e.g., www.assemblyai.com)"
us_social_security_number = "us_social_security_number"
"Social Security Number or equivalent (e.g., 078-05-1120, ***-***-3256)"
username = "username"
"Usernames, login names, or handles (e.g., @AssemblyAI)"
vehicle_id = "vehicle_id"
"Vehicle identification numbers (VINs), vehicle serial numbers, and license plate numbers (e.g., 5FNRL38918B111818, BIF7547)"
zodiac_sign = "zodiac_sign"
"Names of Zodiac signs (e.g., Aries, Taurus)"
# EntityType and PIIRedactionPolicy share the same values
PIIRedactionPolicy = EntityType
"""
Used for AssemblyAI's PII Redaction feature.
See: https://www.assemblyai.com/docs/audio-intelligence/pii-redaction
"""
class PIISubstitutionPolicy(str, Enum):
"""
Used for AssemblyAI's PII Redaction feature.
See: https://www.assemblyai.com/docs/audio-intelligence/pii-redaction
"""
hash = "hash"
"PII that is detected is replaced with a hash - #. For example, I'm calling for John is replaced with ####. (Applied by default)"
entity_name = "entity_name"
"PII that is detected is replaced with the associated policy name. For example, John is replaced with [PERSON_NAME]. This is recommended for readability."
class SummarizationModel(str, Enum):
"""
Used for AssemblyAI's Summarization feature.
See: https://www.assemblyai.com/docs/audio-intelligence/summarization
"""
informative = "informative"
"""
Best for files with a single speaker such as presentations or lectures.
Supported Summarization Types:
- `bullets`
- `bullets_verbose`
- `headline`
- `paragraph`
Required Parameters:
- `punctuate`: `True`
- `format_text`: `True`
"""
conversational = "conversational"
"""
Best for any 2 person conversation such as customer/agent or interview/interviewee calls.
Supported Summarization Types:
- `bullets`
- `bullets_verbose`
- `headline`
- `paragraph`
Required Parameters:
- `punctuate`: `True`
- `format_text`: `True`
- `speaker_labels` or `dual_channel` set to `True`
"""
catchy = "catchy"
"""
Best for creating video, podcast, or media titles.
Supported Summarization Types:
- `headline`
- `gist`
Required Parameters:
- `punctuate`: `True`
- `format_text`: `True`
"""
class SummarizationType(str, Enum):
"""
Used for AssemblyAI's Summarization feature.
See: https://www.assemblyai.com/docs/audio-intelligence/summarization
"""
bullets = "bullets"
"A bulleted summary with the most important points."
bullets_verbose = "bullets_verbose"
"A longer bullet point list summarizing the entire transcription text."
gist = "gist"
"A few words summarizing the entire transcription text."
headline = "headline"
"A single sentence summarizing the entire transcription text."
paragraph = "paragraph"
"A single paragraph summarizing the entire transcription text."
class SpeechModel(str, Enum):
"""
Used for AssemblyAI's Speech Model feature.
"""
best = "best"
"The best model optimized for accuracy."
nano = "nano"
"A lightweight, lower cost model for a wide range of languages."
slam_1 = "slam-1"
"A Speech Language Model optimized explicitly for speech-to-text tasks"
class RawTranscriptionConfig(BaseModel):
language_code: Optional[Union[str, LanguageCode]] = None
"""
The language of your audio file. Possible values are found in Supported Languages.
The default value is "en_us".
"""
punctuate: Optional[bool] = None
"Enable Automatic Punctuation"
format_text: Optional[bool] = None
"Enable Text Formatting"
dual_channel: Optional[bool] = None
"Enable Dual Channel transcription"
multichannel: Optional[bool] = None
"Enable Multichannel transcription"
webhook_url: Optional[str] = None
"The URL we should send webhooks to when your transcript is complete."
webhook_auth_header_name: Optional[str] = None
"The name of the header that is sent when the `webhook_url` is being called."
webhook_auth_header_value: Optional[str] = None
"The value of the `webhook_auth_header_name` that is sent when the `webhook_url` is being called."
audio_start_from: Optional[int] = None
"The point in time, in milliseconds, to begin transcription from in your media file."
audio_end_at: Optional[int] = None
"The point in time, in milliseconds, to stop transcribing in your media file."
word_boost: Optional[List[str]] = None
"A list of custom vocabulary to boost accuracy for."
boost_param: Optional[WordBoost] = None
"The weight to apply to words/phrases in the word_boost array."
filter_profanity: Optional[bool] = None
"Filter profanity from the transcribed text."
redact_pii: Optional[bool] = None
"Redact PII from the transcribed text."
redact_pii_audio: Optional[bool] = None
"Generate a copy of the original media file with spoken PII 'beeped' out."
redact_pii_audio_quality: Optional[PIIRedactedAudioQuality] = None
"The quality of the redacted audio file in case `redact_pii_audio` is enabled."
redact_pii_policies: Optional[List[PIIRedactionPolicy]] = None
"The list of PII Redaction policies to enable."
redact_pii_sub: Optional[PIISubstitutionPolicy] = None
"The replacement logic for detected PII."
speaker_labels: Optional[bool] = None
"Enable Speaker Diarization."
speakers_expected: Optional[int] = None
"The number of speakers you expect to be in your audio file."
content_safety: Optional[bool] = None
"Enable Content Safety Detection."
content_safety_confidence: Optional[int] = None
"The minimum confidence level for a content safety label to be produced."
iab_categories: Optional[bool] = None
"Enable Topic Detection."
custom_spelling: Optional[List[Dict[str, Union[str, List[str]]]]] = None
"Customize how words are spelled and formatted using to and from values."
disfluencies: Optional[bool] = None
"Transcribe Filler Words, like 'umm', in your media file."
sentiment_analysis: Optional[bool] = None
"Enable Sentiment Analysis."
auto_chapters: Optional[bool] = None
"Enable Auto Chapters."
entity_detection: Optional[bool] = None
"Enable Entity Detection."
summarization: Optional[bool] = None
"Enable Summarization"
summary_model: Optional[SummarizationModel] = None
"The summarization model to use in case `summarization` is enabled"
summary_type: Optional[SummarizationType] = None
"The summarization type to use in case `summarization` is enabled"
auto_highlights: Optional[bool] = None
"Detect important phrases and words in your transcription text."
language_detection: Optional[bool] = None
"""
Identify the dominant language that's spoken in an audio file, and route the file to the appropriate model for the detected language.
See the docs for supported languages: https://www.assemblyai.com/docs/getting-started/supported-languages
"""
language_confidence_threshold: Optional[float] = None
"""
The confidence threshold that must be reached if `language_detection` is enabled. An error will be returned
if the language confidence is below this threshold. Valid values are in the range [0,1] inclusive.
"""
speech_threshold: Optional[float] = None
"Reject audio files that contain less than this fraction of speech. Valid values are in the range [0,1] inclusive."
speech_model: Optional[SpeechModel] = None
"""
The speech model to use for the transcription.
"""
model_config = ConfigDict(extra="allow")
class TranscriptionConfig:
def __init__(
self,
language_code: Optional[Union[str, LanguageCode]] = None,
punctuate: Optional[bool] = None,
format_text: Optional[bool] = None,
dual_channel: Optional[bool] = None,
multichannel: Optional[bool] = None,
webhook_url: Optional[str] = None,
webhook_auth_header_name: Optional[str] = None,
webhook_auth_header_value: Optional[str] = None,
audio_start_from: Optional[int] = None,
audio_end_at: Optional[int] = None,
word_boost: List[str] = [],
boost_param: Optional[WordBoost] = None,
filter_profanity: Optional[bool] = None,
redact_pii: Optional[bool] = None,
redact_pii_audio: Optional[bool] = None,
redact_pii_audio_quality: Optional[PIIRedactedAudioQuality] = None,
redact_pii_policies: Optional[List[PIIRedactionPolicy]] = None,
redact_pii_sub: Optional[PIISubstitutionPolicy] = None,
speaker_labels: Optional[bool] = None,
speakers_expected: Optional[int] = None,
content_safety: Optional[bool] = None,
content_safety_confidence: Optional[int] = None,
iab_categories: Optional[bool] = None,
custom_spelling: Optional[Dict[str, Union[str, Sequence[str]]]] = None,
disfluencies: Optional[bool] = None,
sentiment_analysis: Optional[bool] = None,
auto_chapters: Optional[bool] = None,
entity_detection: Optional[bool] = None,
summarization: Optional[bool] = None,
summary_model: Optional[SummarizationModel] = None,
summary_type: Optional[SummarizationType] = None,
auto_highlights: Optional[bool] = None,
language_detection: Optional[bool] = None,
language_confidence_threshold: Optional[float] = None,
speech_threshold: Optional[float] = None,
raw_transcription_config: Optional[RawTranscriptionConfig] = None,
speech_model: Optional[SpeechModel] = None,
) -> None:
"""
Args:
language_code: The language of your audio file. Possible values are found in Supported Languages.
punctuate: Enable Automatic Punctuation
format_text: Enable Text Formatting
dual_channel: Enable Dual Channel transcription
multichannel: Enable Multichannel transcription
webhoook_url: The URL we should send webhooks to when your transcript is complete.
webhook_auth_header_name: The name of the header that is sent when the `webhook_url` is being called.
webhook_auth_header_value: The value of the `webhook_auth_header_name` that is sent when the `webhoook_url` is being called.
audio_start_from: The point in time, in milliseconds, to begin transcription from in your media file.
audio_end_at: The point in time, in milliseconds, to stop transcribing in your media file.
word_boost: A list of custom vocabulary to boost accuracy for.
boost_param: The weight to apply to words/phrases in the word_boost array.
filter_profanity: Filter profanity from the transcribed text.
redact_pii: Redact PII from the transcribed text.
redact_pii_audio: Generate a copy of the original media file with spoken PII 'beeped' out (new audio only available for 24 hours).
redact_pii_audio_quality: The quality of the redacted audio file in case `redact_pii_audio` is enabled.
redact_pii_policies: The list of PII Redaction policies to enable.
redact_pii_sub: The replacement logic for detected PII.
speaker_labels: Enable Speaker Diarization.
speakers_expected: The number of speakers you expect to hear in your audio file. Up to 10 speakers are supported.
content_safety: Enable Content Safety Detection.
iab_categories: Enable Topic Detection.
custom_spelling: Customize how words are spelled and formatted using to and from values.
disfluencies: Transcribe Filler Words, like 'umm', in your media file.
sentiment_analysis: Enable Sentiment Analysis.
auto_chapters: Enable Auto Chapters.
entity_detection: Enable Entity Detection.
summarization: Enable Summarization
summary_model: The summarization model to use in case `summarization` is enabled
summary_type: The summarization type to use in case `summarization` is enabled
auto_highlights: Detect important phrases and words in your transcription text.
language_detection: Identify the dominant language that's spoken in an audio file, and route the file to the appropriate model for the detected language.
language_confidence_threshold: The confidence threshold that must be reached if `language_detection` is enabled.
An error will be returned if the language confidence is below this threshold. Valid values are in the range [0,1] inclusive.
speech_threshold: Reject audio files that contain less than this fraction of speech. Valid values are in the range [0,1] inclusive.
raw_transcription_config: Create the config from a `RawTranscriptionConfig`
"""
self._raw_transcription_config = (
raw_transcription_config
if raw_transcription_config is not None
else RawTranscriptionConfig()
)
# explicit configurations have higher priority if `raw_transcription_config` has been passed as well
self.language_code = language_code
self.punctuate = punctuate
self.format_text = format_text
self.dual_channel = dual_channel
self.multichannel = multichannel
self.set_webhook(
webhook_url,
webhook_auth_header_name,
webhook_auth_header_value,
)
self.set_audio_slice(
audio_start_from,
audio_end_at,
)
self.set_word_boost(word_boost, boost_param)
self.filter_profanity = filter_profanity
self.set_redact_pii(
redact_pii,
redact_pii_audio,
redact_pii_audio_quality,
redact_pii_policies,
redact_pii_sub,
)
self.set_speaker_diarization(speaker_labels, speakers_expected)
self.set_content_safety(content_safety, content_safety_confidence)
self.iab_categories = iab_categories
self.set_custom_spelling(custom_spelling, override=True)
self.disfluencies = disfluencies
self.sentiment_analysis = sentiment_analysis
self.auto_chapters = auto_chapters
self.entity_detection = entity_detection
self.set_summarize(
summarization,
summary_model,
summary_type,
)
self.auto_highlights = auto_highlights
self.language_detection = language_detection
self.language_confidence_threshold = language_confidence_threshold
self.speech_threshold = speech_threshold
self.speech_model = speech_model
@property
def raw(self) -> RawTranscriptionConfig:
return self._raw_transcription_config
# region: Getters/Setters
@property
def language_code(self) -> Optional[Union[str, LanguageCode]]:
"The language code of the audio file."
return self._raw_transcription_config.language_code
@language_code.setter
def language_code(self, language_code: Optional[Union[str, LanguageCode]]) -> None:
"Sets the language code of the audio file."
self._raw_transcription_config.language_code = language_code
@property
def speech_model(self) -> Optional[SpeechModel]:
"The speech model to use for the transcription."
return self._raw_transcription_config.speech_model
@speech_model.setter
def speech_model(self, speech_model: Optional[SpeechModel]) -> None:
"Sets the speech model to use for the transcription."
self._raw_transcription_config.speech_model = speech_model
@property
def punctuate(self) -> Optional[bool]:
"Returns the status of the Automatic Punctuation feature."
return self._raw_transcription_config.punctuate
@punctuate.setter
def punctuate(self, enable: Optional[bool]) -> None:
"Enable Automatic Punctuation feature."
self._raw_transcription_config.punctuate = enable
@property
def format_text(self) -> Optional[bool]:
"Returns the status of the Text Formatting feature."
return self._raw_transcription_config.format_text
@format_text.setter
def format_text(self, enable: Optional[bool]) -> None:
"Enables Formatting Text feature."
self._raw_transcription_config.format_text = enable
@property
def dual_channel(self) -> Optional[bool]:
"Returns the status of the Dual Channel transcription feature"
return self._raw_transcription_config.dual_channel
@dual_channel.setter
def dual_channel(self, enable: Optional[bool]) -> None:
"Enable Dual Channel transcription"
self._raw_transcription_config.dual_channel = enable
@property
def multichannel(self) -> Optional[bool]:
"Returns the status of the Multichannel transcription feature"
return self._raw_transcription_config.multichannel
@multichannel.setter
def multichannel(self, enable: Optional[bool]) -> None:
"Enable Multichannel transcription"
self._raw_transcription_config.multichannel = enable
@property
def webhook_url(self) -> Optional[str]:
"The URL we should send webhooks to when your transcript is complete."
return self._raw_transcription_config.webhook_url
@property
def webhook_auth_header_name(self) -> Optional[str]:
"The name of the header that is sent when the `webhook_url` is being called."
return self._raw_transcription_config.webhook_auth_header_name
@property
def webhook_auth_header_value(self) -> Optional[str]:
"The value of the `webhook_auth_header_name` that is sent when the `webhook_url` is being called."
return self._raw_transcription_config.webhook_auth_header_value
@property
def audio_start_from(self) -> Optional[int]:
"Returns the point in time, in milliseconds, to begin transcription from in your media file."
return self._raw_transcription_config.audio_start_from
@property
def audio_end_at(self) -> Optional[int]:
"Returns the point in time, in milliseconds, to stop transcribing in your media file."
return self._raw_transcription_config.audio_end_at
@property
def word_boost(self) -> Optional[List[str]]:
"Returns the list of custom vocabulary to boost accuracy for."
return self._raw_transcription_config.word_boost
@property
def boost_param(self) -> Optional[WordBoost]:
"Returns how much weight is being applied when boosting custom vocabularies."
return self._raw_transcription_config.boost_param
@property
def filter_profanity(self) -> Optional[bool]:
"Returns the status of whether filtering profanity is enabled or not."
return self._raw_transcription_config.filter_profanity
@filter_profanity.setter
def filter_profanity(self, enable: Optional[bool]) -> None:
"Filter profanity from the transcribed text."
self._raw_transcription_config.filter_profanity = enable
@property
def redact_pii(self) -> Optional[bool]:
"Returns the status of the PII Redaction feature."
return self._raw_transcription_config.redact_pii
@property
def redact_pii_audio(self) -> Optional[bool]:
"Whether or not to generate a copy of the original media file with spoken PII 'beeped' out."
return self._raw_transcription_config.redact_pii_audio
@property
def redact_pii_audio_quality(self) -> Optional[PIIRedactedAudioQuality]:
"The quality of the redacted audio file in case `redact_pii_audio` is enabled."
return self._raw_transcription_config.redact_pii_audio_quality
@property
def redact_pii_policies(self) -> Optional[List[PIIRedactionPolicy]]:
"Returns a list of set of defined PII redaction policies."
return self._raw_transcription_config.redact_pii_policies
@property
def redact_pii_sub(self) -> Optional[PIISubstitutionPolicy]:
"Returns the replacement logic for detected PII."
return self._raw_transcription_config.redact_pii_sub
@property
def speaker_labels(self) -> Optional[bool]:
"Returns the status of the Speaker Diarization feature."
return self._raw_transcription_config.speaker_labels
@property
def speakers_expected(self) -> Optional[int]:
"Returns the number of speakers expected to be in the audio file. Used in combination with the `speaker_labels` parameter."
return self._raw_transcription_config.speakers_expected
@property
def content_safety(self) -> Optional[bool]:
"Returns the status of the Content Safety feature."
return self._raw_transcription_config.content_safety
@property
def content_safety_confidence(self) -> Optional[int]:
"The minimum confidence level for a content safety label to be produced. Used in combination with the `content_safety` parameter."
return self._raw_transcription_config.content_safety_confidence
def set_content_safety(
self,
enable: Optional[bool] = True,
content_safety_confidence: Optional[int] = None,
) -> Self:
"""Enable Content Safety feature.
Args:
`enable`: Whether or not to enable the Content Safety feature.
`content_safety_confidence`: The minimum confidence level for a content safety label to be produced.
Raises:
`ValueError`: Raised if `content_safety_confidence` is not between 25 and 100 (inclusive).
"""
if not enable:
self._raw_transcription_config.content_safety = None
self._raw_transcription_config.content_safety_confidence = None
return self
if content_safety_confidence is not None and (
content_safety_confidence < 25 or content_safety_confidence > 100
):
raise ValueError(
"content_safety_confidence must be between 25 and 100 (inclusive)."
)
self._raw_transcription_config.content_safety = enable
self._raw_transcription_config.content_safety_confidence = (
content_safety_confidence
)
return self
@property
def iab_categories(self) -> Optional[bool]:
"Returns the status of the Topic Detection feature."
return self._raw_transcription_config.iab_categories
@iab_categories.setter
def iab_categories(self, enable: Optional[bool]) -> None:
"Enable Topic Detection feature."
self._raw_transcription_config.iab_categories = enable
@property
def custom_spelling(self) -> Optional[Dict[str, Union[str, List[str]]]]:
"""
Returns the current set of custom spellings. For each key-value pair in the dictionary,
the key is the 'to' field, and the value is the 'from' field.
"""
if self._raw_transcription_config.custom_spelling is None:
return None
custom_spellings = {}
for custom_spelling in self._raw_transcription_config.custom_spelling:
_to = custom_spelling["to"]
if not isinstance(_to, str):
raise ValueError("`to` argument must be a string!")
custom_spellings[_to] = custom_spelling["from"]
return custom_spellings if custom_spelling else None
@property
def disfluencies(self) -> Optional[bool]:
"Returns whether to transcribing filler words is enabled or not."
return self._raw_transcription_config.disfluencies
@disfluencies.setter
def disfluencies(self, enable: Optional[bool]) -> None:
"Transcribe filler words, like 'umm', in your media file."
self._raw_transcription_config.disfluencies = enable
@property
def sentiment_analysis(self) -> Optional[bool]:
"Returns the status of the Sentiment Analysis feature."
return self._raw_transcription_config.sentiment_analysis
@sentiment_analysis.setter
def sentiment_analysis(self, enable: Optional[bool]) -> None: