-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathoptions.rs
3126 lines (2797 loc) · 89.6 KB
/
options.rs
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
//! Set various Deepgram features to control how the audio is transcribed.
//!
//! See the [Deepgram API Reference][api] for more info.
//!
//! [api]: https://developers.deepgram.com/documentation/features/
use std::{collections::HashMap, fmt};
use serde::{ser::SerializeSeq, Deserialize, Serialize};
/// Used as a parameter for [`Transcription::prerecorded`](crate::Transcription::prerecorded) and similar functions.
#[derive(Debug, PartialEq, Clone)]
pub struct Options {
model: Option<Model>,
version: Option<String>,
language: Option<Language>,
punctuate: Option<bool>,
profanity_filter: Option<bool>,
redact: Vec<Redact>,
diarize: Option<bool>,
diarize_version: Option<String>,
ner: Option<bool>,
multichannel: Option<Multichannel>,
alternatives: Option<usize>,
numerals: Option<bool>,
search: Vec<String>,
replace: Vec<Replace>,
keywords: Vec<Keyword>,
keyterms: Vec<String>,
keyword_boost_legacy: Option<bool>,
utterances: Option<Utterances>,
tags: Vec<String>,
detect_language: Option<DetectLanguage>,
query_params: Vec<(String, String)>,
encoding: Option<Encoding>,
smart_format: Option<bool>,
filler_words: Option<bool>,
paragraphs: Option<bool>,
detect_entities: Option<bool>,
intents: Option<bool>,
custom_intent_mode: Option<CustomIntentMode>,
custom_intents: Vec<String>,
sentiment: Option<bool>,
topics: Option<bool>,
custom_topic_mode: Option<CustomTopicMode>,
custom_topics: Vec<String>,
summarize: Option<bool>,
dictation: Option<bool>,
measurements: Option<bool>,
extra: Option<HashMap<String, String>>,
callback_method: Option<CallbackMethod>,
}
impl Default for Options {
fn default() -> Self {
Options::builder().build()
}
}
/// Detect Language value
///
/// See the [Deepgram Detect Language feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/docs/language-detection
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[non_exhaustive]
pub enum DetectLanguage {
#[allow(missing_docs)]
Enabled,
#[allow(missing_docs)]
Disabled,
#[allow(missing_docs)]
Restricted(Vec<Language>),
}
/// DetectLanguage Impl
impl DetectLanguage {
pub(crate) fn to_key_value_pairs(&self) -> Vec<(&str, String)> {
match self {
DetectLanguage::Enabled => vec![("detect_language", "true".to_string())],
DetectLanguage::Disabled => vec![("detect_language", "false".to_string())],
DetectLanguage::Restricted(languages) => languages
.iter()
.map(|lang| ("detect_language", lang.as_ref().to_string()))
.collect(),
}
}
}
/// Callback Method value
///
/// See the [Deepgram Callback Method feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/docs/callback#pre-recorded-audio
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum CallbackMethod {
/// POST Callback Method
POST,
/// PUT Callback Method
PUT,
}
/// Encoding Impl
impl CallbackMethod {
pub(crate) fn as_str(&self) -> &str {
match self {
CallbackMethod::POST => "post",
CallbackMethod::PUT => "put",
}
}
}
/// Encoding value
///
/// See the [Deepgram Encoding feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/docs/encoding
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum Encoding {
/// 16-bit, little endian, signed PCM WAV data
Linear16,
/// Free Lossless Audio Codec (FLAC) encoded data
Flac,
/// Mu-law encoded WAV data
Mulaw,
/// Adaptive Multi-Rate (AMR) narrowband codec
AmrNb,
/// Adaptive Multi-Rate (AMR) wideband codec
AmrWb,
/// Ogg Opus
Opus,
/// Speex
Speex,
/// G729 low-bandwidth (required for both raw and containerized audio)
G729,
#[allow(missing_docs)]
CustomEncoding(String),
}
/// Encoding Impl
impl Encoding {
pub(crate) fn as_str(&self) -> &str {
match self {
Encoding::Linear16 => "linear16",
Encoding::Flac => "flac",
Encoding::Mulaw => "mulaw",
Encoding::AmrNb => "amr-nb",
Encoding::AmrWb => "amr-wb",
Encoding::Opus => "opus",
Encoding::Speex => "speex",
Encoding::G729 => "g729",
Encoding::CustomEncoding(encoding) => encoding,
}
}
}
/// Endpointing value
///
/// See the [Deepgram Endpointing feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/docs/endpointing
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)]
#[non_exhaustive]
pub enum Endpointing {
#[allow(missing_docs)]
Enabled,
#[allow(missing_docs)]
Disabled,
#[allow(missing_docs)]
CustomDurationMs(u32),
}
impl fmt::Display for Endpointing {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Endpointing::Enabled => f.write_str("true"),
Endpointing::Disabled => f.write_str("false"),
Endpointing::CustomDurationMs(value) => f.write_fmt(format_args!("{value}")),
}
}
}
/// Used as a parameter for [`OptionsBuilder::model`] and [`OptionsBuilder::multichannel_with_models`].
///
/// See the [Deepgram Model feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/model/
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[non_exhaustive]
pub enum Model {
/// Recommended for challenging audio.
/// Recommended for most use cases.
///
/// Nova-3 expands on Nova-2's advancements with speech-specific
/// optimizations to the underlying Transformer architecture, advanced
/// data curation techniques, and a multi-stage training methodology.
/// These changes yield reduced word error rate (WER) and enhancements
/// to entity recognition (i.e. proper nouns, alphanumerics, etc.),
/// punctuation, and capitalization and Keyterms.
Nova3,
/// Recommended for readability and Deepgram's lowest word error rates.
/// Recommended for most use cases.
///
/// Nova-2 expands on Nova-1's advancements with speech-specific
/// optimizations to the underlying Transformer architecture, advanced
/// data curation techniques, and a multi-stage training methodology.
/// These changes yield reduced word error rate (WER) and enhancements
/// to entity recognition (i.e. proper nouns, alphanumerics, etc.),
/// punctuation, and capitalization.
Nova2,
/// Recommended for readability and low word error rates.
///
/// Nova is the predecessor to Nova-2. Training on this model spans over
/// 100 domains and 47 billion tokens, making it the deepest-trained
/// automatic speech-to-text model to date. Nova doesn't just excel in one
/// specific domain — it is ideal for a wide array of voice applications
/// that require high accuracy in diverse contexts. See the benchmarks.
Nova,
/// Recommended for lower word error rates than Base, high accuracy
/// timestamps, and use cases that require keyword boosting.
Enhanced,
/// Recommended for large transcription volumes and high accuracy
/// timestamps.
Base,
#[allow(missing_docs)]
Nova2Meeting,
#[allow(missing_docs)]
Nova2Phonecall,
#[allow(missing_docs)]
Nova2Finance,
#[allow(missing_docs)]
Nova2Conversationalai,
#[allow(missing_docs)]
Nova2Voicemail,
#[allow(missing_docs)]
Nova2Video,
#[allow(missing_docs)]
Nova2Medical,
#[allow(missing_docs)]
Nova2Drivethru,
#[allow(missing_docs)]
Nova2Automotive,
#[allow(missing_docs)]
NovaPhonecall,
#[allow(missing_docs)]
NovaMedical,
#[allow(missing_docs)]
EnhancedMeeting,
#[allow(missing_docs)]
EnhancedPhonecall,
#[allow(missing_docs)]
EnhancedFinance,
#[allow(missing_docs)]
BaseMeeting,
#[allow(missing_docs)]
BasePhonecall,
#[allow(missing_docs)]
BaseVoicemail,
#[allow(missing_docs)]
BaseFinance,
#[allow(missing_docs)]
BaseConversationalai,
#[allow(missing_docs)]
BaseVideo,
#[deprecated(
since = "0.5.0",
note = "use one of the general-purpose models like Model::Nova2 instead"
)]
#[allow(missing_docs)]
General,
#[deprecated(
since = "0.5.0",
note = "use one of the qualified models like Model::Nova2Meeting instead"
)]
#[allow(missing_docs)]
Meeting,
#[deprecated(
since = "0.5.0",
note = "use one of the qualified models like Model::Nova2Phonecall instead"
)]
#[allow(missing_docs)]
Phonecall,
#[deprecated(
since = "0.5.0",
note = "use one of the qualified models like Model::Nova2Voicemail instead"
)]
#[allow(missing_docs)]
Voicemail,
#[deprecated(
since = "0.5.0",
note = "use one of the qualified models like Model::Nova2Finance instead"
)]
#[allow(missing_docs)]
Finance,
#[deprecated(
since = "0.5.0",
note = "use one of the qualified models like Model::Nova2Conversationalai instead"
)]
#[allow(missing_docs)]
Conversationalai,
#[deprecated(
since = "0.5.0",
note = "use one of the qualified models like Model::Nova2Video instead"
)]
#[allow(missing_docs)]
Video,
#[allow(missing_docs)]
CustomId(String),
}
/// Used as a parameter for [`OptionsBuilder::language`].
///
/// See the [Deepgram Language feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/language/
#[allow(non_camel_case_types)] // Variants should look like their BCP-47 tag
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[non_exhaustive]
pub enum Language {
#[allow(missing_docs)]
bg,
#[allow(missing_docs)]
ca,
#[allow(missing_docs)]
cs,
#[allow(missing_docs)]
da,
#[allow(missing_docs)]
de,
#[allow(missing_docs)]
de_CH,
#[allow(missing_docs)]
el,
#[allow(missing_docs)]
en,
#[allow(missing_docs)]
en_AU,
#[allow(missing_docs)]
en_GB,
#[allow(missing_docs)]
en_IN,
#[allow(missing_docs)]
en_NZ,
#[allow(missing_docs)]
en_US,
#[allow(missing_docs)]
es,
#[allow(missing_docs)]
es_419,
#[allow(missing_docs)]
es_LATAM,
#[allow(missing_docs)]
et,
#[allow(missing_docs)]
fi,
#[allow(missing_docs)]
fr,
#[allow(missing_docs)]
fr_CA,
#[allow(missing_docs)]
hi,
#[allow(missing_docs)]
hi_Latn,
#[allow(missing_docs)]
hu,
#[allow(missing_docs)]
id,
#[allow(missing_docs)]
it,
#[allow(missing_docs)]
ja,
#[allow(missing_docs)]
ko,
#[allow(missing_docs)]
ko_KR,
#[allow(missing_docs)]
lv,
#[allow(missing_docs)]
lt,
#[allow(missing_docs)]
ms,
#[allow(missing_docs)]
multi,
#[allow(missing_docs)]
nl,
#[allow(missing_docs)]
nl_BE,
#[allow(missing_docs)]
no,
#[allow(missing_docs)]
pl,
#[allow(missing_docs)]
pt,
#[allow(missing_docs)]
pt_BR,
#[allow(missing_docs)]
ro,
#[allow(missing_docs)]
ru,
#[allow(missing_docs)]
sk,
#[allow(missing_docs)]
sv,
#[allow(missing_docs)]
sv_SE,
#[allow(missing_docs)]
ta,
#[allow(missing_docs)]
taq,
#[allow(missing_docs)]
th,
#[allow(missing_docs)]
th_TH,
#[allow(missing_docs)]
tr,
#[allow(missing_docs)]
uk,
#[allow(missing_docs)]
vi,
#[allow(missing_docs)]
zh,
#[allow(missing_docs)]
zh_CN,
#[allow(missing_docs)]
zh_Hans,
#[allow(missing_docs)]
zh_Hant,
#[allow(missing_docs)]
zh_TW,
/// Avoid using the `Other` variant where possible.
/// It exists so that you can use new languages that Deepgram supports without being forced to update your version of the SDK.
/// See the [Deepgram Language feature docs][docs] for the most up-to-date list of supported languages.
///
/// [docs]: https://developers.deepgram.com/documentation/features/language/
Other(String),
}
/// Used as a parameter for [`OptionsBuilder::redact`].
///
/// See the [Deepgram Redaction feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/redact/
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[non_exhaustive]
pub enum Redact {
#[allow(missing_docs)]
Pci,
#[allow(missing_docs)]
Numbers,
#[allow(missing_docs)]
Ssn,
/// Avoid using the `Other` variant where possible.
/// It exists so that you can use new redactable items that Deepgram supports without being forced to update your version of the SDK.
/// See the [Deepgram Redact feature docs][docs] for the most up-to-date list of redactable items.
///
/// [docs]: https://developers.deepgram.com/documentation/features/redact/
Other(String),
}
/// Used as a parameter for [`OptionsBuilder::custom_intent_mode`].
///
/// See the [Deepgram Intent Detection feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/docs/intent-recognition#query-parameters
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
#[non_exhaustive]
#[serde(rename_all = "snake_case")]
pub enum CustomIntentMode {
#[allow(missing_docs)]
Extended,
#[allow(missing_docs)]
Strict,
}
/// Used as a parameter for [`OptionsBuilder::custom_topic_mode`].
///
/// See the [Deepgram Topic Detection feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/docs/topic-detection#query-parameters
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize)]
#[non_exhaustive]
#[serde(rename_all = "snake_case")]
pub enum CustomTopicMode {
#[allow(missing_docs)]
Extended,
#[allow(missing_docs)]
Strict,
}
/// Used as a parameter for [`OptionsBuilder::replace`].
///
/// See the [Deepgram Find and Replace feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/replace/
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct Replace {
/// The term or phrase to find.
pub find: String,
/// The term or phrase to replace [`find`](Replace::find) with.
/// If set to [`None`], [`find`](Replace::find) will be removed from the transcript without being replaced by anything.
pub replace: Option<String>,
}
/// Used as a parameter for [`OptionsBuilder::keywords_with_intensifiers`].
///
/// See the [Deepgram Keywords feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/keywords/
#[derive(Debug, PartialEq, Clone)]
pub struct Keyword {
/// The keyword to boost.
pub keyword: String,
/// Optionally specify how much to boost it.
pub intensifier: Option<f64>,
}
/// Used as a parameter for [`OptionsBuilder::utterances`].
///
/// See the [Deepgram Utterances feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/docs/utterances
#[derive(Debug, PartialEq, Clone, Copy)]
#[non_exhaustive]
pub enum Utterances {
#[allow(missing_docs)]
Enabled,
#[allow(missing_docs)]
Disabled,
#[allow(missing_docs)]
CustomSplit {
#[allow(missing_docs)]
utt_split: Option<f64>,
},
}
/// Used as a parameter for [`OptionsBuilder::multichannel`].
///
/// See the [Deepgram multichannel feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/docs/multichannel
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[non_exhaustive]
pub enum Multichannel {
#[allow(missing_docs)]
Enabled,
#[allow(missing_docs)]
Disabled,
#[allow(missing_docs)]
ModelPerChannel {
#[allow(missing_docs)]
models: Option<Vec<Model>>,
},
}
/// Builds an [`Options`] object using [the Builder pattern][builder].
///
/// Use it to set of Deepgram's features, excluding the Callback feature.
/// The Callback feature can be set when making the request by calling [`Transcription::prerecorded_callback`](crate::Transcription::prerecorded_callback).
///
/// [builder]: https://rust-unofficial.github.io/patterns/patterns/creational/builder.html
#[derive(Debug, PartialEq, Clone)]
pub struct OptionsBuilder(Options);
/// SerializableOptions
#[derive(Debug, PartialEq, Clone)]
pub(crate) struct SerializableOptions<'a>(pub(crate) &'a Options);
impl Options {
/// Construct a new [`OptionsBuilder`].
pub fn builder() -> OptionsBuilder {
OptionsBuilder::new()
}
/// Return the Options in urlencoded format. If serialization would
/// fail, this will also return an error.
///
/// This is intended primarily to help with debugging API requests.
///
/// ```
/// use deepgram::common::options::{DetectLanguage, Model, Options};
/// let options = Options::builder()
/// .model(Model::Nova2)
/// .detect_language(DetectLanguage::Enabled)
/// .build();
/// assert_eq!(&options.urlencoded().unwrap(), "model=nova-2&detect_language=true")
/// ```
///
pub fn urlencoded(&self) -> Result<String, serde_urlencoded::ser::Error> {
serde_urlencoded::to_string(SerializableOptions::from(self))
}
}
impl OptionsBuilder {
/// Construct a new [`OptionsBuilder`].
pub fn new() -> Self {
Self(Options {
model: None,
version: None,
language: None,
punctuate: None,
profanity_filter: None,
redact: Vec::new(),
diarize: None,
diarize_version: None,
ner: None,
multichannel: None,
alternatives: None,
numerals: None,
search: Vec::new(),
replace: Vec::new(),
keywords: Vec::new(),
keyterms: Vec::new(),
keyword_boost_legacy: None,
utterances: None,
tags: Vec::new(),
detect_language: None,
query_params: Vec::new(),
encoding: None,
smart_format: None,
filler_words: None,
paragraphs: None,
detect_entities: None,
intents: None,
custom_intent_mode: None,
custom_intents: Vec::new(),
sentiment: None,
topics: None,
custom_topic_mode: None,
custom_topics: Vec::new(),
summarize: None,
dictation: None,
measurements: None,
extra: None,
callback_method: None,
})
}
/// Set the Model feature.
///
/// Not all models are supported for all languages. For a list of languages and their supported models, see
/// the [Deepgram Language feature][language] docs.
///
/// If you previously set some models using [`OptionsBuilder::multichannel_with_models`],
/// calling this will overwrite the models you set there, but won't disable the Multichannel feature.
///
/// See the [Deepgram Model feature docs][docs] for more info.
///
/// [language]: https://developers.deepgram.com/documentation/features/language/
/// [docs]: https://developers.deepgram.com/documentation/features/model/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::{Model, Options};
/// #
/// let options = Options::builder()
/// .model(Model::Nova2)
/// .build();
/// ```
///
pub fn model(mut self, model: Model) -> Self {
self.0.model = Some(model);
if let Some(Multichannel::ModelPerChannel { models }) = &mut self.0.multichannel {
*models = None;
}
self
}
/// Set the Version feature.
///
/// See the [Deepgram Version feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/version/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::Options;
/// #
/// let options = Options::builder()
/// .version("12345678-1234-1234-1234-1234567890ab")
/// .build();
/// ```
pub fn version(mut self, version: &str) -> Self {
self.0.version = Some(version.into());
self
}
/// Set the Language feature.
///
/// See the [Deepgram Language feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/language/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::{Language, Options};
/// #
/// let options = Options::builder()
/// .language(Language::en_US)
/// .build();
/// ```
pub fn language(mut self, language: Language) -> Self {
self.0.language = Some(language);
self
}
/// Set the Punctuation feature.
///
/// See the [Deepgram Punctuation feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/punctuate/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::Options;
/// #
/// let options = Options::builder()
/// .punctuate(true)
/// .build();
/// ```
pub fn punctuate(mut self, punctuate: bool) -> Self {
self.0.punctuate = Some(punctuate);
self
}
/// Set the Profanity Filter feature.
///
/// Not necessarily available for all languages.
///
/// See the [Deepgram Profanity Filter feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/profanity-filter/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::Options;
/// #
/// let options = Options::builder()
/// .profanity_filter(true)
/// .build();
/// ```
pub fn profanity_filter(mut self, profanity_filter: bool) -> Self {
self.0.profanity_filter = Some(profanity_filter);
self
}
/// Set the Redaction feature.
///
/// Not necessarily available for all languages.
///
/// Calling this when already set will append to the existing redact items, not overwrite them.
///
/// See the [Deepgram Redaction feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/redact/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::{Options, Redact};
/// #
/// let options = Options::builder()
/// .redact([Redact::Pci, Redact::Ssn])
/// .build();
/// ```
///
/// ```
/// # use deepgram::common::options::{Options, Redact};
/// #
/// let options1 = Options::builder()
/// .redact([Redact::Pci])
/// .redact([Redact::Ssn])
/// .build();
///
/// let options2 = Options::builder()
/// .redact([Redact::Pci, Redact::Ssn])
/// .build();
///
/// assert_eq!(options1, options2);
/// ```
pub fn redact(mut self, redact: impl IntoIterator<Item = Redact>) -> Self {
self.0.redact.extend(redact);
self
}
/// Set the Diarization feature.
///
/// See the [Deepgram Diarization feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/diarize/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::Options;
/// #
/// let options = Options::builder()
/// .diarize(true)
/// .build();
/// ```
pub fn diarize(mut self, diarize: bool) -> Self {
self.0.diarize = Some(diarize);
self
}
/// Set the Diarization Version feature.
///
/// See the [Deepgram Diarization Version feature docs][docs] for more info.
///
/// [docs]: https://deepgram.com/changelog/improved-speaker-diarization
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::Options;
/// #
/// let options = Options::builder()
/// .diarize_version("2021-07-14.0")
/// .build();
/// ```
pub fn diarize_version(mut self, diarize_version: &str) -> Self {
self.0.diarize_version = Some(diarize_version.into());
self
}
/// Set the Named-Entity Recognition feature.
///
/// Not necessarily available for all languages.
///
/// See the [Deepgram Named-Entity Recognition feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/named-entity-recognition/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::Options;
/// #
/// let options = Options::builder()
/// .ner(true)
/// .build();
/// ```
pub fn ner(mut self, ner: bool) -> Self {
self.0.ner = Some(ner);
self
}
/// Set the Multichannel feature.
///
/// To specify which model should process each channel, use [`OptionsBuilder::multichannel_with_models`] instead.
/// If [`OptionsBuilder::multichannel_with_models`] is currently set, calling [`OptionsBuilder::multichannel`]
/// will reset the model to the last call to [`OptionsBuilder::model`].
///
/// See the [Deepgram Multichannel feature docs][docs] for more info.
///
/// [docs]: https://developers.deepgram.com/documentation/features/multichannel/
///
/// # Examples
///
/// ```
/// # use deepgram::common::options::Options;
/// #
/// let options = Options::builder()
/// .multichannel(true)
/// .build();
/// ```
///
/// ```
/// # use deepgram::common::options::{Model, Options};
/// #
/// let options1 = Options::builder()
/// .model(Model::Nova2)
/// .multichannel_with_models([Model::Nova2Meeting, Model::Nova2Phonecall])
/// .multichannel(true)
/// .build();
///
/// let options2 = Options::builder()
/// .model(Model::Nova2)
/// .multichannel(true)
/// .build();
///
/// assert_eq!(options1, options2);
/// ```
pub fn multichannel(mut self, multichannel: bool) -> Self {
self.0.multichannel = Some(if multichannel {
Multichannel::Enabled
} else {
Multichannel::Disabled