/
speech_to_text_v1.rb
3509 lines (3299 loc) · 196 KB
/
speech_to_text_v1.rb
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
# frozen_string_literal: true
# (C) Copyright IBM Corp. 2018, 2022.
#
# 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: 3.38.0-07189efd-20210827-205025
#
# The IBM Watson™ Speech to Text service provides APIs that use IBM's
# speech-recognition capabilities to produce transcripts of spoken audio. The service can
# transcribe speech from various languages and audio formats. In addition to basic
# transcription, the service can produce detailed information about many different aspects
# of the audio. It returns all JSON response content in the UTF-8 character set.
#
# The service supports two types of models: previous-generation models that include the
# terms `Broadband` and `Narrowband` in their names, and next-generation models that
# include the terms `Multimedia` and `Telephony` in their names. Broadband and multimedia
# models have minimum sampling rates of 16 kHz. Narrowband and telephony models have
# minimum sampling rates of 8 kHz. The next-generation models offer high throughput and
# greater transcription accuracy.
#
# Effective 15 March 2022, previous-generation models for all languages other than Arabic
# and Japanese are deprecated. The deprecated models remain available until 15 September
# 2022, when they will be removed from the service and the documentation. You must migrate
# to the equivalent next-generation model by the end of service date. For more
# information, see [Migrating to next-generation
# models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-migrate).{:
# deprecated}
#
# For speech recognition, the service supports synchronous and asynchronous HTTP
# Representational State Transfer (REST) interfaces. It also supports a WebSocket
# interface that provides a full-duplex, low-latency communication channel: Clients send
# requests and audio to the service and receive results over a single connection
# asynchronously.
#
# The service also offers two customization interfaces. Use language model customization
# to expand the vocabulary of a base model with domain-specific terminology. Use acoustic
# model customization to adapt a base model for the acoustic characteristics of your
# audio. For language model customization, the service also supports grammars. A grammar
# is a formal language specification that lets you restrict the phrases that the service
# can recognize.
#
# Language model customization and grammars are available for most previous- and
# next-generation models. Acoustic model customization is available for all
# previous-generation models.
require "concurrent"
require "erb"
require "json"
require "ibm_cloud_sdk_core"
require_relative "./common.rb"
module IBMWatson
##
# The Speech to Text V1 service.
class SpeechToTextV1 < IBMCloudSdkCore::BaseService
include Concurrent::Async
DEFAULT_SERVICE_NAME = "speech_to_text"
DEFAULT_SERVICE_URL = "https://api.us-south.speech-to-text.watson.cloud.ibm.com"
##
# @!method initialize(args)
# Construct a new client for the Speech to Text service.
#
# @param args [Hash] The args to initialize with
# @option args service_url [String] The base service URL to use when contacting the service.
# The base service_url may differ between IBM Cloud regions.
# @option args authenticator [Object] The Authenticator instance to be configured for this service.
# @option args service_name [String] The name of the service to configure. Will be used as the key to load
# any external configuration, if applicable.
def initialize(args = {})
@__async_initialized__ = false
defaults = {}
defaults[:service_url] = DEFAULT_SERVICE_URL
defaults[:service_name] = DEFAULT_SERVICE_NAME
defaults[:authenticator] = nil
user_service_url = args[:service_url] unless args[:service_url].nil?
args = defaults.merge(args)
args[:authenticator] = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: args[:service_name]) if args[:authenticator].nil?
super
@service_url = user_service_url unless user_service_url.nil?
end
#########################
# Models
#########################
##
# @!method list_models
# 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:** [Listing all
# models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-list#models-list-all).
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def list_models
headers = {
}
sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "list_models")
headers.merge!(sdk_headers)
method_url = "/v1/models"
response = request(
method: "GET",
url: method_url,
headers: headers,
accept_json: true
)
response
end
##
# @!method get_model(model_id:)
# 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:** [Listing a specific
# model](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-list#models-list-specific).
# @param model_id [String] The identifier of the model in the form of its name from the output of the [List
# models](#listmodels) method. (**Note:** The model `ar-AR_BroadbandModel` is
# deprecated; use `ar-MS_BroadbandModel` instead.).
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def get_model(model_id:)
raise ArgumentError.new("model_id must be provided") if model_id.nil?
headers = {
}
sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "get_model")
headers.merge!(sdk_headers)
method_url = "/v1/models/%s" % [ERB::Util.url_encode(model_id)]
response = request(
method: "GET",
url: method_url,
headers: headers,
accept_json: true
)
response
end
#########################
# Synchronous
#########################
##
# @!method recognize(audio:, content_type: nil, model: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, audio_metrics: nil, end_of_phrase_silence_time: nil, split_transcript_at_phrase_end: nil, speech_detector_sensitivity: nil, background_audio_suppression: nil, low_latency: nil)
# 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:** [Supported audio
# formats](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-audio-formats).
#
#
# ### Next-generation models
#
# The service supports next-generation `Multimedia` (16 kHz) and `Telephony` (8
# kHz) models for many languages. Next-generation models have higher throughput than
# the service's previous generation of `Broadband` and `Narrowband` models. When you
# use next-generation models, the service can return transcriptions more quickly and
# also provide noticeably better transcription accuracy.
#
# You specify a next-generation model by using the `model` query parameter, as you
# do a previous-generation model. Many next-generation models also support the
# `low_latency` parameter, which is not available with previous-generation models.
# Next-generation models do not support all of the parameters that are available for
# use with previous-generation models.
#
# **Important:** Effective 15 March 2022, previous-generation models for all
# languages other than Arabic and Japanese are deprecated. The deprecated models
# remain available until 15 September 2022, when they will be removed from the
# service and the documentation. You must migrate to the equivalent next-generation
# model by the end of service date. For more information, see [Migrating to
# next-generation
# models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-migrate).
#
#
# **See also:**
# * [Next-generation languages and
# models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-ng)
# * [Supported features for next-generation
# models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-ng#models-ng-features)
#
#
# ### Multipart speech recognition
#
# **Note:** The asynchronous HTTP interface, WebSocket interface, and 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).
# @param audio [File] The audio to transcribe.
# @param content_type [String] The format (MIME type) of the audio. For more information about specifying an
# audio format, see **Audio formats (content types)** in the method description.
# @param model [String] The identifier of the model that is to be used for the recognition request.
# (**Note:** The model `ar-AR_BroadbandModel` is deprecated; use
# `ar-MS_BroadbandModel` instead.) See [Using a model for speech
# recognition](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-use).
# @param language_customization_id [String] 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 [Using a custom language model for
# speech
# recognition](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-languageUse).
#
#
# **Note:** Use this parameter instead of the deprecated `customization_id`
# parameter.
# @param acoustic_customization_id [String] 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 [Using a custom acoustic model for
# speech
# recognition](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-acousticUse).
# @param base_model_version [String] 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 [Making speech
# recognition requests with upgraded custom
# models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-custom-upgrade-use#custom-upgrade-use-recognition).
# @param customization_weight [Float] 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 [Using customization
# weight](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-languageUse#weight).
# @param inactivity_timeout [Fixnum] 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).
# @param keywords [Array[String]] 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-spotting#keyword-spotting).
# @param keywords_threshold [Float] 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-spotting#keyword-spotting).
# @param max_alternatives [Fixnum] 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-metadata#max-alternatives).
# @param word_alternatives_threshold [Float] 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-spotting#word-alternatives).
# @param word_confidence [Boolean] 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-metadata#word-confidence).
# @param timestamps [Boolean] 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-metadata#word-timestamps).
# @param profanity_filter [Boolean] 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.
#
# **Note:** The parameter can be used with US English and Japanese transcription
# only. See [Profanity
# filtering](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-formatting#profanity-filtering).
# @param smart_formatting [Boolean] 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:** The parameter can be used with US English, Japanese, and Spanish (all
# dialects) transcription only.
#
# See [Smart
# formatting](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-formatting#smart-formatting).
# @param speaker_labels [Boolean] 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.
# * _For previous-generation models,_ the parameter can be used with Australian
# English, US English, German, Japanese, Korean, and Spanish (both broadband and
# narrowband models) and UK English (narrowband model) transcription only.
# * _For next-generation models,_ the parameter can be used with Czech, English
# (Australian, Indian, UK, and US), German, Japanese, Korean, and Spanish
# transcription only.
#
# See [Speaker
# labels](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-speaker-labels).
# @param customization_id [String] **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.
# @param grammar_name [String] 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 [Using a grammar for speech
# recognition](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-grammarUse).
# @param redaction [Boolean] 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:** The parameter can be used with US English, Japanese, and Korean
# transcription only.
#
# See [Numeric
# redaction](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-formatting#numeric-redaction).
# @param audio_metrics [Boolean] 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).
# @param end_of_phrase_silence_time [Float] 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-parsing#silence-time).
# @param split_transcript_at_phrase_end [Boolean] 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. If
# the parameters are used together on the same request, `end_of_phrase_silence_time`
# has precedence over `split_transcript_at_phrase_end`.
#
# See [Split transcript at phrase
# end](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-parsing#split-transcript).
# @param speech_detector_sensitivity [Float] 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.
#
# The parameter is supported with all next-generation models and with most
# previous-generation models. See [Speech detector
# sensitivity](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-detection#detection-parameters-sensitivity)
# and [Language model
# support](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-detection#detection-support).
# @param background_audio_suppression [Float] 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.
#
# The parameter is supported with all next-generation models and with most
# previous-generation models. See [Background audio
# suppression](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-detection#detection-parameters-suppression)
# and [Language model
# support](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-detection#detection-support).
# @param low_latency [Boolean] If `true` for next-generation `Multimedia` and `Telephony` models that support low
# latency, directs the service to produce results even more quickly than it usually
# does. Next-generation models produce transcription results faster than
# previous-generation models. The `low_latency` parameter causes the models to
# produce results even more quickly, though the results might be less accurate when
# the parameter is used.
#
# The parameter is not available for previous-generation `Broadband` and
# `Narrowband` models. It is available only for some next-generation models. For a
# list of next-generation models that support low latency, see [Supported
# next-generation language
# models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-ng#models-ng-supported).
# * For more information about the `low_latency` parameter, see [Low
# latency](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-interim#low-latency).
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def recognize(audio:, content_type: nil, model: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, audio_metrics: nil, end_of_phrase_silence_time: nil, split_transcript_at_phrase_end: nil, speech_detector_sensitivity: nil, background_audio_suppression: nil, low_latency: nil)
raise ArgumentError.new("audio must be provided") if audio.nil?
headers = {
"Content-Type" => content_type
}
sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "recognize")
headers.merge!(sdk_headers)
keywords *= "," unless keywords.nil?
params = {
"model" => model,
"language_customization_id" => language_customization_id,
"acoustic_customization_id" => acoustic_customization_id,
"base_model_version" => base_model_version,
"customization_weight" => customization_weight,
"inactivity_timeout" => inactivity_timeout,
"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,
"customization_id" => customization_id,
"grammar_name" => grammar_name,
"redaction" => redaction,
"audio_metrics" => audio_metrics,
"end_of_phrase_silence_time" => end_of_phrase_silence_time,
"split_transcript_at_phrase_end" => split_transcript_at_phrase_end,
"speech_detector_sensitivity" => speech_detector_sensitivity,
"background_audio_suppression" => background_audio_suppression,
"low_latency" => low_latency
}
data = audio
method_url = "/v1/recognize"
response = request(
method: "POST",
url: method_url,
headers: headers,
params: params,
data: data,
accept_json: true
)
response
end
##
# @!method recognize_using_websocket(content_type: nil,recognize_callback:,audio: nil,chunk_data: false,model: nil,customization_id: nil,acoustic_customization_id: nil,customization_weight: nil,base_model_version: nil,inactivity_timeout: nil,interim_results: nil,keywords: nil,keywords_threshold: nil,max_alternatives: nil,word_alternatives_threshold: nil,word_confidence: nil,timestamps: nil,profanity_filter: nil,smart_formatting: nil,speaker_labels: nil, end_of_phrase_silence_time: nil, split_transcript_at_phrase_end: nil, speech_detector_sensitivity: nil, background_audio_suppression: nil, low_latency: nil)
# Sends audio for speech recognition using web sockets.
# @param content_type [String] 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 recognize_callback [RecognizeCallback] The instance handling events returned from the service.
# @param audio [IO] Audio to transcribe in the format specified by the `Content-Type` header.
# @param chunk_data [Boolean] If true, then the WebSocketClient will expect to receive data in chunks rather than as a single audio file
# @param model [String] The identifier of the model to be used for the recognition request.
# @param customization_id [String] 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 acoustic_customization_id [String] 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 language_customization_id [String] 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 base_model_version [String] 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://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-input#version).
# @param inactivity_timeout [Integer] 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 interim_results [Boolean] Send back non-final previews of each "sentence" as it is being processed. These results are ignored in text mode.
# @param keywords [Array<String>] 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 keywords_threshold [Float] 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 max_alternatives [Integer] Maximum number of alternative transcripts to be returned. By default, a single transcription is returned.
# @param word_alternatives_threshold [Float] 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 word_confidence [Boolean] If `true`, confidence measure per word is returned.
# @param timestamps [Boolean] If `true`, time alignment for each word is returned.
# @param profanity_filter [Boolean] 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 smart_formatting [Boolean] 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 speaker_labels [Boolean] 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://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-output#speaker_labels).
# @param grammar_name [String] 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/output.html).
# @param redaction [Boolean] 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).
#
# @param processing_metrics [Boolean] If `true`, requests processing metrics about the service's transcription of the
# input audio. The service returns processing metrics at the interval specified by
# the `processing_metrics_interval` parameter. It also returns processing metrics
# for transcription events, for example, for final and interim results. By default,
# the service returns no processing metrics.
# @param processing_metrics_interval [Float] Specifies the interval in real wall-clock seconds at which the service is to
# return processing metrics. The parameter is ignored unless the
# `processing_metrics` parameter is set to `true`. # The parameter accepts a minimum value of 0.1 seconds. The level of precision is
# not restricted, so you can specify values such as 0.25 and 0.125.
#
# The service does not impose a maximum value. If you want to receive processing
# metrics only for transcription events instead of at periodic intervals, set the
# value to a large number. If the value is larger than the duration of the audio,
# the service returns processing metrics only for transcription events.
# @param audio_metrics [Boolean] 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.
# @return [WebSocketClient] Returns a new WebSocketClient object
#
# See [Audio
# metrics](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-metrics#audio_metrics).
# @param end_of_phrase_silence_time [Float] 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).
# @param split_transcript_at_phrase_end [Boolean] 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).
# @param speech_detector_sensitivity [Float] 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).
# @param background_audio_suppression [Float] 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).
# @param low_latency [Boolean] If `true` for next-generation `Multimedia` and `Telephony` models that support low
# latency, directs the service to produce results even more quickly than it usually
# does. Next-generation models produce transcription results faster than
# previous-generation models. The `low_latency` parameter causes the models to
# produce results even more quickly, though the results might be less accurate when
# the parameter is used.
#
# **Note:** The parameter is beta functionality. It is not available for
# previous-generation `Broadband` and `Narrowband` models. It is available only for
# some next-generation models.
#
# * For a list of next-generation models that support low latency, see [Supported
# language
# models](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-models-ng#models-ng-supported)
# for next-generation models.
# * For more information about the `low_latency` parameter, see [Low
# latency](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-interim#low-latency).
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def recognize_using_websocket(
content_type: nil,
recognize_callback:,
audio: nil,
chunk_data: false,
model: nil,
language_customization_id: nil,
customization_id: nil,
acoustic_customization_id: nil,
customization_weight: nil,
base_model_version: nil,
inactivity_timeout: nil,
interim_results: nil,
keywords: nil,
keywords_threshold: nil,
max_alternatives: nil,
word_alternatives_threshold: nil,
word_confidence: nil,
timestamps: nil,
profanity_filter: nil,
smart_formatting: nil,
speaker_labels: nil,
grammar_name: nil,
redaction: nil,
processing_metrics: nil,
processing_metrics_interval: nil,
audio_metrics: nil,
end_of_phrase_silence_time: nil,
split_transcript_at_phrase_end: nil,
speech_detector_sensitivity: nil,
background_audio_suppression: nil,
low_latency: nil
)
raise ArgumentError("Audio must be provided") if audio.nil? && !chunk_data
raise ArgumentError("Recognize callback must be provided") if recognize_callback.nil?
raise TypeError("Callback is not a derived class of RecognizeCallback") unless recognize_callback.is_a?(IBMWatson::RecognizeCallback)
require_relative("./websocket/speech_to_text_websocket_listener.rb")
headers = {}
headers = conn.default_options.headers.to_hash unless conn.default_options.headers.to_hash.empty?
@authenticator.authenticate(headers)
service_url = @service_url.gsub("https:", "wss:")
params = {
"model" => model,
"customization_id" => customization_id,
"language_customization_id" => language_customization_id,
"acoustic_customization_id" => acoustic_customization_id,
"customization_weight" => customization_weight,
"base_model_version" => base_model_version
}
params.delete_if { |_, v| v.nil? }
service_url += "/v1/recognize?" + HTTP::URI.form_encode(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,
"grammar_name" => grammar_name,
"redaction" => redaction,
"processing_metrics" => processing_metrics,
"processing_metrics_interval" => processing_metrics_interval,
"audio_metrics" => audio_metrics,
"end_of_phrase_silence_time" => end_of_phrase_silence_time,
"split_transcript_at_phrase_end" => split_transcript_at_phrase_end,
"speech_detector_sensitivity" => speech_detector_sensitivity,
"background_audio_suppression" => background_audio_suppression,
"low_latency" => low_latency
}
options.delete_if { |_, v| v.nil? }
WebSocketClient.new(audio: audio, chunk_data: chunk_data, options: options, recognize_callback: recognize_callback, service_url: service_url, headers: headers, disable_ssl_verification: @disable_ssl_verification)
end
#########################
# Asynchronous
#########################
##
# @!method register_callback(callback_url:, user_secret: nil)
# 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 request to register a
# callback. 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).
# @param callback_url [String] 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 user_secret [String] 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.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def register_callback(callback_url:, user_secret: nil)
raise ArgumentError.new("callback_url must be provided") if callback_url.nil?
headers = {
}
sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "register_callback")
headers.merge!(sdk_headers)
params = {
"callback_url" => callback_url,
"user_secret" => user_secret
}
method_url = "/v1/register_callback"
response = request(
method: "POST",
url: method_url,
headers: headers,
params: params,
accept_json: true
)
response
end
##
# @!method unregister_callback(callback_url:)
# Unregister a callback.
# Unregisters a callback URL that was previously allowlisted with a [Register a
# callback](#registercallback) request for use with the asynchronous interface. Once
# unregistered, the URL can no longer be used with asynchronous recognition
# requests.
#
# **See also:** [Unregistering a callback
# URL](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-async#unregister).
# @param callback_url [String] The callback URL that is to be unregistered.
# @return [nil]
def unregister_callback(callback_url:)
raise ArgumentError.new("callback_url must be provided") if callback_url.nil?
headers = {
}
sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "unregister_callback")
headers.merge!(sdk_headers)
params = {
"callback_url" => callback_url
}
method_url = "/v1/unregister_callback"
request(
method: "POST",
url: method_url,
headers: headers,
params: params,
accept_json: false
)
nil
end
##
# @!method create_job(audio:, content_type: nil, model: nil, callback_url: nil, events: nil, user_token: nil, results_ttl: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, processing_metrics: nil, processing_metrics_interval: nil, audio_metrics: nil, end_of_phrase_silence_time: nil, split_transcript_at_phrase_end: nil, speech_detector_sensitivity: nil, background_audio_suppression: nil, low_latency: nil)
# Create a job.
# Creates a job for a new asynchronous recognition request. The job is owned by the
# instance of the service whose credentials are used to create it. How you learn the
# status and results of a job depends on the parameters you include with the job
# creation request:
# * By callback notification: Include the `callback_url` parameter to specify a URL
# to which the service is to send callback notifications when the status of the job
# changes. Optionally, you can also include the `events` and `user_token` parameters
# to subscribe to specific events and to specify a string that is to be included
# with each notification for the job.
# * By polling the service: Omit the `callback_url`, `events`, and `user_token`
# parameters. You must then use the [Check jobs](#checkjobs) or [Check a
# job](#checkjob) methods to check the status of the job, using the latter to
# retrieve the results when the job is complete.
#
# The two approaches are not mutually exclusive. You can poll the service for job
# status or obtain results from the service manually even if you include a callback
# URL. In both cases, you can include the `results_ttl` parameter to specify how
# long the results are to remain available after the job is complete. Using the
# HTTPS [Check a job](#checkjob) method to retrieve results is more secure than
# receiving them via callback notification over HTTP because it provides
# confidentiality in addition to authentication and data integrity.
#
# The method supports the same basic parameters as other HTTP and WebSocket
# recognition requests. It also supports the following parameters specific to the
# asynchronous interface:
# * `callback_url`
# * `events`
# * `user_token`
# * `results_ttl`
#
# You can pass a maximum of 1 GB 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:** [Creating a
# job](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-async#create).
#
#
# ### 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:** [Supported audio
# formats](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-audio-formats).
#
#
# ### Next-generation models
#
# The service supports next-generation `Multimedia` (16 kHz) and `Telephony` (8
# kHz) models for many languages. Next-generation models have higher throughput than
# the service's previous generation of `Broadband` and `Narrowband` models. When you