1
+ # -*- coding: utf-8 -*-
2
+ """Client used for interacting with our forced alignment api"""
3
+
4
+ import json
5
+ from .generic_api_client import GenericApiClient
6
+ from .models .forced_alignment import ForcedAlignmentJob , ForcedAlignmentResult
7
+
8
+
9
+ class ForcedAlignmentClient (GenericApiClient ):
10
+ """Client for interacting with the Rev AI forced alignment api"""
11
+
12
+ # Default version of Rev AI forced alignment api
13
+ api_version = 'v1'
14
+
15
+ # Default api name of Rev AI forced alignment api
16
+ api_name = 'alignment'
17
+
18
+ def __init__ (self , access_token ):
19
+ """Constructor
20
+
21
+ :param access_token: access token which authorizes all requests and links them to your
22
+ account. Generated on the settings page of your account dashboard
23
+ on Rev AI.
24
+ """
25
+ GenericApiClient .__init__ (self , access_token , self .api_name , self .api_version ,
26
+ ForcedAlignmentJob .from_json , ForcedAlignmentResult .from_json )
27
+
28
+ def submit_job_url (
29
+ self ,
30
+ source_config = None ,
31
+ source_transcript_config = None ,
32
+ transcript_text = None ,
33
+ metadata = None ,
34
+ delete_after_seconds = None ,
35
+ notification_config = None ,
36
+ language = None ):
37
+ """Submit a job to the Rev AI forced alignment api.
38
+
39
+ :param source_config: CustomerUrlData object containing url of the source media and
40
+ optional authentication headers to use when accessing the source url
41
+ :param source_transcript_config: CustomerUrlData object containing url of the transcript file and
42
+ optional authentication headers to use when accessing the transcript url
43
+ :param transcript_text: The text of the transcript to be aligned (no punctuation, just words)
44
+ :param metadata: info to associate with the alignment job
45
+ :param delete_after_seconds: number of seconds after job completion when job is auto-deleted
46
+ :param notification_config: CustomerUrlData object containing the callback url to
47
+ invoke on job completion as a webhook and optional authentication headers to use when
48
+ calling the callback url
49
+ :param language: Language code for the audio and transcript. One of: "en", "es", "fr"
50
+ :returns: ForcedAlignmentJob object
51
+ :raises: HTTPError
52
+ """
53
+ if not source_config :
54
+ raise ValueError ('source_config must be provided' )
55
+ if not (source_transcript_config or transcript_text ):
56
+ raise ValueError ('Either source_transcript_config or transcript_text must be provided' )
57
+ if source_transcript_config and transcript_text :
58
+ raise ValueError ('Only one of source_transcript_config or transcript_text may be provided' )
59
+
60
+ payload = self ._enhance_payload ({
61
+ 'source_config' : source_config .to_dict () if source_config else None ,
62
+ 'source_transcript_config' : source_transcript_config .to_dict () if source_transcript_config else None ,
63
+ 'transcript_text' : transcript_text ,
64
+ 'language' : language
65
+ }, metadata , None , delete_after_seconds , notification_config )
66
+
67
+ return self ._submit_job (payload )
68
+
69
+ def get_result_json (self , id_ ):
70
+ """Get result of a forced alignment job as json.
71
+
72
+ :param id_: id of job to be requested
73
+ :returns: job result data as raw json
74
+ :raises: HTTPError
75
+ """
76
+ return self ._get_result_json (id_ )
77
+
78
+ def get_result_object (self , id_ ):
79
+ """Get result of a forced alignment job as ForcedAlignmentResult object.
80
+
81
+ :param id_: id of job to be requested
82
+ :returns: job result data as ForcedAlignmentResult object
83
+ :raises: HTTPError
84
+ """
85
+ return self ._get_result_object (id_ )
0 commit comments