Services
ASR Service module that handle all AI interactions.
ASRAsyncService
Bases: ASRService
ASR Service module for async endpoints.
Source code in src/wordcab_transcribe/services/asr_service.py
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 |
|
__init__(whisper_model, compute_type, window_lengths, shift_lengths, multiscale_weights, extra_languages, extra_languages_model_paths, transcribe_server_urls, diarize_server_urls, debug_mode)
Initialize the ASRAsyncService class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
whisper_model |
str
|
The path to the whisper model. |
required |
compute_type |
str
|
The compute type to use for inference. |
required |
window_lengths |
List[float]
|
The window lengths to use for diarization. |
required |
shift_lengths |
List[float]
|
The shift lengths to use for diarization. |
required |
multiscale_weights |
List[float]
|
The multiscale weights to use for diarization. |
required |
extra_languages |
Union[List[str], None]
|
The list of extra languages to support. |
required |
extra_languages_model_paths |
Union[List[str], None]
|
The list of paths to the extra language models. |
required |
use_remote_servers |
bool
|
Whether to use remote servers for transcription and diarization. |
required |
transcribe_server_urls |
Union[List[str], None]
|
The list of URLs to the remote transcription servers. |
required |
diarize_server_urls |
Union[List[str], None]
|
The list of URLs to the remote diarization servers. |
required |
debug_mode |
bool
|
Whether to run in debug mode. |
required |
Source code in src/wordcab_transcribe/services/asr_service.py
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 |
|
add_url(data)
async
Add a remote URL to the list of URLs.
Source code in src/wordcab_transcribe/services/asr_service.py
create_diarization_local_service()
Create a local diarization service.
Source code in src/wordcab_transcribe/services/asr_service.py
create_local_service(task)
Create a local service.
Source code in src/wordcab_transcribe/services/asr_service.py
create_transcription_local_service()
Create a local transcription service.
Source code in src/wordcab_transcribe/services/asr_service.py
get_url(task)
async
Get the list of remote URLs.
Source code in src/wordcab_transcribe/services/asr_service.py
inference_warmup()
async
Warmup the GPU by loading the models.
Source code in src/wordcab_transcribe/services/asr_service.py
process_diarization(task, debug_mode)
async
Process a task of diarization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task |
ASRTask
|
The task and its parameters. |
required |
debug_mode |
bool
|
Whether to run in debug mode or not. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
The task is updated with the result. |
Source code in src/wordcab_transcribe/services/asr_service.py
process_input(filepath, offset_start, offset_end, num_speakers, diarization, multi_channel, source_lang, timestamps_format, vocab, word_timestamps, internal_vad, repetition_penalty, compression_ratio_threshold, log_prob_threshold, no_speech_threshold, condition_on_previous_text)
async
Process the input request and return the results.
This method will create a task and add it to the appropriate queues. All tasks are added to the transcription queue, but will be added to the diarization queues only if the user requested it. Each step will be processed asynchronously and the results will be returned and stored in separated keys in the task dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
Union[str, List[str]]
|
Path to the audio file or list of paths to the audio files to process. |
required |
offset_start |
Union[float, None]
|
The start time of the audio file to process. |
required |
offset_end |
Union[float, None]
|
The end time of the audio file to process. |
required |
num_speakers |
int
|
The number of oracle speakers. |
required |
diarization |
bool
|
Whether to do diarization or not. |
required |
multi_channel |
bool
|
Whether to do multi-channel diarization or not. |
required |
source_lang |
str
|
Source language of the audio file. |
required |
timestamps_format |
str
|
Timestamps format to use. |
required |
vocab |
Union[List[str], None]
|
List of words to use for the vocabulary. |
required |
word_timestamps |
bool
|
Whether to return word timestamps or not. |
required |
internal_vad |
bool
|
Whether to use faster-whisper's VAD or not. |
required |
repetition_penalty |
float
|
The repetition penalty to use for the beam search. |
required |
compression_ratio_threshold |
float
|
If the gzip compression ratio is above this value, treat as failed. |
required |
log_prob_threshold |
float
|
If the average log probability over sampled tokens is below this value, treat as failed. |
required |
no_speech_threshold |
float
|
If the no_speech probability is higher than this value AND the average log probability
over sampled tokens is below |
required |
condition_on_previous_text |
bool
|
If True, the previous output of the model is provided as a prompt for the next window; disabling may make the text inconsistent across windows, but the model becomes less prone to getting stuck in a failure loop, such as repetition looping or timestamps going out of sync. |
required |
Returns:
Type | Description |
---|---|
Union[Tuple[List[dict], ProcessTimes, float], Exception]
|
Union[Tuple[List[dict], ProcessTimes, float], Exception]: The results of the ASR pipeline or an exception if something went wrong. Results are returned as a tuple of the following: * List[dict]: The final results of the ASR pipeline. * ProcessTimes: The process times of each step of the ASR pipeline. * float: The audio duration |
Source code in src/wordcab_transcribe/services/asr_service.py
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 |
|
process_post_processing(task)
Process a task of post-processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task |
ASRTask
|
The task and its parameters. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
The task is updated with the result. |
Source code in src/wordcab_transcribe/services/asr_service.py
process_transcription(task, debug_mode)
async
Process a task of transcription and update the task with the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task |
ASRTask
|
The task and its parameters. |
required |
debug_mode |
bool
|
Whether to run in debug mode or not. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
The task is updated with the result. |
Source code in src/wordcab_transcribe/services/asr_service.py
remote_diarization(url, data)
async
Remote diarization method.
Source code in src/wordcab_transcribe/services/asr_service.py
remote_transcription(url, data)
async
Remote transcription method.
Source code in src/wordcab_transcribe/services/asr_service.py
remove_url(data)
async
Remove a remote URL from the list of URLs.
Source code in src/wordcab_transcribe/services/asr_service.py
ASRDiarizationOnly
Bases: ASRService
ASR Service module for diarization-only endpoint.
Source code in src/wordcab_transcribe/services/asr_service.py
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 |
|
__init__(window_lengths, shift_lengths, multiscale_weights, debug_mode)
Initialize the ASRDiarizationOnly class.
Source code in src/wordcab_transcribe/services/asr_service.py
inference_warmup()
async
Warmup the GPU by doing one inference.
Source code in src/wordcab_transcribe/services/asr_service.py
process_input(data)
async
Process the input data and return the results as a list of segments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DiarizationRequest
|
The input data to process. |
required |
Returns:
Name | Type | Description |
---|---|---|
DiarizationOutput |
DiarizationOutput
|
The results of the ASR pipeline. |
Source code in src/wordcab_transcribe/services/asr_service.py
ASRLiveService
Bases: ASRService
ASR Service module for live endpoints.
Source code in src/wordcab_transcribe/services/asr_service.py
__init__(whisper_model, compute_type, debug_mode)
Initialize the ASRLiveService class.
Source code in src/wordcab_transcribe/services/asr_service.py
inference_warmup()
async
Warmup the GPU by loading the models.
Source code in src/wordcab_transcribe/services/asr_service.py
process_input(data, source_lang)
async
Process the input data and return the results as a tuple of text and duration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
bytes
|
The raw audio bytes to process. |
required |
source_lang |
str
|
The source language of the audio data. |
required |
Yields:
Type | Description |
---|---|
Iterable[dict]
|
Iterable[dict]: The results of the ASR pipeline. |
Source code in src/wordcab_transcribe/services/asr_service.py
ASRService
Bases: ABC
Base ASR Service module that handle all AI interactions and batch processing.
Source code in src/wordcab_transcribe/services/asr_service.py
__init__()
Initialize the ASR Service.
This class is not meant to be instantiated. Use the subclasses instead.
Source code in src/wordcab_transcribe/services/asr_service.py
process_input()
abstractmethod
async
Process the input request by creating a task and adding it to the appropriate queues.
Source code in src/wordcab_transcribe/services/asr_service.py
ASRTask
Bases: BaseModel
ASR Task model.
Source code in src/wordcab_transcribe/services/asr_service.py
ASRTranscriptionOnly
Bases: ASRService
ASR Service module for transcription-only endpoint.
Source code in src/wordcab_transcribe/services/asr_service.py
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 |
|
__init__(whisper_model, compute_type, extra_languages, extra_languages_model_paths, debug_mode)
Initialize the ASRTranscriptionOnly class.
Source code in src/wordcab_transcribe/services/asr_service.py
inference_warmup()
async
Warmup the GPU by doing one inference.
Source code in src/wordcab_transcribe/services/asr_service.py
process_input(data)
async
Process the input data and return the results as a list of segments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
TranscribeRequest
|
The input data to process. |
required |
Returns:
Type | Description |
---|---|
Union[TranscriptionOutput, List[TranscriptionOutput]]
|
Union[TranscriptionOutput, List[TranscriptionOutput]]: The results of the ASR pipeline. |
Source code in src/wordcab_transcribe/services/asr_service.py
DiarizationTask
Bases: BaseModel
Diarization Task model.
Source code in src/wordcab_transcribe/services/asr_service.py
ExceptionSource
Bases: str
, Enum
Exception source enum.
Source code in src/wordcab_transcribe/services/asr_service.py
LocalExecution
LocalServiceRegistry
dataclass
Registry for local services.
Source code in src/wordcab_transcribe/services/asr_service.py
PostProcessingTask
ProcessException
RemoteExecution
RemoteServiceConfig
dataclass
Remote service config.
Source code in src/wordcab_transcribe/services/asr_service.py
add_url(url)
async
get_queue_size()
get_urls()
next_url()
async
RemoteServiceRegistry
dataclass
Registry for remote services.
Source code in src/wordcab_transcribe/services/asr_service.py
TranscriptionOptions
Bases: BaseModel
Transcription options model.
Source code in src/wordcab_transcribe/services/asr_service.py
TranscriptionTask
Bases: BaseModel
Transcription Task model.
Source code in src/wordcab_transcribe/services/asr_service.py
GPU service class to handle gpu availability for models.
GPUService
GPU service class to handle gpu availability for models.
Source code in src/wordcab_transcribe/services/concurrency_services.py
__init__(device, device_index)
Initialize the GPU service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
str
|
Device to use for inference. Can be "cpu" or "cuda". |
required |
device_index |
List[int]
|
Index of the device to use for inference. |
required |
Source code in src/wordcab_transcribe/services/concurrency_services.py
get_device()
async
Get the next available device.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Index of the next available device. |
Source code in src/wordcab_transcribe/services/concurrency_services.py
release_device(device_index)
Return a device to the available devices list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_index |
int
|
Index of the device to add to the available devices list. |
required |
Source code in src/wordcab_transcribe/services/concurrency_services.py
URLService
URL service class to handle multiple remote URLs.
Source code in src/wordcab_transcribe/services/concurrency_services.py
__init__(remote_urls)
Initialize the URL service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_urls |
List[str]
|
List of remote URLs to use. |
required |
Source code in src/wordcab_transcribe/services/concurrency_services.py
add_url(url)
async
Add a URL to the pool of available URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
URL to add to the queue. |
required |
Source code in src/wordcab_transcribe/services/concurrency_services.py
get_queue_size()
Get the current queue size.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Current queue size. |
get_urls()
Get the list of available URLs.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of available URLs. |
next_url()
async
We use this to iterate equally over the available URLs.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Next available URL. |
Source code in src/wordcab_transcribe/services/concurrency_services.py
remove_url(url)
async
Remove a URL from the pool of available URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
URL to remove from the queue. |
required |
Source code in src/wordcab_transcribe/services/concurrency_services.py
Diarization Service for audio files.
DiarizationModels
DiarizeService
Diarize Service for audio files.
Source code in src/wordcab_transcribe/services/diarization/diarize_service.py
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 |
|
__call__(waveform, audio_duration, oracle_num_speakers, model_index, vad_service)
Run inference with the diarization model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
waveform |
Union[Tensor, TensorShare]
|
Waveform to run inference on. |
required |
audio_duration |
float
|
Duration of the audio file in seconds. |
required |
oracle_num_speakers |
int
|
Number of speakers in the audio file. |
required |
model_index |
int
|
Index of the model to use for inference. |
required |
vad_service |
VadService
|
VAD service instance to use for Voice Activity Detection. |
required |
Returns:
Name | Type | Description |
---|---|---|
DiarizationOutput |
DiarizationOutput
|
List of segments with the following keys: "start", "end", "speaker". |
Source code in src/wordcab_transcribe/services/diarization/diarize_service.py
__init__(device, device_index, window_lengths, shift_lengths, multiscale_weights, max_num_speakers=8)
Initialize the Diarize Service.
This service uses the NVIDIA NeMo diarization models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device |
str
|
Device to use for inference. Can be "cpu" or "cuda". |
required |
device_index |
Union[int, List[int]]
|
Index of the device to use for inference. |
required |
window_lengths |
List[float]
|
List of window lengths. |
required |
shift_lengths |
List[float]
|
List of shift lengths. |
required |
multiscale_weights |
List[int]
|
List of weights for each scale. |
required |
max_num_speakers |
int
|
Maximum number of speakers. Defaults to 8. |
8
|
Source code in src/wordcab_transcribe/services/diarization/diarize_service.py
get_contiguous_stamps(stamps)
staticmethod
Return contiguous timestamps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stamps |
List[Tuple[float, float, int]]
|
List of segments containing the start time, end time and speaker. |
required |
Returns:
Type | Description |
---|---|
List[Tuple[float, float, int]]
|
List[Tuple[float, float, int]]: List of segments containing the start time, end time and speaker. |
Source code in src/wordcab_transcribe/services/diarization/diarize_service.py
merge_stamps(stamps)
staticmethod
Merge timestamps of the same speaker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stamps |
List[Tuple[float, float, int]]
|
List of segments containing the start time, end time and speaker. |
required |
Returns:
Type | Description |
---|---|
List[Tuple[float, float, int]]
|
List[Tuple[float, float, int]]: List of segments containing the start time, end time and speaker. |
Source code in src/wordcab_transcribe/services/diarization/diarize_service.py
Post-Processing Service for audio files.
PostProcessingService
Post-Processing Service for audio files.
Source code in src/wordcab_transcribe/services/post_processing_service.py
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 |
|
__init__()
final_processing_before_returning(utterances, offset_start, timestamps_format, word_timestamps)
Do final processing before returning the utterances to the API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
utterances |
List[Utterance]
|
List of utterances. |
required |
offset_start |
Union[float, None]
|
Offset start. |
required |
timestamps_format |
Timestamps
|
Timestamps format. Can be |
required |
word_timestamps |
bool
|
Whether to include word timestamps. |
required |
Returns:
Type | Description |
---|---|
List[Utterance]
|
List[Utterance]: List of utterances after final processing. |
Source code in src/wordcab_transcribe/services/post_processing_service.py
multi_channel_speaker_mapping(multi_channel_segments)
Run the multi-channel post-processing functions on the inputs by merging the segments based on the timestamps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
multi_channel_segments |
List[MultiChannelTranscriptionOutput]
|
List of segments from multi speakers. |
required |
Returns:
Name | Type | Description |
---|---|---|
TranscriptionOutput |
TranscriptionOutput
|
List of sentences with speaker mapping. |
Source code in src/wordcab_transcribe/services/post_processing_service.py
reconstruct_multi_channel_utterances(transcript_words)
Reconstruct multi-channel utterances based on the speaker mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcript_words |
List[Tuple[int, Word]]
|
List of tuples containing the speaker and the word. |
required |
Returns:
Type | Description |
---|---|
List[Utterance]
|
List[Utterance]: List of sentences with speaker mapping. |
Source code in src/wordcab_transcribe/services/post_processing_service.py
reconstruct_utterances(transcript_segments, word_timestamps)
Reconstruct the utterances based on the speaker mapping.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcript_words |
List[Utterance]
|
List of transcript segments. |
required |
word_timestamps |
bool
|
Whether to include word timestamps. |
required |
Returns:
Type | Description |
---|---|
List[Utterance]
|
List[Utterance]: List of sentences with speaker mapping. |
Source code in src/wordcab_transcribe/services/post_processing_service.py
segments_speaker_mapping(transcript_segments, speaker_timestamps)
Function to map transcription and diarization results.
Map each segment to its corresponding speaker based on the speaker timestamps and reconstruct the utterances when the speaker changes in the middle of a segment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcript_segments |
List[dict]
|
List of transcript segments. |
required |
speaker_timestamps |
List[dict]
|
List of speaker timestamps. |
required |
Returns:
Type | Description |
---|---|
List[dict]
|
List[dict]: List of sentences with speaker mapping. |
Source code in src/wordcab_transcribe/services/post_processing_service.py
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 |
|
single_channel_speaker_mapping(transcript_segments, speaker_timestamps, word_timestamps)
Run the post-processing functions on the inputs.
The postprocessing pipeline is as follows: 1. Map each transcript segment to its corresponding speaker. 2. Group utterances of the same speaker together.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcript_segments |
List[Utterance]
|
List of transcript utterances. |
required |
speaker_timestamps |
DiarizationOutput
|
List of speaker timestamps. |
required |
word_timestamps |
bool
|
Whether to include word timestamps. |
required |
Returns:
Type | Description |
---|---|
List[Utterance]
|
List[Utterance]: List of utterances with speaker mapping. |
Source code in src/wordcab_transcribe/services/post_processing_service.py
Transcribe Service for audio files.
FasterWhisperModel
TranscribeService
Transcribe Service for audio files.
Source code in src/wordcab_transcribe/services/transcribe_service.py
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 |
|
__call__(audio, source_lang, model_index, suppress_blank=False, vocab=None, word_timestamps=True, internal_vad=False, repetition_penalty=1.0, compression_ratio_threshold=2.4, log_prob_threshold=-1.0, no_speech_threshold=0.6, condition_on_previous_text=True)
Run inference with the transcribe model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio |
Union[str, Tensor, TensorShare, List[str], List[Tensor], List[TensorShare]]
|
Audio file path or audio tensor. If a tuple is passed, the task is assumed to be a multi_channel task and the list of audio files or tensors is passed. |
required |
source_lang |
str
|
Language of the audio file. |
required |
model_index |
int
|
Index of the model to use. |
required |
suppress_blank |
bool
|
Whether to suppress blank at the beginning of the sampling. |
False
|
vocab |
Union[List[str], None]
|
Vocabulary to use during generation if not None. Defaults to None. |
None
|
word_timestamps |
bool
|
Whether to return word timestamps. |
True
|
internal_vad |
bool
|
Whether to use faster-whisper's VAD or not. |
False
|
repetition_penalty |
float
|
Repetition penalty to use during generation beamed search. |
1.0
|
compression_ratio_threshold |
float
|
If the gzip compression ratio is above this value, treat as failed. |
2.4
|
log_prob_threshold |
float
|
If the average log probability over sampled tokens is below this value, treat as failed. |
-1.0
|
no_speech_threshold |
float
|
If the no_speech probability is higher than this value AND the average log probability
over sampled tokens is below |
0.6
|
condition_on_previous_text |
bool
|
If True, the previous output of the model is provided as a prompt for the next window; disabling may make the text inconsistent across windows, but the model becomes less prone to getting stuck in a failure loop, such as repetition looping or timestamps going out of sync. |
True
|
Returns:
Type | Description |
---|---|
Union[TranscriptionOutput, List[TranscriptionOutput]]
|
Union[TranscriptionOutput, List[TranscriptionOutput]]: Transcription output. If the task is a multi_channel task, a list of TranscriptionOutput is returned. |
Source code in src/wordcab_transcribe/services/transcribe_service.py
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 |
|
__init__(model_path, compute_type, device, device_index, extra_languages=None, extra_languages_model_paths=None)
Initialize the Transcribe Service.
This service uses the WhisperModel from faster-whisper to transcribe audio files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_path |
str
|
Path to the model checkpoint. This can be a local path or a URL. |
required |
compute_type |
str
|
Compute type to use for inference. Can be "int8", "int8_float16", "int16" or "float_16". |
required |
device |
str
|
Device to use for inference. Can be "cpu" or "cuda". |
required |
device_index |
Union[int, List[int]]
|
Index of the device to use for inference. |
required |
extra_languages |
Union[List[str], None]
|
List of extra languages to transcribe. Defaults to None. |
None
|
extra_languages_model_paths |
Union[List[str], None]
|
List of paths to the extra language models. Defaults to None. |
None
|
Source code in src/wordcab_transcribe/services/transcribe_service.py
async_live_transcribe(audio, source_lang, model_index)
async
Async generator for live transcriptions.
This method wraps the live_transcribe method to make it async.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio |
Tensor
|
Audio tensor. |
required |
source_lang |
str
|
Language of the audio file. |
required |
model_index |
int
|
Index of the model to use. |
required |
Yields:
Type | Description |
---|---|
Iterable[dict]
|
Iterable[dict]: Iterable of transcribed segments. |
Source code in src/wordcab_transcribe/services/transcribe_service.py
live_transcribe(audio, source_lang, model_index)
Transcribe audio from a WebSocket connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio |
Tensor
|
Audio tensor. |
required |
source_lang |
str
|
Language of the audio file. |
required |
model_index |
int
|
Index of the model to use. |
required |
Yields:
Type | Description |
---|---|
Iterable[dict]
|
Iterable[dict]: Iterable of transcribed segments. |
Source code in src/wordcab_transcribe/services/transcribe_service.py
multi_channel(audio, source_lang, speaker_id, suppress_blank=False, word_timestamps=True, internal_vad=True, repetition_penalty=1.0, compression_ratio_threshold=2.4, log_prob_threshold=-1.0, no_speech_threshold=0.6, condition_on_previous_text=False, prompt=None)
Transcribe an audio file using the faster-whisper original pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
audio |
Union[str, Tensor, TensorShare]
|
Audio file path or loaded audio. |
required |
source_lang |
str
|
Language of the audio file. |
required |
speaker_id |
int
|
Speaker ID used in the diarization. |
required |
suppress_blank |
bool
|
Whether to suppress blank at the beginning of the sampling. |
False
|
word_timestamps |
bool
|
Whether to return word timestamps. |
True
|
internal_vad |
bool
|
Whether to use faster-whisper's VAD or not. |
True
|
repetition_penalty |
float
|
Repetition penalty to use during generation beamed search. |
1.0
|
compression_ratio_threshold |
float
|
If the gzip compression ratio is above this value, treat as failed. |
2.4
|
log_prob_threshold |
float
|
If the average log probability over sampled tokens is below this value, treat as failed. |
-1.0
|
no_speech_threshold |
float
|
If the no_speech probability is higher than this value AND the average log probability
over sampled tokens is below |
0.6
|
condition_on_previous_text |
bool
|
If True, the previous output of the model is provided as a prompt for the next window; disabling may make the text inconsistent across windows, but the model becomes less prone to getting stuck in a failure loop, such as repetition looping or timestamps going out of sync. |
False
|
prompt |
Optional[str]
|
Initial prompt to use for the generation. |
None
|
Returns:
Name | Type | Description |
---|---|---|
MultiChannelTranscriptionOutput |
MultiChannelTranscriptionOutput
|
Multi-channel transcription segments in a list. |
Source code in src/wordcab_transcribe/services/transcribe_service.py
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 |
|
Voice Activation Detection (VAD) Service for audio files.
VadService
VAD Service for audio files.
Source code in src/wordcab_transcribe/services/vad_service.py
__call__(waveform, group_timestamps=True)
Use the VAD model to get the speech timestamps. Multi-channel pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
waveform |
Tensor
|
Audio tensor. |
required |
group_timestamps |
Optional[bool]
|
Group timestamps. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Tuple[Union[List[dict], List[List[dict]]], Tensor]
|
Tuple[Union[List[dict], List[List[dict]]], torch.Tensor]: Speech timestamps and audio tensor. |
Source code in src/wordcab_transcribe/services/vad_service.py
__init__()
Initialize the VAD Service.
Source code in src/wordcab_transcribe/services/vad_service.py
group_timestamps(timestamps, threshold=3.0)
Group timestamps based on a threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamps |
List[dict]
|
List of timestamps. |
required |
threshold |
float
|
Threshold to use for grouping. Defaults to 3.0. |
3.0
|
Returns:
Type | Description |
---|---|
List[List[dict]]
|
List[List[dict]]: List of grouped timestamps. |
Source code in src/wordcab_transcribe/services/vad_service.py
save_audio(filepath, audio)
Save audio tensor to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
str
|
Path to save the audio file. |
required |
audio |
Tensor
|
Audio tensor. |
required |
Source code in src/wordcab_transcribe/services/vad_service.py
Created: 2023-10-12