Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add streaming features and missing pre recorded features #74

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
93a0f27
Add streaming features
DamienDeepgram Jul 13, 2024
8f5ec53
Avoid breaking change and add new stream_request_with_options
DamienDeepgram Jul 13, 2024
a12cc0e
remove features
DamienDeepgram Jul 13, 2024
0a3e6f3
fix Clippy, Format, Documentation, Minimal-Version
DamienDeepgram Jul 13, 2024
98d3177
fix build
DamienDeepgram Jul 13, 2024
7673cc3
fix build
DamienDeepgram Jul 13, 2024
70deca6
fix build
DamienDeepgram Jul 13, 2024
33df00d
fix build + add missing response mappings
DamienDeepgram Jul 13, 2024
c6b2d04
fix build for deserialization
DamienDeepgram Jul 13, 2024
a093e2e
fix build for deserialization
DamienDeepgram Jul 13, 2024
79344fb
fix build error - enum variants
DamienDeepgram Jul 13, 2024
be9eaa7
fix optional speaker id
DamienDeepgram Jul 13, 2024
7c26484
fix optional attributes
DamienDeepgram Jul 13, 2024
c5f5d14
add debug
DamienDeepgram Jul 13, 2024
e28fbcd
add debug
DamienDeepgram Jul 13, 2024
6b5441c
make public
DamienDeepgram Jul 13, 2024
6bf181b
test old code
DamienDeepgram Jul 13, 2024
bf58e70
test new code
DamienDeepgram Jul 13, 2024
28a99d7
Add paragraphs
DamienDeepgram Jul 13, 2024
ff5d292
test commenting out type and optionals
DamienDeepgram Jul 13, 2024
a13a540
Add keep alive
DamienDeepgram Jul 13, 2024
62a9596
fix imports
DamienDeepgram Jul 13, 2024
7a2c8f2
rename type without r#
DamienDeepgram Jul 13, 2024
eeaf7c9
add back in optionals
DamienDeepgram Jul 13, 2024
a5993cf
Add paragraphs
DamienDeepgram Jul 13, 2024
b0fa712
Add docs for examples and building the SDK
DamienDeepgram Jul 13, 2024
472ab5b
bump version
DamienDeepgram Jul 13, 2024
f18ee09
update test all options + add a more verbose example
DamienDeepgram Jul 13, 2024
c4fcbfd
fix test eval + lint issue
DamienDeepgram Jul 13, 2024
c1c8534
Add initial audio intelligence features
DamienDeepgram Jul 13, 2024
67ce230
Add new features to test all test
DamienDeepgram Jul 13, 2024
efd1f6d
Add support for custom topics and custom intents
DamienDeepgram Jul 13, 2024
07a4529
fix formatting
DamienDeepgram Jul 13, 2024
569a213
fix indentiation
DamienDeepgram Jul 13, 2024
6bf25f5
fix import
DamienDeepgram Jul 13, 2024
d467f15
add missing import
DamienDeepgram Jul 13, 2024
76ae23d
update import
DamienDeepgram Jul 13, 2024
292f418
update import
DamienDeepgram Jul 13, 2024
a756fdc
update import
DamienDeepgram Jul 13, 2024
0571053
Add dictation and measurements support
DamienDeepgram Jul 13, 2024
64eb6ba
Add diarize_version, extra, callback, callback_method features
DamienDeepgram Jul 13, 2024
868e2a7
support callback response format
DamienDeepgram Jul 13, 2024
50c1a18
print entire response
DamienDeepgram Jul 13, 2024
69cd345
print entire response
DamienDeepgram Jul 13, 2024
857f0eb
fix lint error
DamienDeepgram Jul 13, 2024
3390c74
remove comment
DamienDeepgram Jul 15, 2024
896b6d8
print out the transcript if it exists
DamienDeepgram Jul 15, 2024
bf23993
print out the transcript if it exists
DamienDeepgram Jul 15, 2024
8eab7a4
remove callback as an Option param, keep it as it's own method call s…
DamienDeepgram Jul 15, 2024
3d90e3c
Add back in features
DamienDeepgram Jul 15, 2024
f1c0210
Add back in features
DamienDeepgram Jul 15, 2024
689d91f
Add back in features and make options common
DamienDeepgram Jul 15, 2024
64f0ffd
Add back in features and make options common
DamienDeepgram Jul 15, 2024
4de1e1f
fix lint errors
DamienDeepgram Jul 15, 2024
210830c
fix doc errors
DamienDeepgram Jul 15, 2024
2129168
fix test errors
DamienDeepgram Jul 15, 2024
2d3fc34
fix test
DamienDeepgram Jul 15, 2024
535c774
fix docs
DamienDeepgram Jul 15, 2024
2042462
fix format
DamienDeepgram Jul 15, 2024
2c19727
fix docs
DamienDeepgram Jul 15, 2024
5e6c33f
fix docs
DamienDeepgram Jul 15, 2024
c150904
fix docs
DamienDeepgram Jul 15, 2024
0821052
fix tests
DamienDeepgram Jul 15, 2024
f900140
fix docs
DamienDeepgram Jul 15, 2024
ad71df9
Update README.md
DamienDeepgram Jul 16, 2024
cb911a1
PR Feedback changes
DamienDeepgram Jul 16, 2024
582b149
add back in redact
DamienDeepgram Jul 16, 2024
f12e8b1
add back in redact
DamienDeepgram Jul 16, 2024
a661303
add back in redact
DamienDeepgram Jul 16, 2024
61192c2
add snake case
DamienDeepgram Jul 16, 2024
3695d27
mark audio source as only for live and prerecorded features
DamienDeepgram Jul 16, 2024
a623657
mark test as only for prerecorded feature
DamienDeepgram Jul 16, 2024
48caec9
mark audio source as only for prerecorded features
DamienDeepgram Jul 16, 2024
6150ed1
mark audio source as only for live and prerecorded features
DamienDeepgram Jul 16, 2024
df62e9e
mark audio source as only for prerecorded features
DamienDeepgram Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deepgram"
version = "0.5.0"
version = "0.6.0"
authors = ["Deepgram <[email protected]>"]
edition = "2021"
description = "Official Rust SDK for Deepgram's automated speech recognition APIs."
Expand All @@ -20,6 +20,7 @@ pin-project = "1"
reqwest = { version = "0.11.22", default-features = false, features = ["json", "rustls-tls", "stream"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_urlencoded = "0.7"
thiserror = "1"
tokio = { version = "1.13.0", features = ["full"] }
tokio-tungstenite = { version = "0.20.1", features = ["rustls-tls-webpki-roots"], optional = true }
Expand Down Expand Up @@ -62,4 +63,4 @@ required-features = ["prerecorded"]

[[example]]
name = "simple_stream"
required-features = ["live"]
required-features = ["live"]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You can learn more about the Deepgram API at [developers.deepgram.com](https://d
## Current Status

This SDK is still very much work-in-progress. The interface is subject to rapid change.

## Install

From within your Cargo project directory, run the following command:
Expand All @@ -46,6 +47,13 @@ To make sure our community is safe for all, be sure to review and agree to our
[Code of Conduct](./CODE_OF_CONDUCT.md). Then see the
[Contributing Guidelines](./CONTRIBUTING.md) for more information.


### Build the SDK

```sh
cargo build
```

## Getting Help

We love to hear from you so if you have questions, comments or find a bug in the
Expand All @@ -55,4 +63,4 @@ project, let us know! You can either:
- [Join the Deepgram Github Discussions Community](https://github.com/orgs/deepgram/discussions)
- [Join the Deepgram Discord Community](https://discord.gg/xWRaCDBtW4)

[license]: LICENSE.txt
[license]: LICENSE.txt
Binary file added bin/act
Binary file not shown.
21 changes: 21 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Running Examples

### Setting Env Vars

```sh
export FILENAME=./examples/prerecorded_from_file/bueller.wav
```

### Running the examples

```sh
cargo run --example prerecorded_from_url
```

```sh
cargo run --example simple_stream
```

```sh
cargo run --example advanced_stream
```
4 changes: 2 additions & 2 deletions examples/callback.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::env;

use deepgram::{
transcription::prerecorded::{
transcription::{
audio_source::AudioSource,
options::{Language, Options},
common_options::{Language, Options},
},
Deepgram, DeepgramError,
};
Expand Down
8 changes: 5 additions & 3 deletions examples/make_prerecorded_request_builder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::env;

use deepgram::{
transcription::prerecorded::{
transcription::{
audio_source::AudioSource,
options::{Language, Options},
response::Response,
common_options::{Language, Options},
prerecorded::response::Response,
},
Deepgram,
};
Expand Down Expand Up @@ -41,5 +41,7 @@ async fn main() -> reqwest::Result<()> {
let transcript = &response.results.channels[0].alternatives[0].transcript;
println!("{}", transcript);

println!("{:?}", response);
DamienDeepgram marked this conversation as resolved.
Show resolved Hide resolved

Ok(())
}
2 changes: 1 addition & 1 deletion examples/microphone_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ async fn main() -> Result<(), DeepgramError> {
let mut results = dg
.transcription()
.stream_request()
.keep_alive()
.stream(microphone_as_stream())
// TODO Enum.
.encoding("linear16".to_string())
// TODO Specific to my machine, not general enough example.
.sample_rate(44100)
Expand Down
Binary file added examples/prerecorded_from_file/bueller.wav
Binary file not shown.
6 changes: 4 additions & 2 deletions examples/prerecorded_from_file/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::env;

use deepgram::{
transcription::prerecorded::{
transcription::{
audio_source::AudioSource,
options::{Language, Options},
common_options::{Language, Options},
},
Deepgram, DeepgramError,
};
Expand Down Expand Up @@ -35,5 +35,7 @@ async fn main() -> Result<(), DeepgramError> {
let transcript = &response.results.channels[0].alternatives[0].transcript;
println!("{}", transcript);

println!("{:?}", response);

Ok(())
}
27 changes: 25 additions & 2 deletions examples/prerecorded_from_url.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::env;

use deepgram::{
transcription::prerecorded::{
transcription::{
audio_source::AudioSource,
options::{Language, Options},
common_options::{CustomIntentMode, Language, Model, Options, Redact},
},
Deepgram, DeepgramError,
};
Expand All @@ -20,8 +20,29 @@ async fn main() -> Result<(), DeepgramError> {
let source = AudioSource::from_url(AUDIO_URL);

let options = Options::builder()
DamienDeepgram marked this conversation as resolved.
Show resolved Hide resolved
.model(Model::CustomId(String::from("nova-2-general")))
.punctuate(true)
.paragraphs(true)
.redact([Redact::Pci, Redact::Other(String::from("cvv"))])
.detect_language(true)
.diarize(true)
.diarize_version("2021-07-14.0")
.filler_words(true)
.smart_format(true)
.encoding("linear16")
.language(Language::en_US)
.detect_entities(true)
.intents(true)
.custom_intent_mode(CustomIntentMode::Extended)
.custom_intents(["Phone repair", "Phone cancellation"])
.sentiment(true)
.topics(true)
.custom_intent_mode(CustomIntentMode::Strict)
.custom_intents(["Get support", "Complain"])
.summarize("v2")
.dictation(true)
.measurements(true)
.extra("key:value")
.build();

let response = dg_client
Expand All @@ -32,5 +53,7 @@ async fn main() -> Result<(), DeepgramError> {
let transcript = &response.results.channels[0].alternatives[0].transcript;
println!("{}", transcript);

println!("{:?}", response);

Ok(())
}
23 changes: 20 additions & 3 deletions examples/simple_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,34 @@ use std::time::Duration;

use futures::stream::StreamExt;

use deepgram::{Deepgram, DeepgramError};
use deepgram::{
transcription::common_options::{Language, Options},
Deepgram, DeepgramError,
};

#[tokio::main]
async fn main() -> Result<(), DeepgramError> {
let dg = Deepgram::new(env::var("DEEPGRAM_API_KEY").unwrap());

let options = Options::builder()
.smart_format(true)
.language(Language::en_US)
.build();

let mut results = dg
.transcription()
.stream_request()
.stream_request_with_options(Some(&options))
.keep_alive()
.encoding("linear16".to_string())
.sample_rate(44100)
.channels(2)
.endpointing("300".to_string())
.interim_results(true)
.utterance_end_ms(1000)
.vad_events(true)
.no_delay(true)
.file(
env::var("FILENAME").unwrap(),
"./examples/prerecorded_from_file/bueller.wav",
3174,
Duration::from_millis(16),
)
Expand Down
5 changes: 4 additions & 1 deletion src/transcription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub mod live;
#[cfg(feature = "prerecorded")]
pub mod prerecorded;

pub mod audio_source;
pub mod common_options;

/// Transcribe audio using Deepgram's automated speech recognition.
///
/// Constructed using [`Deepgram::transcription`].
Expand All @@ -19,7 +22,7 @@ pub mod prerecorded;
///
/// [api]: https://developers.deepgram.com/api-reference/#transcription
#[derive(Debug, Clone)]
pub struct Transcription<'a>(#[allow(unused)] &'a Deepgram);
pub struct Transcription<'a>(&'a Deepgram);

impl Deepgram {
/// Construct a new [`Transcription`] from a [`Deepgram`].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use reqwest::{header::CONTENT_TYPE, RequestBuilder};
use serde::Serialize;

/// Used as a parameter for [`Transcription::prerecorded`](crate::transcription::Transcription::prerecorded) and similar functions.
#[cfg(any(feature = "prerecorded", feature = "live"))]
#[derive(Debug)]
pub struct AudioSource(InternalAudioSource);

#[cfg(any(feature = "prerecorded", feature = "live"))]
#[derive(Debug)]
enum InternalAudioSource {
Url(String),
Expand All @@ -20,6 +22,7 @@ enum InternalAudioSource {
},
}

#[cfg(any(feature = "prerecorded", feature = "live"))]
impl AudioSource {
/// Constructs an [`AudioSource`] that will instruct Deepgram to download the audio from the specified URL.
pub fn from_url(url: impl Into<String>) -> Self {
Expand Down
Loading
Loading