Skip to content

Commit

Permalink
fix Clippy, Format, Documentation, Minimal-Version
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienDeepgram committed Jul 13, 2024
1 parent a12cc0e commit 0a3e6f3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/advanced_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn main() -> Result<(), DeepgramError> {
.smart_format(true)
.language(Language::en_US)
.build();

let mut results = dg
.transcription()
.stream_request_with_options(Some(&options))
Expand Down
31 changes: 15 additions & 16 deletions src/transcription/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::path::Path;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use serde_urlencoded;
use serde_json::Value;
use serde_urlencoded;

use bytes::{Bytes, BytesMut};
use futures::channel::mpsc::{self, Receiver};
Expand Down Expand Up @@ -85,20 +85,19 @@ pub enum StreamResponse {
UtteranceEndResponse {
r#type: String,
channel: Vec<u8>,
last_word_end: f64
last_word_end: f64,
},
SpeechStartedResponse {
r#type: String,
channel: Vec<u8>,
timestamp: f64
timestamp: f64,
},
TerminalResponse {
request_id: String,
created: String,
duration: f64,
channels: u32,
},
Other(Value), // Log unhandled messages if any
}
}

#[pin_project]
Expand All @@ -110,7 +109,7 @@ struct FileChunker {
}

impl Transcription<'_> {
pub fn stream_request<'a, E, S>(&'a self) -> StreamRequestBuilder<'a, S, E>
pub fn stream_request<E, S>(&self) -> StreamRequestBuilder<'_, S, E>
where
S: Stream<Item = std::result::Result<Bytes, E>>,
{
Expand All @@ -119,14 +118,14 @@ impl Transcription<'_> {

pub fn stream_request_with_options<'a, E, S>(
&'a self,
options: Option<&'a Options>
options: Option<&'a Options>,
) -> StreamRequestBuilder<'a, S, E>
where
S: Stream<Item = std::result::Result<Bytes, E>>,
{
StreamRequestBuilder {
config: self.0,
options: options,
options,
source: None,
encoding: None,
sample_rate: None,
Expand Down Expand Up @@ -226,7 +225,7 @@ where

self
}

pub fn utterance_end_ms(mut self, utterance_end_ms: u16) -> Self {
self.utterance_end_ms = Some(utterance_end_ms);

Expand All @@ -238,19 +237,18 @@ where

self
}

pub fn no_delay(mut self, no_delay: bool) -> Self {
self.no_delay = Some(no_delay);

self
}

pub fn vad_events(mut self, vad_events: bool) -> Self {
self.vad_events = Some(vad_events);

self
}

}

impl<'a> StreamRequestBuilder<'a, Receiver<Result<Bytes>>, DeepgramError> {
Expand Down Expand Up @@ -280,7 +278,7 @@ impl<'a> StreamRequestBuilder<'a, Receiver<Result<Bytes>>, DeepgramError> {

fn options_to_query_string(options: &Options) -> String {
let serialized_options = SerializableOptions::from(options);
serde_urlencoded::to_string(&serialized_options).unwrap_or_default()
serde_urlencoded::to_string(serialized_options).unwrap_or_default()
}

impl<S, E> StreamRequestBuilder<'_, S, E>
Expand All @@ -297,16 +295,17 @@ where
// Add standard pre-recorded options
if let Some(options) = &self.options {
let query_string = options_to_query_string(options);
let query_pairs: Vec<(Cow<str>, Cow<str>)> = query_string.split('&')
let query_pairs: Vec<(Cow<str>, Cow<str>)> = query_string
.split('&')
.map(|s| {
let mut split = s.splitn(2, '=');
(
Cow::from(split.next().unwrap_or_default()),
Cow::from(split.next().unwrap_or_default())
Cow::from(split.next().unwrap_or_default()),
)
})
.collect();

for (key, value) in query_pairs {
pairs.append_pair(&key, &value);
}
Expand Down
15 changes: 7 additions & 8 deletions src/transcription/prerecorded/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Options {
query_params: Vec<(String, String)>,
encoding: Option<String>,
smart_format: Option<bool>,
filler_words: Option<bool>
filler_words: Option<bool>,
}

/// Used as a parameter for [`OptionsBuilder::model`] and [`OptionsBuilder::multichannel_with_models`].
Expand Down Expand Up @@ -427,8 +427,7 @@ pub enum Utterances {
/// Enabled
Enabled {
/// utt_split
/// [docs]: https://developers.deepgram.com/docs/utterance-split
utt_split: Option<f64>
utt_split: Option<f64>,
},
}

Expand All @@ -444,7 +443,7 @@ pub enum Multichannel {
/// Enabled
Enabled {
/// models
models: Option<Vec<Model>>
models: Option<Vec<Model>>,
},
}

Expand Down Expand Up @@ -493,7 +492,7 @@ impl OptionsBuilder {
query_params: Vec::new(),
encoding: None,
smart_format: None,
filler_words: None
filler_words: None,
})
}

Expand Down Expand Up @@ -1287,8 +1286,8 @@ impl OptionsBuilder {
self
}

/// Encoding is required when raw, headerless audio packets are sent to the
/// streaming service. If containerized audio packets are sent to the
/// Encoding is required when raw, headerless audio packets are sent to the
/// streaming service. If containerized audio packets are sent to the
/// streaming service, this feature should not be used.
///
/// See the [Deepgram Encoding feature docs][docs] for more info.
Expand Down Expand Up @@ -1403,7 +1402,7 @@ impl Serialize for SerializableOptions<'_> {
query_params,
encoding,
smart_format,
filler_words
filler_words,
} = self.0;

match multichannel {
Expand Down

0 comments on commit 0a3e6f3

Please sign in to comment.