-
Notifications
You must be signed in to change notification settings - Fork 124
/
SpeechToTextService.cs
4950 lines (4632 loc) · 262 KB
/
SpeechToTextService.cs
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
/**
* (C) Copyright IBM Corp. 2016, 2020.
*
* 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.
*
*/
/**
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-8d569e8f-20201109-230115
*/
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text;
using IBM.Cloud.SDK.Core.Authentication;
using IBM.Cloud.SDK.Core.Http;
using IBM.Cloud.SDK.Core.Http.Extensions;
using IBM.Cloud.SDK.Core.Service;
using IBM.Watson.SpeechToText.v1.Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
namespace IBM.Watson.SpeechToText.v1
{
public partial class SpeechToTextService : IBMService, ISpeechToTextService
{
const string defaultServiceName = "speech_to_text";
private const string defaultServiceUrl = "https://api.us-south.speech-to-text.watson.cloud.ibm.com";
public SpeechToTextService() : this(defaultServiceName, ConfigBasedAuthenticatorFactory.GetAuthenticator(defaultServiceName)) { }
public SpeechToTextService(IAuthenticator authenticator) : this(defaultServiceName, authenticator) {}
public SpeechToTextService(string serviceName) : this(serviceName, ConfigBasedAuthenticatorFactory.GetAuthenticator(serviceName)) { }
public SpeechToTextService(IClient httpClient) : base(defaultServiceName, httpClient) { }
public SpeechToTextService(string serviceName, IAuthenticator authenticator) : base(serviceName, authenticator)
{
if (string.IsNullOrEmpty(ServiceUrl))
{
SetServiceUrl(defaultServiceUrl);
}
}
/// <summary>
/// List models.
///
/// Lists 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. The ordering of the list of models can
/// change from call to call; do not rely on an alphabetized or static list of models.
///
/// **See also:** [Languages and
/// models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models#models).
/// </summary>
/// <returns><see cref="SpeechModels" />SpeechModels</returns>
public DetailedResponse<SpeechModels> ListModels()
{
DetailedResponse<SpeechModels> result = null;
try
{
IClient client = this.Client;
SetAuthentication();
var restRequest = client.GetAsync($"{this.Endpoint}/v1/models");
restRequest.WithHeader("Accept", "application/json");
restRequest.WithHeaders(Common.GetSdkHeaders("speech_to_text", "v1", "ListModels"));
restRequest.WithHeaders(customRequestHeaders);
ClearCustomRequestHeaders();
result = restRequest.As<SpeechModels>().Result;
if (result == null)
{
result = new DetailedResponse<SpeechModels>();
}
}
catch (AggregateException ae)
{
throw ae.Flatten();
}
return result;
}
/// <summary>
/// Get a model.
///
/// Gets information for 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.
///
/// **See also:** [Languages and
/// models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models#models).
/// </summary>
/// <param name="modelId">The identifier of the model in the form of its name from the output of the **Get a
/// model** method.</param>
/// <returns><see cref="SpeechModel" />SpeechModel</returns>
public DetailedResponse<SpeechModel> GetModel(string modelId)
{
if (string.IsNullOrEmpty(modelId))
{
throw new ArgumentNullException("`modelId` is required for `GetModel`");
}
else
{
modelId = Uri.EscapeDataString(modelId);
}
DetailedResponse<SpeechModel> result = null;
try
{
IClient client = this.Client;
SetAuthentication();
var restRequest = client.GetAsync($"{this.Endpoint}/v1/models/{modelId}");
restRequest.WithHeader("Accept", "application/json");
restRequest.WithHeaders(Common.GetSdkHeaders("speech_to_text", "v1", "GetModel"));
restRequest.WithHeaders(customRequestHeaders);
ClearCustomRequestHeaders();
result = restRequest.As<SpeechModel>().Result;
if (result == null)
{
result = new DetailedResponse<SpeechModel>();
}
}
catch (AggregateException ae)
{
throw ae.Flatten();
}
return result;
}
/// <summary>
/// Enum values for GetModel.
/// </summary>
public class GetModelEnums
{
/// <summary>
/// The identifier of the model in the form of its name from the output of the **Get a model** method.
/// </summary>
public class ModelIdValue
{
/// <summary>
/// Constant AR_AR_BROADBANDMODEL for ar-AR_BroadbandModel
/// </summary>
public const string AR_AR_BROADBANDMODEL = "ar-AR_BroadbandModel";
/// <summary>
/// Constant DE_DE_BROADBANDMODEL for de-DE_BroadbandModel
/// </summary>
public const string DE_DE_BROADBANDMODEL = "de-DE_BroadbandModel";
/// <summary>
/// Constant DE_DE_NARROWBANDMODEL for de-DE_NarrowbandModel
/// </summary>
public const string DE_DE_NARROWBANDMODEL = "de-DE_NarrowbandModel";
/// <summary>
/// Constant EN_AU_BROADBANDMODEL for en-AU_BroadbandModel
/// </summary>
public const string EN_AU_BROADBANDMODEL = "en-AU_BroadbandModel";
/// <summary>
/// Constant EN_AU_NARROWBANDMODEL for en-AU_NarrowbandModel
/// </summary>
public const string EN_AU_NARROWBANDMODEL = "en-AU_NarrowbandModel";
/// <summary>
/// Constant EN_GB_BROADBANDMODEL for en-GB_BroadbandModel
/// </summary>
public const string EN_GB_BROADBANDMODEL = "en-GB_BroadbandModel";
/// <summary>
/// Constant EN_GB_NARROWBANDMODEL for en-GB_NarrowbandModel
/// </summary>
public const string EN_GB_NARROWBANDMODEL = "en-GB_NarrowbandModel";
/// <summary>
/// Constant EN_US_BROADBANDMODEL for en-US_BroadbandModel
/// </summary>
public const string EN_US_BROADBANDMODEL = "en-US_BroadbandModel";
/// <summary>
/// Constant EN_US_NARROWBANDMODEL for en-US_NarrowbandModel
/// </summary>
public const string EN_US_NARROWBANDMODEL = "en-US_NarrowbandModel";
/// <summary>
/// Constant EN_US_SHORTFORM_NARROWBANDMODEL for en-US_ShortForm_NarrowbandModel
/// </summary>
public const string EN_US_SHORTFORM_NARROWBANDMODEL = "en-US_ShortForm_NarrowbandModel";
/// <summary>
/// Constant ES_AR_BROADBANDMODEL for es-AR_BroadbandModel
/// </summary>
public const string ES_AR_BROADBANDMODEL = "es-AR_BroadbandModel";
/// <summary>
/// Constant ES_AR_NARROWBANDMODEL for es-AR_NarrowbandModel
/// </summary>
public const string ES_AR_NARROWBANDMODEL = "es-AR_NarrowbandModel";
/// <summary>
/// Constant ES_CL_BROADBANDMODEL for es-CL_BroadbandModel
/// </summary>
public const string ES_CL_BROADBANDMODEL = "es-CL_BroadbandModel";
/// <summary>
/// Constant ES_CL_NARROWBANDMODEL for es-CL_NarrowbandModel
/// </summary>
public const string ES_CL_NARROWBANDMODEL = "es-CL_NarrowbandModel";
/// <summary>
/// Constant ES_CO_BROADBANDMODEL for es-CO_BroadbandModel
/// </summary>
public const string ES_CO_BROADBANDMODEL = "es-CO_BroadbandModel";
/// <summary>
/// Constant ES_CO_NARROWBANDMODEL for es-CO_NarrowbandModel
/// </summary>
public const string ES_CO_NARROWBANDMODEL = "es-CO_NarrowbandModel";
/// <summary>
/// Constant ES_ES_BROADBANDMODEL for es-ES_BroadbandModel
/// </summary>
public const string ES_ES_BROADBANDMODEL = "es-ES_BroadbandModel";
/// <summary>
/// Constant ES_ES_NARROWBANDMODEL for es-ES_NarrowbandModel
/// </summary>
public const string ES_ES_NARROWBANDMODEL = "es-ES_NarrowbandModel";
/// <summary>
/// Constant ES_MX_BROADBANDMODEL for es-MX_BroadbandModel
/// </summary>
public const string ES_MX_BROADBANDMODEL = "es-MX_BroadbandModel";
/// <summary>
/// Constant ES_MX_NARROWBANDMODEL for es-MX_NarrowbandModel
/// </summary>
public const string ES_MX_NARROWBANDMODEL = "es-MX_NarrowbandModel";
/// <summary>
/// Constant ES_PE_BROADBANDMODEL for es-PE_BroadbandModel
/// </summary>
public const string ES_PE_BROADBANDMODEL = "es-PE_BroadbandModel";
/// <summary>
/// Constant ES_PE_NARROWBANDMODEL for es-PE_NarrowbandModel
/// </summary>
public const string ES_PE_NARROWBANDMODEL = "es-PE_NarrowbandModel";
/// <summary>
/// Constant FR_CA_BROADBANDMODEL for fr-CA_BroadbandModel
/// </summary>
public const string FR_CA_BROADBANDMODEL = "fr-CA_BroadbandModel";
/// <summary>
/// Constant FR_CA_NARROWBANDMODEL for fr-CA_NarrowbandModel
/// </summary>
public const string FR_CA_NARROWBANDMODEL = "fr-CA_NarrowbandModel";
/// <summary>
/// Constant FR_FR_BROADBANDMODEL for fr-FR_BroadbandModel
/// </summary>
public const string FR_FR_BROADBANDMODEL = "fr-FR_BroadbandModel";
/// <summary>
/// Constant FR_FR_NARROWBANDMODEL for fr-FR_NarrowbandModel
/// </summary>
public const string FR_FR_NARROWBANDMODEL = "fr-FR_NarrowbandModel";
/// <summary>
/// Constant IT_IT_BROADBANDMODEL for it-IT_BroadbandModel
/// </summary>
public const string IT_IT_BROADBANDMODEL = "it-IT_BroadbandModel";
/// <summary>
/// Constant IT_IT_NARROWBANDMODEL for it-IT_NarrowbandModel
/// </summary>
public const string IT_IT_NARROWBANDMODEL = "it-IT_NarrowbandModel";
/// <summary>
/// Constant JA_JP_BROADBANDMODEL for ja-JP_BroadbandModel
/// </summary>
public const string JA_JP_BROADBANDMODEL = "ja-JP_BroadbandModel";
/// <summary>
/// Constant JA_JP_NARROWBANDMODEL for ja-JP_NarrowbandModel
/// </summary>
public const string JA_JP_NARROWBANDMODEL = "ja-JP_NarrowbandModel";
/// <summary>
/// Constant KO_KR_BROADBANDMODEL for ko-KR_BroadbandModel
/// </summary>
public const string KO_KR_BROADBANDMODEL = "ko-KR_BroadbandModel";
/// <summary>
/// Constant KO_KR_NARROWBANDMODEL for ko-KR_NarrowbandModel
/// </summary>
public const string KO_KR_NARROWBANDMODEL = "ko-KR_NarrowbandModel";
/// <summary>
/// Constant NL_NL_BROADBANDMODEL for nl-NL_BroadbandModel
/// </summary>
public const string NL_NL_BROADBANDMODEL = "nl-NL_BroadbandModel";
/// <summary>
/// Constant NL_NL_NARROWBANDMODEL for nl-NL_NarrowbandModel
/// </summary>
public const string NL_NL_NARROWBANDMODEL = "nl-NL_NarrowbandModel";
/// <summary>
/// Constant PT_BR_BROADBANDMODEL for pt-BR_BroadbandModel
/// </summary>
public const string PT_BR_BROADBANDMODEL = "pt-BR_BroadbandModel";
/// <summary>
/// Constant PT_BR_NARROWBANDMODEL for pt-BR_NarrowbandModel
/// </summary>
public const string PT_BR_NARROWBANDMODEL = "pt-BR_NarrowbandModel";
/// <summary>
/// Constant ZH_CN_BROADBANDMODEL for zh-CN_BroadbandModel
/// </summary>
public const string ZH_CN_BROADBANDMODEL = "zh-CN_BroadbandModel";
/// <summary>
/// Constant ZH_CN_NARROWBANDMODEL for zh-CN_NarrowbandModel
/// </summary>
public const string ZH_CN_NARROWBANDMODEL = "zh-CN_NarrowbandModel";
}
}
/// <summary>
/// Recognize audio.
///
/// Sends audio and returns transcription results for a recognition request. You can pass a maximum of 100 MB
/// and a minimum of 100 bytes of audio with a request. The service automatically detects the endianness of the
/// incoming audio and, for audio that includes multiple channels, downmixes the audio to one-channel mono
/// during transcoding. The method returns only final results; to enable interim results, use the WebSocket API.
/// (With the `curl` command, use the `--data-binary` option to upload the file for the request.)
///
/// **See also:** [Making a basic HTTP
/// request](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-http#HTTP-basic).
///
/// ### Streaming mode
///
/// For requests to transcribe live audio as it becomes available, you must set the `Transfer-Encoding` header
/// to `chunked` to use streaming mode. In streaming mode, the service closes the connection (status code 408)
/// if it does not receive at least 15 seconds of audio (including silence) in any 30-second period. The service
/// also closes the connection (status code 400) if it detects no speech for `inactivity_timeout` seconds of
/// streaming audio; use the `inactivity_timeout` parameter to change the default of 30 seconds.
///
/// **See also:**
/// * [Audio transmission](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#transmission)
/// * [Timeouts](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#timeouts)
///
/// ### Audio formats (content types)
///
/// The service accepts audio in the following formats (MIME types).
/// * For formats that are labeled **Required**, you must use the `Content-Type` header with the request to
/// specify the format of the audio.
/// * For all other formats, you can omit the `Content-Type` header or specify `application/octet-stream` with
/// the header to have the service automatically detect the format of the audio. (With the `curl` command, you
/// can specify either `"Content-Type:"` or `"Content-Type: application/octet-stream"`.)
///
/// Where indicated, the format that you specify must include the sampling rate and can optionally include the
/// number of channels and the endianness of the audio.
/// * `audio/alaw` (**Required.** Specify the sampling rate (`rate`) of the audio.)
/// * `audio/basic` (**Required.** Use only with narrowband models.)
/// * `audio/flac`
/// * `audio/g729` (Use only with narrowband models.)
/// * `audio/l16` (**Required.** Specify the sampling rate (`rate`) and optionally the number of channels
/// (`channels`) and endianness (`endianness`) of the audio.)
/// * `audio/mp3`
/// * `audio/mpeg`
/// * `audio/mulaw` (**Required.** Specify the sampling rate (`rate`) of the audio.)
/// * `audio/ogg` (The service automatically detects the codec of the input audio.)
/// * `audio/ogg;codecs=opus`
/// * `audio/ogg;codecs=vorbis`
/// * `audio/wav` (Provide audio with a maximum of nine channels.)
/// * `audio/webm` (The service automatically detects the codec of the input audio.)
/// * `audio/webm;codecs=opus`
/// * `audio/webm;codecs=vorbis`
///
/// The sampling rate of the audio must match the sampling rate of the model for the recognition request: for
/// broadband models, at least 16 kHz; for narrowband models, at least 8 kHz. If the sampling rate of the audio
/// is higher than the minimum required rate, the service down-samples the audio to the appropriate rate. If the
/// sampling rate of the audio is lower than the minimum required rate, the request fails.
///
/// **See also:** [Audio
/// formats](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-audio-formats#audio-formats).
///
/// ### Multipart speech recognition
///
/// **Note:** The Watson SDKs do not support multipart speech recognition.
///
/// The HTTP `POST` method of the service also supports multipart speech recognition. With multipart requests,
/// you pass all audio data as multipart form data. You specify some parameters as request headers and query
/// parameters, but you pass JSON metadata as form data to control most aspects of the transcription. You can
/// use multipart recognition to pass multiple audio files with a single request.
///
/// Use the multipart approach with browsers for which JavaScript is disabled or when the parameters used with
/// the request are greater than the 8 KB limit imposed by most HTTP servers and proxies. You can encounter this
/// limit, for example, if you want to spot a very large number of keywords.
///
/// **See also:** [Making a multipart HTTP
/// request](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-http#HTTP-multi).
/// </summary>
/// <param name="audio">The audio to transcribe.</param>
/// <param name="contentType">The format (MIME type) of the audio. For more information about specifying an
/// audio format, see **Audio formats (content types)** in the method description. (optional)</param>
/// <param name="model">The identifier of the model that is to be used for the recognition request. See
/// [Languages and models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models#models).
/// (optional, default to en-US_BroadbandModel)</param>
/// <param name="languageCustomizationId">The customization ID (GUID) of a custom language model that is to be
/// used with the recognition 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 credentials for the instance of
/// the service that owns the custom model. By default, no custom language model is used. See [Custom
/// models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#custom-input).
///
/// **Note:** Use this parameter instead of the deprecated `customization_id` parameter. (optional)</param>
/// <param name="acousticCustomizationId">The customization ID (GUID) of a custom acoustic model that is to be
/// used with the recognition 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 credentials for the instance of
/// the service that owns the custom model. By default, no custom acoustic model is used. See [Custom
/// models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#custom-input).
/// (optional)</param>
/// <param name="baseModelVersion">The version of the specified base model that is to be used with the
/// recognition 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.
/// See [Base model version](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#version).
/// (optional)</param>
/// <param name="customizationWeight">If you specify the customization ID (GUID) of a custom language model with
/// the recognition request, 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 the current request.
///
/// 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.
///
/// See [Custom models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#custom-input).
/// (optional)</param>
/// <param name="inactivityTimeout">The time in seconds after which, if only silence (no speech) is detected in
/// streaming audio, the connection is closed with a 400 error. The parameter is useful for stopping audio
/// submission from a live microphone when a user simply walks away. Use `-1` for infinity. See [Inactivity
/// timeout](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#timeouts-inactivity).
/// (optional)</param>
/// <param name="keywords">An array of keyword strings to spot in the audio. Each keyword string can include one
/// or more string tokens. Keywords are spotted only in the final results, not in interim hypotheses. 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.
///
/// You can spot a maximum of 1000 keywords with a single request. A single keyword can have a maximum length of
/// 1024 characters, though the maximum effective length for double-byte languages might be shorter. Keywords
/// are case-insensitive.
///
/// See [Keyword
/// spotting](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#keyword_spotting).
/// (optional)</param>
/// <param name="keywordsThreshold">A 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.0 and 1.0. If you specify a threshold, you must also specify one or more keywords. The
/// service performs no keyword spotting if you omit either parameter. See [Keyword
/// spotting](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#keyword_spotting).
/// (optional)</param>
/// <param name="maxAlternatives">The maximum number of alternative transcripts that the service is to return.
/// By default, the service returns a single transcript. If you specify a value of `0`, the service uses the
/// default value, `1`. See [Maximum
/// alternatives](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#max_alternatives).
/// (optional)</param>
/// <param name="wordAlternativesThreshold">A 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.0
/// and 1.0. By default, the service computes no alternative words. See [Word
/// alternatives](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#word_alternatives).
/// (optional)</param>
/// <param name="wordConfidence">If `true`, the service returns a confidence measure in the range of 0.0 to 1.0
/// for each word. By default, the service returns no word confidence scores. See [Word
/// confidence](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#word_confidence).
/// (optional, default to false)</param>
/// <param name="timestamps">If `true`, the service returns time alignment for each word. By default, no
/// timestamps are returned. See [Word
/// timestamps](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#word_timestamps).
/// (optional, default to false)</param>
/// <param name="profanityFilter">If `true`, the service 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. See [Profanity
/// filtering](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#profanity_filter).
/// (optional, default to true)</param>
/// <param name="smartFormatting">If `true`, the service 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. For US English, the service also converts certain keyword
/// strings to punctuation symbols. By default, the service performs no smart formatting.
///
/// **Note:** Applies to US English, Japanese, and Spanish transcription only.
///
/// See [Smart
/// formatting](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#smart_formatting).
/// (optional, default to false)</param>
/// <param name="speakerLabels">If `true`, the response includes labels that identify which words were spoken by
/// which participants in a multi-person exchange. By default, the service returns no speaker labels. Setting
/// `speaker_labels` to `true` forces the `timestamps` parameter to be `true`, regardless of whether you specify
/// `false` for the parameter.
///
/// **Note:** Applies to US English, Australian English, German, Japanese, Korean, and Spanish (both broadband
/// and narrowband models) and UK English (narrowband model) transcription only.
///
/// See [Speaker labels](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#speaker_labels).
/// (optional, default to false)</param>
/// <param name="customizationId">**Deprecated.** Use the `language_customization_id` parameter to specify the
/// customization ID (GUID) of a custom language model that is to be used with the recognition request. Do not
/// specify both parameters with a request. (optional)</param>
/// <param name="grammarName">The name of a grammar that is to be used with the recognition request. If you
/// specify a grammar, you must also use the `language_customization_id` parameter to specify the name of the
/// custom language model for which the grammar is defined. The service recognizes only strings that are
/// recognized by the specified grammar; it does not recognize other custom words from the model's words
/// resource. See
/// [Grammars](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#grammars-input).
/// (optional)</param>
/// <param name="redaction">If `true`, the service redacts, or masks, numeric data from final transcripts. The
/// feature redacts any number that has three or more consecutive digits by replacing each digit with an `X`
/// character. It is intended to redact sensitive numeric data, such as credit card numbers. By default, the
/// service performs no redaction.
///
/// When you enable redaction, the service automatically enables smart formatting, regardless of whether you
/// explicitly disable that feature. To ensure maximum security, the service also disables keyword spotting
/// (ignores the `keywords` and `keywords_threshold` parameters) and returns only a single final transcript
/// (forces the `max_alternatives` parameter to be `1`).
///
/// **Note:** Applies to US English, Japanese, and Korean transcription only.
///
/// See [Numeric redaction](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#redaction).
/// (optional, default to false)</param>
/// <param name="audioMetrics">If `true`, requests detailed information about the signal characteristics of the
/// input audio. The service returns audio metrics with the final transcription results. By default, the service
/// returns no audio metrics.
///
/// See [Audio metrics](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-metrics#audio_metrics).
/// (optional, default to false)</param>
/// <param name="endOfPhraseSilenceTime">If `true`, specifies the duration of the pause interval at which the
/// service splits a transcript into multiple final results. If the service detects pauses or extended silence
/// before it reaches the end of the audio stream, its response can include multiple final results. Silence
/// indicates a point at which the speaker pauses between spoken words or phrases.
///
/// Specify a value for the pause interval in the range of 0.0 to 120.0.
/// * A value greater than 0 specifies the interval that the service is to use for speech recognition.
/// * A value of 0 indicates that the service is to use the default interval. It is equivalent to omitting the
/// parameter.
///
/// The default pause interval for most languages is 0.8 seconds; the default for Chinese is 0.6 seconds.
///
/// See [End of phrase silence
/// time](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#silence_time).
/// (optional)</param>
/// <param name="splitTranscriptAtPhraseEnd">If `true`, directs the service to split the transcript into
/// multiple final results based on semantic features of the input, for example, at the conclusion of meaningful
/// phrases such as sentences. The service bases its understanding of semantic features on the base language
/// model that you use with a request. Custom language models and grammars can also influence how and where the
/// service splits a transcript. By default, the service splits transcripts based solely on the pause interval.
///
/// See [Split transcript at phrase
/// end](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#split_transcript). (optional,
/// default to false)</param>
/// <param name="speechDetectorSensitivity">The sensitivity of speech activity detection that the service is to
/// perform. Use the parameter to suppress word insertions from music, coughing, and other non-speech events.
/// The service biases the audio it passes for speech recognition by evaluating the input audio against prior
/// models of speech and non-speech activity.
///
/// Specify a value between 0.0 and 1.0:
/// * 0.0 suppresses all audio (no speech is transcribed).
/// * 0.5 (the default) provides a reasonable compromise for the level of sensitivity.
/// * 1.0 suppresses no audio (speech detection sensitivity is disabled).
///
/// The values increase on a monotonic curve. See [Speech Activity
/// Detection](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#detection).
/// (optional)</param>
/// <param name="backgroundAudioSuppression">The level to which the service is to suppress background audio
/// based on its volume to prevent it from being transcribed as speech. Use the parameter to suppress side
/// conversations or background noise.
///
/// Specify a value in the range of 0.0 to 1.0:
/// * 0.0 (the default) provides no suppression (background audio suppression is disabled).
/// * 0.5 provides a reasonable level of audio suppression for general usage.
/// * 1.0 suppresses all audio (no audio is transcribed).
///
/// The values increase on a monotonic curve. See [Speech Activity
/// Detection](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#detection).
/// (optional)</param>
/// <returns><see cref="SpeechRecognitionResults" />SpeechRecognitionResults</returns>
public DetailedResponse<SpeechRecognitionResults> Recognize(System.IO.MemoryStream audio, string contentType = null, string model = null, string languageCustomizationId = null, string acousticCustomizationId = null, string baseModelVersion = null, double? customizationWeight = null, long? inactivityTimeout = null, List<string> keywords = null, float? keywordsThreshold = null, long? maxAlternatives = null, float? wordAlternativesThreshold = null, bool? wordConfidence = null, bool? timestamps = null, bool? profanityFilter = null, bool? smartFormatting = null, bool? speakerLabels = null, string customizationId = null, string grammarName = null, bool? redaction = null, bool? audioMetrics = null, double? endOfPhraseSilenceTime = null, bool? splitTranscriptAtPhraseEnd = null, float? speechDetectorSensitivity = null, float? backgroundAudioSuppression = null)
{
if (audio == null)
{
throw new ArgumentNullException("`audio` is required for `Recognize`");
}
DetailedResponse<SpeechRecognitionResults> result = null;
try
{
IClient client = this.Client;
SetAuthentication();
var restRequest = client.PostAsync($"{this.Endpoint}/v1/recognize");
restRequest.WithHeader("Accept", "application/json");
if (!string.IsNullOrEmpty(contentType))
{
restRequest.WithHeader("Content-Type", contentType);
}
if (!string.IsNullOrEmpty(model))
{
restRequest.WithArgument("model", model);
}
if (!string.IsNullOrEmpty(languageCustomizationId))
{
restRequest.WithArgument("language_customization_id", languageCustomizationId);
}
if (!string.IsNullOrEmpty(acousticCustomizationId))
{
restRequest.WithArgument("acoustic_customization_id", acousticCustomizationId);
}
if (!string.IsNullOrEmpty(baseModelVersion))
{
restRequest.WithArgument("base_model_version", baseModelVersion);
}
if (customizationWeight != null)
{
restRequest.WithArgument("customization_weight", customizationWeight);
}
if (inactivityTimeout != null)
{
restRequest.WithArgument("inactivity_timeout", inactivityTimeout);
}
if (keywords != null && keywords.Count > 0)
{
restRequest.WithArgument("keywords", string.Join(",", keywords.ToArray()));
}
if (keywordsThreshold != null)
{
restRequest.WithArgument("keywords_threshold", keywordsThreshold);
}
if (maxAlternatives != null)
{
restRequest.WithArgument("max_alternatives", maxAlternatives);
}
if (wordAlternativesThreshold != null)
{
restRequest.WithArgument("word_alternatives_threshold", wordAlternativesThreshold);
}
if (wordConfidence != null)
{
restRequest.WithArgument("word_confidence", wordConfidence);
}
if (timestamps != null)
{
restRequest.WithArgument("timestamps", timestamps);
}
if (profanityFilter != null)
{
restRequest.WithArgument("profanity_filter", profanityFilter);
}
if (smartFormatting != null)
{
restRequest.WithArgument("smart_formatting", smartFormatting);
}
if (speakerLabels != null)
{
restRequest.WithArgument("speaker_labels", speakerLabels);
}
if (!string.IsNullOrEmpty(customizationId))
{
restRequest.WithArgument("customization_id", customizationId);
}
if (!string.IsNullOrEmpty(grammarName))
{
restRequest.WithArgument("grammar_name", grammarName);
}
if (redaction != null)
{
restRequest.WithArgument("redaction", redaction);
}
if (audioMetrics != null)
{
restRequest.WithArgument("audio_metrics", audioMetrics);
}
if (endOfPhraseSilenceTime != null)
{
restRequest.WithArgument("end_of_phrase_silence_time", endOfPhraseSilenceTime);
}
if (splitTranscriptAtPhraseEnd != null)
{
restRequest.WithArgument("split_transcript_at_phrase_end", splitTranscriptAtPhraseEnd);
}
if (speechDetectorSensitivity != null)
{
restRequest.WithArgument("speech_detector_sensitivity", speechDetectorSensitivity);
}
if (backgroundAudioSuppression != null)
{
restRequest.WithArgument("background_audio_suppression", backgroundAudioSuppression);
}
var httpContent = new ByteArrayContent(audio.ToArray());
System.Net.Http.Headers.MediaTypeHeaderValue audioContentType;
System.Net.Http.Headers.MediaTypeHeaderValue.TryParse(contentType, out audioContentType);
httpContent.Headers.ContentType = audioContentType;
restRequest.WithBodyContent(httpContent);
restRequest.WithHeaders(Common.GetSdkHeaders("speech_to_text", "v1", "Recognize"));
restRequest.WithHeaders(customRequestHeaders);
ClearCustomRequestHeaders();
result = restRequest.As<SpeechRecognitionResults>().Result;
if (result == null)
{
result = new DetailedResponse<SpeechRecognitionResults>();
}
}
catch (AggregateException ae)
{
throw ae.Flatten();
}
return result;
}
/// <summary>
/// Enum values for Recognize.
/// </summary>
public class RecognizeEnums
{
/// <summary>
/// The format (MIME type) of the audio. For more information about specifying an audio format, see **Audio
/// formats (content types)** in the method description.
/// </summary>
public class ContentTypeValue
{
/// <summary>
/// Constant APPLICATION_OCTET_STREAM for application/octet-stream
/// </summary>
public const string APPLICATION_OCTET_STREAM = "application/octet-stream";
/// <summary>
/// Constant AUDIO_ALAW for audio/alaw
/// </summary>
public const string AUDIO_ALAW = "audio/alaw";
/// <summary>
/// Constant AUDIO_BASIC for audio/basic
/// </summary>
public const string AUDIO_BASIC = "audio/basic";
/// <summary>
/// Constant AUDIO_FLAC for audio/flac
/// </summary>
public const string AUDIO_FLAC = "audio/flac";
/// <summary>
/// Constant AUDIO_G729 for audio/g729
/// </summary>
public const string AUDIO_G729 = "audio/g729";
/// <summary>
/// Constant AUDIO_L16 for audio/l16
/// </summary>
public const string AUDIO_L16 = "audio/l16";
/// <summary>
/// Constant AUDIO_MP3 for audio/mp3
/// </summary>
public const string AUDIO_MP3 = "audio/mp3";
/// <summary>
/// Constant AUDIO_MPEG for audio/mpeg
/// </summary>
public const string AUDIO_MPEG = "audio/mpeg";
/// <summary>
/// Constant AUDIO_MULAW for audio/mulaw
/// </summary>
public const string AUDIO_MULAW = "audio/mulaw";
/// <summary>
/// Constant AUDIO_OGG for audio/ogg
/// </summary>
public const string AUDIO_OGG = "audio/ogg";
/// <summary>
/// Constant AUDIO_OGG_CODECS_OPUS for audio/ogg;codecs=opus
/// </summary>
public const string AUDIO_OGG_CODECS_OPUS = "audio/ogg;codecs=opus";
/// <summary>
/// Constant AUDIO_OGG_CODECS_VORBIS for audio/ogg;codecs=vorbis
/// </summary>
public const string AUDIO_OGG_CODECS_VORBIS = "audio/ogg;codecs=vorbis";
/// <summary>
/// Constant AUDIO_WAV for audio/wav
/// </summary>
public const string AUDIO_WAV = "audio/wav";
/// <summary>
/// Constant AUDIO_WEBM for audio/webm
/// </summary>
public const string AUDIO_WEBM = "audio/webm";
/// <summary>
/// Constant AUDIO_WEBM_CODECS_OPUS for audio/webm;codecs=opus
/// </summary>
public const string AUDIO_WEBM_CODECS_OPUS = "audio/webm;codecs=opus";
/// <summary>
/// Constant AUDIO_WEBM_CODECS_VORBIS for audio/webm;codecs=vorbis
/// </summary>
public const string AUDIO_WEBM_CODECS_VORBIS = "audio/webm;codecs=vorbis";
}
/// <summary>
/// The identifier of the model that is to be used for the recognition request. See [Languages and
/// models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models#models).
/// </summary>
public class ModelValue
{
/// <summary>
/// Constant AR_AR_BROADBANDMODEL for ar-AR_BroadbandModel
/// </summary>
public const string AR_AR_BROADBANDMODEL = "ar-AR_BroadbandModel";
/// <summary>
/// Constant DE_DE_BROADBANDMODEL for de-DE_BroadbandModel
/// </summary>
public const string DE_DE_BROADBANDMODEL = "de-DE_BroadbandModel";
/// <summary>
/// Constant DE_DE_NARROWBANDMODEL for de-DE_NarrowbandModel
/// </summary>
public const string DE_DE_NARROWBANDMODEL = "de-DE_NarrowbandModel";
/// <summary>
/// Constant EN_AU_BROADBANDMODEL for en-AU_BroadbandModel
/// </summary>
public const string EN_AU_BROADBANDMODEL = "en-AU_BroadbandModel";
/// <summary>
/// Constant EN_AU_NARROWBANDMODEL for en-AU_NarrowbandModel
/// </summary>
public const string EN_AU_NARROWBANDMODEL = "en-AU_NarrowbandModel";
/// <summary>
/// Constant EN_GB_BROADBANDMODEL for en-GB_BroadbandModel
/// </summary>
public const string EN_GB_BROADBANDMODEL = "en-GB_BroadbandModel";
/// <summary>
/// Constant EN_GB_NARROWBANDMODEL for en-GB_NarrowbandModel
/// </summary>
public const string EN_GB_NARROWBANDMODEL = "en-GB_NarrowbandModel";
/// <summary>
/// Constant EN_US_BROADBANDMODEL for en-US_BroadbandModel
/// </summary>
public const string EN_US_BROADBANDMODEL = "en-US_BroadbandModel";
/// <summary>
/// Constant EN_US_NARROWBANDMODEL for en-US_NarrowbandModel
/// </summary>
public const string EN_US_NARROWBANDMODEL = "en-US_NarrowbandModel";
/// <summary>
/// Constant EN_US_SHORTFORM_NARROWBANDMODEL for en-US_ShortForm_NarrowbandModel
/// </summary>
public const string EN_US_SHORTFORM_NARROWBANDMODEL = "en-US_ShortForm_NarrowbandModel";
/// <summary>
/// Constant ES_AR_BROADBANDMODEL for es-AR_BroadbandModel
/// </summary>
public const string ES_AR_BROADBANDMODEL = "es-AR_BroadbandModel";
/// <summary>
/// Constant ES_AR_NARROWBANDMODEL for es-AR_NarrowbandModel
/// </summary>
public const string ES_AR_NARROWBANDMODEL = "es-AR_NarrowbandModel";
/// <summary>
/// Constant ES_CL_BROADBANDMODEL for es-CL_BroadbandModel
/// </summary>
public const string ES_CL_BROADBANDMODEL = "es-CL_BroadbandModel";
/// <summary>
/// Constant ES_CL_NARROWBANDMODEL for es-CL_NarrowbandModel
/// </summary>
public const string ES_CL_NARROWBANDMODEL = "es-CL_NarrowbandModel";
/// <summary>
/// Constant ES_CO_BROADBANDMODEL for es-CO_BroadbandModel
/// </summary>
public const string ES_CO_BROADBANDMODEL = "es-CO_BroadbandModel";
/// <summary>
/// Constant ES_CO_NARROWBANDMODEL for es-CO_NarrowbandModel
/// </summary>
public const string ES_CO_NARROWBANDMODEL = "es-CO_NarrowbandModel";
/// <summary>
/// Constant ES_ES_BROADBANDMODEL for es-ES_BroadbandModel
/// </summary>
public const string ES_ES_BROADBANDMODEL = "es-ES_BroadbandModel";
/// <summary>
/// Constant ES_ES_NARROWBANDMODEL for es-ES_NarrowbandModel
/// </summary>
public const string ES_ES_NARROWBANDMODEL = "es-ES_NarrowbandModel";
/// <summary>
/// Constant ES_MX_BROADBANDMODEL for es-MX_BroadbandModel
/// </summary>
public const string ES_MX_BROADBANDMODEL = "es-MX_BroadbandModel";
/// <summary>
/// Constant ES_MX_NARROWBANDMODEL for es-MX_NarrowbandModel
/// </summary>
public const string ES_MX_NARROWBANDMODEL = "es-MX_NarrowbandModel";
/// <summary>
/// Constant ES_PE_BROADBANDMODEL for es-PE_BroadbandModel
/// </summary>
public const string ES_PE_BROADBANDMODEL = "es-PE_BroadbandModel";
/// <summary>
/// Constant ES_PE_NARROWBANDMODEL for es-PE_NarrowbandModel
/// </summary>
public const string ES_PE_NARROWBANDMODEL = "es-PE_NarrowbandModel";
/// <summary>
/// Constant FR_CA_BROADBANDMODEL for fr-CA_BroadbandModel
/// </summary>
public const string FR_CA_BROADBANDMODEL = "fr-CA_BroadbandModel";
/// <summary>
/// Constant FR_CA_NARROWBANDMODEL for fr-CA_NarrowbandModel
/// </summary>
public const string FR_CA_NARROWBANDMODEL = "fr-CA_NarrowbandModel";
/// <summary>
/// Constant FR_FR_BROADBANDMODEL for fr-FR_BroadbandModel
/// </summary>
public const string FR_FR_BROADBANDMODEL = "fr-FR_BroadbandModel";
/// <summary>
/// Constant FR_FR_NARROWBANDMODEL for fr-FR_NarrowbandModel
/// </summary>
public const string FR_FR_NARROWBANDMODEL = "fr-FR_NarrowbandModel";
/// <summary>
/// Constant IT_IT_BROADBANDMODEL for it-IT_BroadbandModel
/// </summary>
public const string IT_IT_BROADBANDMODEL = "it-IT_BroadbandModel";
/// <summary>
/// Constant IT_IT_NARROWBANDMODEL for it-IT_NarrowbandModel
/// </summary>
public const string IT_IT_NARROWBANDMODEL = "it-IT_NarrowbandModel";
/// <summary>
/// Constant JA_JP_BROADBANDMODEL for ja-JP_BroadbandModel
/// </summary>
public const string JA_JP_BROADBANDMODEL = "ja-JP_BroadbandModel";
/// <summary>
/// Constant JA_JP_NARROWBANDMODEL for ja-JP_NarrowbandModel
/// </summary>
public const string JA_JP_NARROWBANDMODEL = "ja-JP_NarrowbandModel";
/// <summary>
/// Constant KO_KR_BROADBANDMODEL for ko-KR_BroadbandModel
/// </summary>
public const string KO_KR_BROADBANDMODEL = "ko-KR_BroadbandModel";
/// <summary>
/// Constant KO_KR_NARROWBANDMODEL for ko-KR_NarrowbandModel
/// </summary>
public const string KO_KR_NARROWBANDMODEL = "ko-KR_NarrowbandModel";
/// <summary>
/// Constant NL_NL_BROADBANDMODEL for nl-NL_BroadbandModel
/// </summary>
public const string NL_NL_BROADBANDMODEL = "nl-NL_BroadbandModel";
/// <summary>
/// Constant NL_NL_NARROWBANDMODEL for nl-NL_NarrowbandModel
/// </summary>
public const string NL_NL_NARROWBANDMODEL = "nl-NL_NarrowbandModel";
/// <summary>
/// Constant PT_BR_BROADBANDMODEL for pt-BR_BroadbandModel
/// </summary>
public const string PT_BR_BROADBANDMODEL = "pt-BR_BroadbandModel";
/// <summary>
/// Constant PT_BR_NARROWBANDMODEL for pt-BR_NarrowbandModel
/// </summary>
public const string PT_BR_NARROWBANDMODEL = "pt-BR_NarrowbandModel";
/// <summary>
/// Constant ZH_CN_BROADBANDMODEL for zh-CN_BroadbandModel
/// </summary>
public const string ZH_CN_BROADBANDMODEL = "zh-CN_BroadbandModel";
/// <summary>
/// Constant ZH_CN_NARROWBANDMODEL for zh-CN_NarrowbandModel
/// </summary>
public const string ZH_CN_NARROWBANDMODEL = "zh-CN_NarrowbandModel";
}
}
/// <summary>
/// Register a callback.
///
/// Registers a callback URL with the service for use with subsequent asynchronous recognition requests. The
/// service attempts to register, or allowlist, the callback URL if it is not already registered by sending a
/// `GET` request to the callback URL. The service passes a random alphanumeric challenge string via the
/// `challenge_string` parameter of the request. The request includes an `Accept` header that specifies
/// `text/plain` as the required response type.
///
/// To be registered successfully, the callback URL must respond to the `GET` request from the service. The
/// response must send status code 200 and must include the challenge string in its body. Set the `Content-Type`
/// response header to `text/plain`. Upon receiving this response, the service responds to the original
/// registration request with response code 201.
///
/// The service sends only a single `GET` request to the callback URL. If the service does not receive a reply
/// with a response code of 200 and a body that echoes the challenge string sent by the service within five
/// seconds, it does not allowlist the URL; it instead sends status code 400 in response to the **Register a
/// callback** request. If the requested callback URL is already allowlisted, the service responds to the
/// initial registration request with response code 200.
///
/// If you specify a user secret with the request, the service uses it as a key to calculate an HMAC-SHA1
/// signature of the challenge string in its response to the `POST` request. It sends this signature in the
/// `X-Callback-Signature` header of its `GET` request to the URL during registration. It also uses the secret
/// to calculate a signature over the payload of every callback notification that uses the URL. The signature
/// provides authentication and data integrity for HTTP communications.
///
/// After you successfully register a callback URL, you can use it with an indefinite number of recognition
/// requests. You can register a maximum of 20 callback URLS in a one-hour span of time.
///
/// **See also:** [Registering a callback
/// URL](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-async#register).
/// </summary>
/// <param name="callbackUrl">An HTTP or HTTPS URL to which callback notifications are to be sent. To be
/// allowlisted, 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>
/// <param name="userSecret">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. (optional)</param>
/// <returns><see cref="RegisterStatus" />RegisterStatus</returns>
public DetailedResponse<RegisterStatus> RegisterCallback(string callbackUrl, string userSecret = null)
{
if (string.IsNullOrEmpty(callbackUrl))
{
throw new ArgumentNullException("`callbackUrl` is required for `RegisterCallback`");
}
DetailedResponse<RegisterStatus> result = null;