forked from watson-developer-cloud/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech_to_text_v1.py
More file actions
3468 lines (3064 loc) · 194 KB
/
speech_to_text_v1.py
File metadata and controls
3468 lines (3064 loc) · 194 KB
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
# coding: utf-8
# Copyright 2018 IBM All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
### Service Overview
The service transcribes speech from various languages and audio formats to text with low
latency. The service supports transcription of the following languages: Brazilian
Portuguese, French, Japanese, Mandarin Chinese, Modern Standard Arabic, Spanish, UK
English, and US English. For most languages, the service supports two sampling rates,
broadband and narrowband.
"""
from __future__ import absolute_import
import json
from .watson_service import WatsonService, _remove_null_values
from .utils import deprecated
from watson_developer_cloud.websocket import RecognizeCallback, RecognizeListener
import base64
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode
##############################################################################
# Service
##############################################################################
class SpeechToTextV1(WatsonService):
"""The Speech to Text V1 service."""
default_url = 'https://stream.watsonplatform.net/speech-to-text/api'
def __init__(self,
url=default_url,
username=None,
password=None,
iam_api_key=None,
iam_access_token=None,
iam_url=None):
"""
Construct a new client for the Speech to Text service.
:param str url: The base url to use when contacting the service (e.g.
"https://stream.watsonplatform.net/speech-to-text/api").
The base url may differ between Bluemix regions.
:param str username: The username used to authenticate with the service.
Username and password credentials are only required to run your
application locally or outside of Bluemix. When running on
Bluemix, the credentials will be automatically loaded from the
`VCAP_SERVICES` environment variable.
:param str password: The password used to authenticate with the service.
Username and password credentials are only required to run your
application locally or outside of Bluemix. When running on
Bluemix, the credentials will be automatically loaded from the
`VCAP_SERVICES` environment variable.
:param str iam_api_key: An API key that can be used to request IAM tokens. If
this API key is provided, the SDK will manage the token and handle the
refreshing.
:param str iam_access_token: An IAM access token is fully managed by the application.
Responsibility falls on the application to refresh the token, either before
it expires or reactively upon receiving a 401 from the service as any requests
made with an expired token will fail.
:param str iam_url: An optional URL for the IAM service API. Defaults to
'https://iam.ng.bluemix.net/identity/token'.
"""
WatsonService.__init__(
self,
vcap_services_name='speech_to_text',
url=url,
username=username,
password=password,
iam_api_key=iam_api_key,
iam_access_token=iam_access_token,
iam_url=iam_url,
use_vcap_services=True)
#########################
# Models
#########################
def get_model(self, model_id, **kwargs):
"""
Retrieves information about the model.
Returns information about a single specified language model that is available for
use with the service. The information includes the name of the model and its
minimum sampling rate in Hertz, among other things.
:param str model_id: The identifier of the desired model in the form of its `name` from the output of **Get models**.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `SpeechModel` response.
:rtype: dict
"""
if model_id is None:
raise ValueError('model_id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/models/{0}'.format(*self._encode_path_vars(model_id))
response = self.request(
method='GET', url=url, headers=headers, accept_json=True)
return response
def list_models(self, **kwargs):
"""
Retrieves the models available for the service.
Returns a list of all language models that are available for use with the service.
The information includes the name of the model and its minimum sampling rate in
Hertz, among other things.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `SpeechModels` response.
:rtype: dict
"""
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/models'
response = self.request(
method='GET', url=url, headers=headers, accept_json=True)
return response
@deprecated('Use list_models instead.')
def models(self):
return self.list_models()
#########################
# Sessionless
#########################
def recognize(self,
model=None,
customization_id=None,
acoustic_customization_id=None,
customization_weight=None,
version=None,
audio=None,
content_type=None,
inactivity_timeout=None,
keywords=None,
keywords_threshold=None,
max_alternatives=None,
word_alternatives_threshold=None,
word_confidence=None,
timestamps=None,
profanity_filter=None,
smart_formatting=None,
speaker_labels=None,
**kwargs):
"""
Sends audio for speech recognition in sessionless mode.
:param str model: The identifier of the model that is to be used for the recognition request.
:param str customization_id: The GUID of a custom language model that is to be used with the request. The base model of the specified custom language model must match the model specified with the `model` parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom language model is used.
:param str acoustic_customization_id: The GUID of a custom acoustic model that is to be used with the request. The base model of the specified custom acoustic model must match the model specified with the `model` parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom acoustic model is used.
:param float customization_weight: NON-MULTIPART ONLY: If you specify a customization ID with the request, you can use the customization weight to tell the service how much weight to give to words from the custom language model compared to those from the base model for speech recognition. Specify a value between 0.0 and 1.0. Unless a different customization weight was specified for the custom model when it was trained, the default value is 0.3. A customization weight that you specify overrides a weight that was specified when the custom model was trained. The default value yields the best performance in general. Assign a higher value if your audio makes frequent use of OOV words from the custom model. Use caution when setting the weight: a higher value can improve the accuracy of phrases from the custom model's domain, but it can negatively affect performance on non-domain phrases.
:param str version: The version of the specified base `model` that is to be used for speech recognition. Multiple versions of a base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with custom models that have been upgraded for a new base model. The default value depends on whether the parameter is used with or without a custom model. For more information, see [Base model version](https://console.bluemix.net/docs/services/speech-to-text/input.html#version).
:param str audio: NON-MULTIPART ONLY: Audio to transcribe in the format specified by the `Content-Type` header. **Required for a non-multipart request.**.
:param str content_type: The type of the input: audio/basic, audio/flac, audio/l16, audio/mp3, audio/mpeg, audio/mulaw, audio/ogg, audio/ogg;codecs=opus, audio/ogg;codecs=vorbis, audio/wav, audio/webm, audio/webm;codecs=opus, audio/webm;codecs=vorbis, or multipart/form-data.
:param int inactivity_timeout: NON-MULTIPART ONLY: The time in seconds after which, if only silence (no speech) is detected in submitted audio, the connection is closed with a 400 error. Useful for stopping audio submission from a live microphone when a user simply walks away. Use `-1` for infinity.
:param list[str] keywords: NON-MULTIPART ONLY: Array of keyword strings to spot in the audio. Each keyword string can include one or more tokens. Keywords are spotted only in the final hypothesis, not in interim results. If you specify any keywords, you must also specify a keywords threshold. You can spot a maximum of 1000 keywords. Omit the parameter or specify an empty array if you do not need to spot keywords.
:param float keywords_threshold: NON-MULTIPART ONLY: Confidence value that is the lower bound for spotting a keyword. A word is considered to match a keyword if its confidence is greater than or equal to the threshold. Specify a probability between 0 and 1 inclusive. No keyword spotting is performed if you omit the parameter. If you specify a threshold, you must also specify one or more keywords.
:param int max_alternatives: NON-MULTIPART ONLY: Maximum number of alternative transcripts to be returned. By default, a single transcription is returned.
:param float word_alternatives_threshold: NON-MULTIPART ONLY: Confidence value that is the lower bound for identifying a hypothesis as a possible word alternative (also known as \"Confusion Networks\"). An alternative word is considered if its confidence is greater than or equal to the threshold. Specify a probability between 0 and 1 inclusive. No alternative words are computed if you omit the parameter.
:param bool word_confidence: NON-MULTIPART ONLY: If `true`, confidence measure per word is returned.
:param bool timestamps: NON-MULTIPART ONLY: If `true`, time alignment for each word is returned.
:param bool profanity_filter: NON-MULTIPART ONLY: If `true` (the default), filters profanity from all output except for keyword results by replacing inappropriate words with a series of asterisks. Set the parameter to `false` to return results with no censoring. Applies to US English transcription only.
:param bool smart_formatting: NON-MULTIPART ONLY: If `true`, converts dates, times, series of digits and numbers, phone numbers, currency values, and Internet addresses into more readable, conventional representations in the final transcript of a recognition request. If `false` (the default), no formatting is performed. Applies to US English transcription only.
:param bool speaker_labels: NON-MULTIPART ONLY: Indicates whether labels that identify which words were spoken by which participants in a multi-person exchange are to be included in the response. The default is `false`; no speaker labels are returned. Setting `speaker_labels` to `true` forces the `timestamps` parameter to be `true`, regardless of whether you specify `false` for the parameter. To determine whether a language model supports speaker labels, use the **Get models** method and check that the attribute `speaker_labels` is set to `true`. You can also refer to [Speaker labels](https://console.bluemix.net/docs/services/speech-to-text/output.html#speaker_labels).
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `SpeechRecognitionResults` response.
:rtype: dict
"""
headers = {'Content-Type': content_type}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
params = {
'model': model,
'customization_id': customization_id,
'acoustic_customization_id': acoustic_customization_id,
'customization_weight': customization_weight,
'version': version,
'base_model_version': version,
'inactivity_timeout': inactivity_timeout,
'keywords': self._convert_list(keywords),
'keywords_threshold': keywords_threshold,
'max_alternatives': max_alternatives,
'word_alternatives_threshold': word_alternatives_threshold,
'word_confidence': word_confidence,
'timestamps': timestamps,
'profanity_filter': profanity_filter,
'smart_formatting': smart_formatting,
'speaker_labels': speaker_labels
}
data = audio
url = '/v1/recognize'
response = self.request(
method='POST',
url=url,
headers=headers,
params=params,
data=data,
accept_json=True)
return response
def recognize_with_websocket(self,
audio=None,
content_type='audio/l16; rate=44100',
model='en-US_BroadbandModel',
recognize_callback=None,
customization_id=None,
acoustic_customization_id=None,
customization_weight=None,
version=None,
inactivity_timeout=None,
interim_results=True,
keywords=None,
keywords_threshold=None,
max_alternatives=1,
word_alternatives_threshold=None,
word_confidence=False,
timestamps=False,
profanity_filter=None,
smart_formatting=False,
speaker_labels=None,
**kwargs):
"""
Sends audio for speech recognition using web sockets.
:param str audio: Audio to transcribe in the format specified by the `Content-Type` header.
:param str content_type: The type of the input: audio/basic, audio/flac, audio/l16, audio/mp3, audio/mpeg, audio/mulaw, audio/ogg, audio/ogg;codecs=opus, audio/ogg;codecs=vorbis, audio/wav, audio/webm, audio/webm;codecs=opus, audio/webm;codecs=vorbis, or multipart/form-data.
:param str model: The identifier of the model to be used for the recognition request.
:param RecognizeCallback recognize_callback: The instance handling events returned from the service.
:param str customization_id: The GUID of a custom language model that is to be used with the request. The base model of the specified custom language model must match the model specified with the `model` parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom language model is used.
:param str acoustic_customization_id: The GUID of a custom acoustic model that is to be used with the request. The base model of the specified custom acoustic model must match the model specified with the `model` parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom acoustic model is used.
:param float customization_weight: If you specify a `customization_id` with the request, you can use the `customization_weight` parameter to tell the service how much weight to give to words from the custom language model compared to those from the base model for speech recognition. Specify a value between 0.0 and 1.0. Unless a different customization weight was specified for the custom model when it was trained, the default value is 0.3. A customization weight that you specify overrides a weight that was specified when the custom model was trained. The default value yields the best performance in general. Assign a higher value if your audio makes frequent use of OOV words from the custom model. Use caution when setting the weight: a higher value can improve the accuracy of phrases from the custom model's domain, but it can negatively affect performance on non-domain phrases.
:param str version: The version of the specified base `model` that is to be used for speech recognition. Multiple versions of a base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with custom models that have been upgraded for a new base model. The default value depends on whether the parameter is used with or without a custom model. For more information, see [Base model version](https://console.bluemix.net/docs/services/speech-to-text/input.html#version).
:param int inactivity_timeout: The time in seconds after which, if only silence (no speech) is detected in submitted audio, the connection is closed with a 400 error. Useful for stopping audio submission from a live microphone when a user simply walks away. Use `-1` for infinity.
:param bool interim_results: Send back non-final previews of each "sentence" as it is being processed. These results are ignored in text mode.
:param list[str] keywords: Array of keyword strings to spot in the audio. Each keyword string can include one or more tokens. Keywords are spotted only in the final hypothesis, not in interim results. If you specify any keywords, you must also specify a keywords threshold. Omit the parameter or specify an empty array if you do not need to spot keywords.
:param float keywords_threshold: Confidence value that is the lower bound for spotting a keyword. A word is considered to match a keyword if its confidence is greater than or equal to the threshold. Specify a probability between 0 and 1 inclusive. No keyword spotting is performed if you omit the parameter. If you specify a threshold, you must also specify one or more keywords.
:param int max_alternatives: Maximum number of alternative transcripts to be returned. By default, a single transcription is returned.
:param float word_alternatives_threshold: Confidence value that is the lower bound for identifying a hypothesis as a possible word alternative (also known as \"Confusion Networks\"). An alternative word is considered if its confidence is greater than or equal to the threshold. Specify a probability between 0 and 1 inclusive. No alternative words are computed if you omit the parameter.
:param bool word_confidence: If `true`, confidence measure per word is returned.
:param bool timestamps: If `true`, time alignment for each word is returned.
:param bool profanity_filter: If `true` (the default), filters profanity from all output except for keyword results by replacing inappropriate words with a series of asterisks. Set the parameter to `false` to return results with no censoring. Applies to US English transcription only.
:param bool smart_formatting: If `true`, converts dates, times, series of digits and numbers, phone numbers, currency values, and Internet addresses into more readable, conventional representations in the final transcript of a recognition request. If `false` (the default), no formatting is performed. Applies to US English transcription only.
:param bool speaker_labels: Indicates whether labels that identify which words were spoken by which participants in a multi-person exchange are to be included in the response. The default is `false`; no speaker labels are returned. Setting `speaker_labels` to `true` forces the `timestamps` parameter to be `true`, regardless of whether you specify `false` for the parameter. To determine whether a language model supports speaker labels, use the `GET /v1/models` method and check that the attribute `speaker_labels` is set to `true`. You can also refer to [Speaker labels](https://console.bluemix.net/docs/services/speech-to-text/output.html#speaker_labels).
:param dict headers: A `dict` containing the request headers
:return:
"""
if audio is None:
raise ValueError('Audio must be provided')
if recognize_callback is None:
raise ValueError('Recognize callback must be provided')
if not isinstance(recognize_callback, RecognizeCallback):
raise Exception(
'Callback is not a derived class of RecognizeCallback')
headers = {}
if self.default_headers is not None:
headers = self.default_headers.copy()
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
authstring = "{0}:{1}".format(self.username, self.password)
base64_authorization = base64.b64encode(authstring.encode('utf-8')).decode('utf-8')
headers['Authorization'] = 'Basic {0}'.format(base64_authorization)
url = self.url.replace('https:', 'wss:')
params = {
'model': model,
'customization_id': customization_id,
'acoustic_customization_id': acoustic_customization_id,
'customization_weight': customization_weight,
'version': version
}
params = _remove_null_values(params)
url = url + '/v1/recognize?{0}'.format(urlencode(params))
options = {
'content_type': content_type,
'inactivity_timeout': inactivity_timeout,
'interim_results': interim_results,
'keywords': keywords,
'keywords_threshold': keywords_threshold,
'max_alternatives': max_alternatives,
'word_alternatives_threshold': word_alternatives_threshold,
'word_confidence': word_confidence,
'timestamps': timestamps,
'profanity_filter': profanity_filter,
'smart_formatting': smart_formatting,
'speaker_labels': speaker_labels
}
options = _remove_null_values(options)
RecognizeListener(audio, options, recognize_callback, url, headers)
#########################
# Asynchronous
#########################
def check_job(self, id, **kwargs):
"""
Checks the status of the specified asynchronous job.
:param str id: The ID of the job whose status is to be checked.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `RecognitionJob` response.
:rtype: dict
"""
if id is None:
raise ValueError('id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/recognitions/{0}'.format(*self._encode_path_vars(id))
response = self.request(
method='GET', url=url, headers=headers, accept_json=True)
return response
def check_jobs(self, **kwargs):
"""
Checks the status of all asynchronous jobs.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `RecognitionJobs` response.
:rtype: dict
"""
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/recognitions'
response = self.request(
method='GET', url=url, headers=headers, accept_json=True)
return response
def create_job(self,
audio,
content_type,
model=None,
callback_url=None,
events=None,
user_token=None,
results_ttl=None,
customization_id=None,
acoustic_customization_id=None,
customization_weight=None,
version=None,
inactivity_timeout=None,
keywords=None,
keywords_threshold=None,
max_alternatives=None,
word_alternatives_threshold=None,
word_confidence=None,
timestamps=None,
profanity_filter=None,
smart_formatting=None,
speaker_labels=None,
**kwargs):
"""
Creates a job for an asynchronous recognition request.
:param str audio: Audio to transcribe in the format specified by the `Content-Type` header.
:param str content_type: The type of the input: audio/basic, audio/flac, audio/l16, audio/mp3, audio/mpeg, audio/mulaw, audio/ogg, audio/ogg;codecs=opus, audio/ogg;codecs=vorbis, audio/wav, audio/webm, audio/webm;codecs=opus, or audio/webm;codecs=vorbis.
:param str model: The identifier of the model that is to be used for the recognition request.
:param str callback_url: A URL to which callback notifications are to be sent. The URL must already be successfully white-listed by using the **Register a callback** method. Omit the parameter to poll the service for job completion and results. You can include the same callback URL with any number of job creation requests. Use the `user_token` parameter to specify a unique user-specified string with each job to differentiate the callback notifications for the jobs.
:param str events: If the job includes a callback URL, a comma-separated list of notification events to which to subscribe. Valid events are: `recognitions.started` generates a callback notification when the service begins to process the job. `recognitions.completed` generates a callback notification when the job is complete; you must use the **Check a job** method to retrieve the results before they time out or are deleted. `recognitions.completed_with_results` generates a callback notification when the job is complete; the notification includes the results of the request. `recognitions.failed` generates a callback notification if the service experiences an error while processing the job. Omit the parameter to subscribe to the default events: `recognitions.started`, `recognitions.completed`, and `recognitions.failed`. The `recognitions.completed` and `recognitions.completed_with_results` events are incompatible; you can specify only of the two events. If the job does not include a callback URL, omit the parameter.
:param str user_token: If the job includes a callback URL, a user-specified string that the service is to include with each callback notification for the job; the token allows the user to maintain an internal mapping between jobs and notification events. If the job does not include a callback URL, omit the parameter.
:param int results_ttl: The number of minutes for which the results are to be available after the job has finished. If not delivered via a callback, the results must be retrieved within this time. Omit the parameter to use a time to live of one week. The parameter is valid with or without a callback URL.
:param str customization_id: The GUID of a custom language model that is to be used with the request. The base model of the specified custom language model must match the model specified with the `model` parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom language model is used.
:param str acoustic_customization_id: The GUID of a custom acoustic model that is to be used with the request. The base model of the specified custom acoustic model must match the model specified with the `model` parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom acoustic model is used.
:param float customization_weight: If you specify a customization ID with the request, you can use the customization weight to tell the service how much weight to give to words from the custom language model compared to those from the base model for speech recognition. Specify a value between 0.0 and 1.0. Unless a different customization weight was specified for the custom model when it was trained, the default value is 0.3. A customization weight that you specify overrides a weight that was specified when the custom model was trained. The default value yields the best performance in general. Assign a higher value if your audio makes frequent use of OOV words from the custom model. Use caution when setting the weight: a higher value can improve the accuracy of phrases from the custom model's domain, but it can negatively affect performance on non-domain phrases.
:param str version: The version of the specified base `model` that is to be used with the request. Multiple versions of a base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with custom models that have been upgraded for a new base model. The default value depends on whether the parameter is used with or without a custom model. For more information, see [Base model version](https://console.bluemix.net/docs/services/speech-to-text/input.html#version).
:param int inactivity_timeout: The time in seconds after which, if only silence (no speech) is detected in submitted audio, the connection is closed with a 400 error. Useful for stopping audio submission from a live microphone when a user simply walks away. Use `-1` for infinity.
:param list[str] keywords: Array of keyword strings to spot in the audio. Each keyword string can include one or more tokens. Keywords are spotted only in the final hypothesis, not in interim results. If you specify any keywords, you must also specify a keywords threshold. You can spot a maximum of 1000 keywords. Omit the parameter or specify an empty array if you do not need to spot keywords.
:param float keywords_threshold: Confidence value that is the lower bound for spotting a keyword. A word is considered to match a keyword if its confidence is greater than or equal to the threshold. Specify a probability between 0 and 1 inclusive. No keyword spotting is performed if you omit the parameter. If you specify a threshold, you must also specify one or more keywords.
:param int max_alternatives: Maximum number of alternative transcripts to be returned. By default, a single transcription is returned.
:param float word_alternatives_threshold: Confidence value that is the lower bound for identifying a hypothesis as a possible word alternative (also known as \"Confusion Networks\"). An alternative word is considered if its confidence is greater than or equal to the threshold. Specify a probability between 0 and 1 inclusive. No alternative words are computed if you omit the parameter.
:param bool word_confidence: If `true`, confidence measure per word is returned.
:param bool timestamps: If `true`, time alignment for each word is returned.
:param bool profanity_filter: If `true` (the default), filters profanity from all output except for keyword results by replacing inappropriate words with a series of asterisks. Set the parameter to `false` to return results with no censoring. Applies to US English transcription only.
:param bool smart_formatting: If `true`, converts dates, times, series of digits and numbers, phone numbers, currency values, and Internet addresses into more readable, conventional representations in the final transcript of a recognition request. If `false` (the default), no formatting is performed. Applies to US English transcription only.
:param bool speaker_labels: Indicates whether labels that identify which words were spoken by which participants in a multi-person exchange are to be included in the response. The default is `false`; no speaker labels are returned. Setting `speaker_labels` to `true` forces the `timestamps` parameter to be `true`, regardless of whether you specify `false` for the parameter. To determine whether a language model supports speaker labels, use the **Get models** method and check that the attribute `speaker_labels` is set to `true`. You can also refer to [Speaker labels](https://console.bluemix.net/docs/services/speech-to-text/output.html#speaker_labels).
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `RecognitionJob` response.
:rtype: dict
"""
if audio is None:
raise ValueError('audio must be provided')
if content_type is None:
raise ValueError('content_type must be provided')
headers = {'Content-Type': content_type}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
params = {
'model': model,
'callback_url': callback_url,
'events': events,
'user_token': user_token,
'results_ttl': results_ttl,
'customization_id': customization_id,
'acoustic_customization_id': acoustic_customization_id,
'customization_weight': customization_weight,
'version': version,
'base_model_version': version,
'inactivity_timeout': inactivity_timeout,
'keywords': self._convert_list(keywords),
'keywords_threshold': keywords_threshold,
'max_alternatives': max_alternatives,
'word_alternatives_threshold': word_alternatives_threshold,
'word_confidence': word_confidence,
'timestamps': timestamps,
'profanity_filter': profanity_filter,
'smart_formatting': smart_formatting,
'speaker_labels': speaker_labels
}
data = audio
url = '/v1/recognitions'
response = self.request(
method='POST',
url=url,
headers=headers,
params=params,
data=data,
accept_json=True)
return response
def delete_job(self, id, **kwargs):
"""
Deletes the specified asynchronous job.
Deletes the specified job. You cannot delete a job that the service is actively
processing. Once you delete a job, its results are no longer available. The
service automatically deletes a job and its results when the time to live for the
results expires. You must submit the request with the service credentials of the
user who created the job.
:param str id: The ID of the job that is to be deleted.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if id is None:
raise ValueError('id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/recognitions/{0}'.format(*self._encode_path_vars(id))
self.request(
method='DELETE', url=url, headers=headers, accept_json=True)
return None
def register_callback(self, callback_url, user_secret=None, **kwargs):
"""
Registers a callback URL for use with the asynchronous interface.
:param str callback_url: An HTTP or HTTPS URL to which callback notifications are to be sent. To be white-listed, the URL must successfully echo the challenge string during URL verification. During verification, the client can also check the signature that the service sends in the `X-Callback-Signature` header to verify the origin of the request.
:param str user_secret: A user-specified string that the service uses to generate the HMAC-SHA1 signature that it sends via the `X-Callback-Signature` header. The service includes the header during URL verification and with every notification sent to the callback URL. It calculates the signature over the payload of the notification. If you omit the parameter, the service does not send the header.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `RegisterStatus` response.
:rtype: dict
"""
if callback_url is None:
raise ValueError('callback_url must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
params = {'callback_url': callback_url, 'user_secret': user_secret}
url = '/v1/register_callback'
response = self.request(
method='POST',
url=url,
headers=headers,
params=params,
accept_json=True)
return response
def unregister_callback(self, callback_url, **kwargs):
"""
Removes the registration for an asynchronous callback URL.
Unregisters a callback URL that was previously white-listed with a `POST
register_callback` request for use with the asynchronous interface. Once
unregistered, the URL can no longer be used with asynchronous recognition
requests.
:param str callback_url: The callback URL that is to be unregistered.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if callback_url is None:
raise ValueError('callback_url must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
params = {'callback_url': callback_url}
url = '/v1/unregister_callback'
self.request(
method='POST',
url=url,
headers=headers,
params=params,
accept_json=True)
return None
#########################
# Custom language models
#########################
def create_language_model(self,
name,
base_model_name,
dialect=None,
description=None,
**kwargs):
"""
Creates a custom language model.
Creates a new custom language model for a specified base model. The custom
language model can be used only with the base model for which it is created. The
model is owned by the instance of the service whose credentials are used to create
it.
:param str name: A user-defined name for the new custom language model. Use a name that is unique among all custom language models that you own. Use a localized name that matches the language of the custom model. Use a name that describes the domain of the custom model, such as `Medical custom model` or `Legal custom model`.
:param str base_model_name: The name of the base language model that is to be customized by the new custom language model. The new custom model can be used only with the base model that it customizes. To determine whether a base model supports language model customization, request information about the base model and check that the attribute `custom_language_model` is set to `true`, or refer to [Language support for customization](https://console.bluemix.net/docs/services/speech-to-text/custom.html#languageSupport).
:param str dialect: The dialect of the specified language that is to be used with the custom language model. The parameter is meaningful only for Spanish models, for which the service creates a custom language model that is suited for speech in one of the following dialects: * `es-ES` for Castilian Spanish (the default) * `es-LA` for Latin American Spanish * `es-US` for North American (Mexican) Spanish A specified dialect must be valid for the base model. By default, the dialect matches the language of the base model; for example, `en-US` for either of the US English language models.
:param str description: A description of the new custom language model. Use a localized description that matches the language of the custom model.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `LanguageModel` response.
:rtype: dict
"""
if name is None:
raise ValueError('name must be provided')
if base_model_name is None:
raise ValueError('base_model_name must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
data = {
'name': name,
'base_model_name': base_model_name,
'dialect': dialect,
'description': description
}
url = '/v1/customizations'
response = self.request(
method='POST',
url=url,
headers=headers,
json=data,
accept_json=True)
return response
@deprecated('Use create_language_model() instead.')
def create_custom_model(self,
name,
description="",
base_model="en-US_BroadbandModel"):
return self.create_language_model(
name, base_model, description=description)
def delete_language_model(self, customization_id, **kwargs):
"""
Deletes a custom language model.
Deletes an existing custom language model. The custom model cannot be deleted if
another request, such as adding a corpus to the model, is currently being
processed. You must use credentials for the instance of the service that owns a
model to delete it.
:param str customization_id: The GUID of the custom language model that is to be deleted. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/customizations/{0}'.format(
*self._encode_path_vars(customization_id))
self.request(
method='DELETE', url=url, headers=headers, accept_json=True)
return None
@deprecated('Use delete_language_model() instead.')
def delete_custom_model(self, modelid):
return self.delete_language_model(modelid)
def get_language_model(self, customization_id, **kwargs):
"""
Lists information about a custom language model.
Lists information about a specified custom language model. You must use
credentials for the instance of the service that owns a model to list information
about it.
:param str customization_id: The GUID of the custom language model for which information is to be returned. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `LanguageModel` response.
:rtype: dict
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/customizations/{0}'.format(
*self._encode_path_vars(customization_id))
response = self.request(
method='GET', url=url, headers=headers, accept_json=True)
return response
@deprecated('Use get_language_model() instead.')
def get_custom_model(self, modelid):
return self.get_language_model(modelid)
def list_language_models(self, language=None, **kwargs):
"""
Lists information about all custom language models.
Lists information about all custom language models that are owned by an instance
of the service. Use the `language` parameter to see all custom language models for
the specified language; omit the parameter to see all custom language models for
all languages. You must use credentials for the instance of the service that owns
a model to list information about it.
:param str language: The identifier of the language for which custom language models are to be returned (for example, `en-US`). Omit the parameter to see all custom language models owned by the requesting service credentials.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `LanguageModels` response.
:rtype: dict
"""
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
params = {'language': language}
url = '/v1/customizations'
response = self.request(
method='GET',
url=url,
headers=headers,
params=params,
accept_json=True)
return response
@deprecated('Use list_language_models() instead.')
def list_custom_models(self):
return self.list_language_models()
def reset_language_model(self, customization_id, **kwargs):
"""
Resets a custom language model.
Resets a custom language model by removing all corpora and words from the model.
Resetting a custom language model initializes the model to its state when it was
first created. Metadata such as the name and language of the model are preserved,
but the model's words resource is removed and must be re-created. You must use
credentials for the instance of the service that owns a model to reset it.
:param str customization_id: The GUID of the custom language model that is to be reset. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/customizations/{0}/reset'.format(
*self._encode_path_vars(customization_id))
self.request(method='POST', url=url, headers=headers, accept_json=True)
return None
def train_language_model(self,
customization_id,
word_type_to_add=None,
customization_weight=None,
**kwargs):
"""
Trains a custom language model.
:param str customization_id: The GUID of the custom language model that is to be trained. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param str word_type_to_add: The type of words from the custom language model's words resource on which to train the model: * `all` (the default) trains the model on all new words, regardless of whether they were extracted from corpora or were added or modified by the user. * `user` trains the model only on new words that were added or modified by the user; the model is not trained on new words extracted from corpora.
:param float customization_weight: Specifies a customization weight for the custom language model. The customization weight tells the service how much weight to give to words from the custom language model compared to those from the base model for speech recognition. Specify a value between 0.0 and 1.0. The default value is 0.3. The default value yields the best performance in general. Assign a higher value if your audio makes frequent use of OOV words from the custom model. Use caution when setting the weight: a higher value can improve the accuracy of phrases from the custom model's domain, but it can negatively affect performance on non-domain phrases. The value that you assign is used for all recognition requests that use the model. You can override it for any recognition request by specifying a customization weight for that request.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
params = {
'word_type_to_add': word_type_to_add,
'customization_weight': customization_weight
}
url = '/v1/customizations/{0}/train'.format(
*self._encode_path_vars(customization_id))
self.request(
method='POST',
url=url,
headers=headers,
params=params,
accept_json=True)
return None
@deprecated('Use train_language_model() instead.')
def train_custom_model(self,
customization_id,
customization_weight=None,
word_type=None):
self.train_language_model(customization_id, word_type,
customization_weight)
def upgrade_language_model(self, customization_id, **kwargs):
"""
Upgrades a custom language model.
:param str customization_id: The GUID of the custom language model that is to be upgraded. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/customizations/{0}/upgrade_model'.format(
*self._encode_path_vars(customization_id))
self.request(method='POST', url=url, headers=headers, accept_json=True)
return None
#########################
# Custom corpora
#########################
def add_corpus(self,
customization_id,
corpus_name,
corpus_file,
allow_overwrite=None,
corpus_file_content_type=None,
corpus_filename=None,
**kwargs):
"""
Adds a corpus text file to a custom language model.
:param str customization_id: The GUID of the custom language model to which a corpus is to be added. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param str corpus_name: The name of the corpus that is to be added to the custom language model. The name cannot contain spaces and cannot be the string `user`, which is reserved by the service to denote custom words added or modified by the user. Use a localized name that matches the language of the custom model.
:param file corpus_file: A plain text file that contains the training data for the corpus. Encode the file in UTF-8 if it contains non-ASCII characters; the service assumes UTF-8 encoding if it encounters non-ASCII characters. With cURL, use the `--data-binary` option to upload the file for the request.
:param bool allow_overwrite: Indicates whether the specified corpus is to overwrite an existing corpus with the same name. If a corpus with the same name already exists, the request fails unless `allow_overwrite` is set to `true`; by default, the parameter is `false`. The parameter has no effect if a corpus with the same name does not already exist.
:param str corpus_file_content_type: The content type of corpus_file.
:param str corpus_filename: The filename for corpus_file.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
if corpus_name is None:
raise ValueError('corpus_name must be provided')
if corpus_file is None:
raise ValueError('corpus_file must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
params = {'allow_overwrite': allow_overwrite}
if not corpus_filename and hasattr(corpus_file, 'name'):
corpus_filename = corpus_file.name
mime_type = corpus_file_content_type or 'application/octet-stream'
corpus_file_tuple = (corpus_filename, corpus_file, mime_type)
url = '/v1/customizations/{0}/corpora/{1}'.format(
*self._encode_path_vars(customization_id, corpus_name))
self.request(
method='POST',
url=url,
headers=headers,
params=params,
files={'corpus_file': corpus_file_tuple},
accept_json=True)
return None
def delete_corpus(self, customization_id, corpus_name, **kwargs):
"""
Deletes a corpus from a custom language model.
:param str customization_id: The GUID of the custom language model from which a corpus is to be deleted. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param str corpus_name: The name of the corpus that is to be deleted from the custom language model.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
if corpus_name is None:
raise ValueError('corpus_name must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/customizations/{0}/corpora/{1}'.format(
*self._encode_path_vars(customization_id, corpus_name))
self.request(
method='DELETE', url=url, headers=headers, accept_json=True)
return None
def get_corpus(self, customization_id, corpus_name, **kwargs):
"""
Lists information about a corpus for a custom language model.
Lists information about a corpus from a custom language model. The information
includes the total number of words and out-of-vocabulary (OOV) words, name, and
status of the corpus. You must use credentials for the instance of the service
that owns a model to list its corpora.
:param str customization_id: The GUID of the custom language model for which a corpus is to be listed. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param str corpus_name: The name of the corpus about which information is to be listed.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `Corpus` response.
:rtype: dict
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
if corpus_name is None:
raise ValueError('corpus_name must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/customizations/{0}/corpora/{1}'.format(
*self._encode_path_vars(customization_id, corpus_name))
response = self.request(
method='GET', url=url, headers=headers, accept_json=True)
return response
def list_corpora(self, customization_id, **kwargs):
"""
Lists information about all corpora for a custom language model.
Lists information about all corpora from a custom language model. The information
includes the total number of words and out-of-vocabulary (OOV) words, name, and
status of each corpus. You must use credentials for the instance of the service
that owns a model to list its corpora.
:param str customization_id: The GUID of the custom language model for which corpora are to be listed. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `Corpora` response.
:rtype: dict
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/customizations/{0}/corpora'.format(
*self._encode_path_vars(customization_id))
response = self.request(
method='GET', url=url, headers=headers, accept_json=True)
return response
#########################
# Custom words
#########################
def add_word(self,
customization_id,
word_name,
sounds_like=None,
display_as=None,
**kwargs):
"""
Adds a custom word to a custom language model.
:param str customization_id: The GUID of the custom language model to which a word is to be added. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param str word_name: The custom word that is to be added to or updated in the custom model. Do not include spaces in the word. Use a - (dash) or _ (underscore) to connect the tokens of compound words.
:param list[str] sounds_like: An array of sounds-like pronunciations for the custom word. Specify how words that are difficult to pronounce, foreign words, acronyms, and so on can be pronounced by users. For a word that is not in the service's base vocabulary, omit the parameter to have the service automatically generate a sounds-like pronunciation for the word. For a word that is in the service's base vocabulary, use the parameter to specify additional pronunciations for the word. You cannot override the default pronunciation of a word; pronunciations you add augment the pronunciation from the base vocabulary. A word can have at most five sounds-like pronunciations, and a pronunciation can include at most 40 characters not including spaces.
:param str display_as: An alternative spelling for the custom word when it appears in a transcript. Use the parameter when you want the word to have a spelling that is different from its usual representation or from its spelling in corpora training data.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
if word_name is None:
raise ValueError('word_name must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
data = {
'word': word_name,
'sounds_like': sounds_like,
'display_as': display_as
}
url = '/v1/customizations/{0}/words/{1}'.format(
*self._encode_path_vars(customization_id, word_name))
self.request(
method='PUT',
url=url,
headers=headers,
json=data,
accept_json=True)
return None
@deprecated('Use add_word instead.')
def add_custom_word(self, customization_id, custom_word):
return self.add_word(customization_id, custom_word)
def add_words(self, customization_id, words, **kwargs):
"""
Adds one or more custom words to a custom language model.
:param str customization_id: The GUID of the custom language model to which words are to be added. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param list[CustomWord] words: An array of objects that provides information about each custom word that is to be added to or updated in the custom language model.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
if words is None:
raise ValueError('words must be provided')
words = [self._convert_model(x, CustomWord) for x in words]
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
data = {'words': words}
url = '/v1/customizations/{0}/words'.format(
*self._encode_path_vars(customization_id))
self.request(
method='POST',
url=url,
headers=headers,
json=data,
accept_json=True)
return None
@deprecated('Use add_words() instead.')
def add_custom_words(self, customization_id, custom_words):
return self.add_words(customization_id, custom_words)
def delete_word(self, customization_id, word_name, **kwargs):
"""
Deletes a custom word from a custom language model.
:param str customization_id: The GUID of the custom language model from which a word is to be deleted. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param str word_name: The custom word that is to be deleted from the custom language model.
:param dict headers: A `dict` containing the request headers
:rtype: None
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
if word_name is None:
raise ValueError('word_name must be provided')
headers = {}
if 'headers' in kwargs:
headers.update(kwargs.get('headers'))
url = '/v1/customizations/{0}/words/{1}'.format(
*self._encode_path_vars(customization_id, word_name))
self.request(
method='DELETE', url=url, headers=headers, accept_json=True)
return None
@deprecated('Use delete_word() instead.')
def delete_custom_word(self, customization_id, custom_word):
return self.delete_word(customization_id, custom_word)
def get_word(self, customization_id, word_name, **kwargs):
"""
Lists a custom word from a custom language model.
Lists information about a custom word from a custom language model. You must use
credentials for the instance of the service that owns a model to query information
about its words.
:param str customization_id: The GUID of the custom language model from which a word is to be queried. You must make the request with service credentials created for the instance of the service that owns the custom model.
:param str word_name: The custom word that is to be queried from the custom language model.
:param dict headers: A `dict` containing the request headers
:return: A `dict` containing the `Word` response.
:rtype: dict
"""
if customization_id is None:
raise ValueError('customization_id must be provided')
if word_name is None:
raise ValueError('word_name must be provided')
headers = {}