From 42a4d4b9fba49cf6d522023b6c52a84be2391f0c Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Wed, 3 Jul 2024 09:59:15 -0400 Subject: [PATCH 1/5] Add feature flags for prerecorded and live transcription --- Cargo.toml | 9 +++++++-- src/lib.rs | 2 ++ src/transcription.rs | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3db6f109..88289839 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" thiserror = "1" tokio = { version = "1", features = ["full"] } -tokio-tungstenite = { version = "0.20.1", features = ["rustls-tls-webpki-roots"] } +tokio-tungstenite = { version = "0.20.1", features = ["rustls-tls-webpki-roots"], optional = true } tokio-util = { version = "0.7.1", features = ["codec", "io"] } -tungstenite = "0.20.1" +tungstenite = { version = "0.20.1", optional = true } url = "2" uuid = { version = "1", features = ["serde"] } # Dependencies below are specified only to satisfy minimal-versions. @@ -34,3 +34,8 @@ proc-macro2 = "1.0.60" pkg-config = "0.3.27" cpal = "0.13" crossbeam = "0.8" + +[features] +default = ["prerecorded", "live"] +live = ["dep:tungstenite", "dep:tokio-tungstenite"] +prerecorded = [] diff --git a/src/lib.rs b/src/lib.rs index f0839b9e..6d80dd3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,7 @@ mod response; /// Make transcriptions requests using [`Deepgram::transcription`]. #[derive(Debug, Clone)] pub struct Deepgram { + #[cfg_attr(not(feature="live"), allow(unused))] api_key: String, client: reqwest::Client, } @@ -65,6 +66,7 @@ pub enum DeepgramError { #[error("Something went wrong during I/O: {0}")] IoError(#[from] io::Error), + #[cfg(feature = "live")] /// Something went wrong with WS. #[error("Something went wrong with WS: {0}")] WsError(#[from] tungstenite::Error), diff --git a/src/transcription.rs b/src/transcription.rs index 6a576e79..fe22ce55 100644 --- a/src/transcription.rs +++ b/src/transcription.rs @@ -6,7 +6,9 @@ use crate::Deepgram; +#[cfg(feature = "live")] pub mod live; +#[cfg(feature = "prerecorded")] pub mod prerecorded; /// Transcribe audio using Deepgram's automated speech recognition. From 8382a70b2615ee3188991dcaa26902b9e6f9cf79 Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Wed, 3 Jul 2024 11:04:32 -0400 Subject: [PATCH 2/5] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2387daf3..9db4fb3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Deprecate tiers and add explicit support for all currently available models. - Expand language enum to include all currently-supported languages. +- Add (default on) feature flags for live and prerecorded transcription. ## [0.4.0] - 2023-11-01 From a59f2e48ef4feb98445040bc2669f5643f4bbd7a Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Wed, 3 Jul 2024 11:57:46 -0400 Subject: [PATCH 3/5] fmt --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6d80dd3a..f6635679 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,7 @@ mod response; /// Make transcriptions requests using [`Deepgram::transcription`]. #[derive(Debug, Clone)] pub struct Deepgram { - #[cfg_attr(not(feature="live"), allow(unused))] + #[cfg_attr(not(feature = "live"), allow(unused))] api_key: String, client: reqwest::Client, } From 016cb3f8a76da1d593921e70ca33be38789f8301 Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Wed, 3 Jul 2024 13:50:39 -0400 Subject: [PATCH 4/5] Clean up examples and lint with no features --- Cargo.toml | 24 ++++++++++++++++++++++++ src/transcription.rs | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c136ada4..6b702b21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,3 +39,27 @@ crossbeam = "0.8" default = ["prerecorded", "live"] live = ["dep:tungstenite", "dep:tokio-tungstenite"] prerecorded = [] + +[[example]] +name = "prerecorded_from_file" +required-features = ["prerecorded"] + +[[example]] +name = "callback" +required-features = ["prerecorded"] + +[[example]] +name = "make_prerecorded_request_builder" +required-features = ["prerecorded"] + +[[example]] +name = "microphone_stream" +required-features = ["live"] + +[[example]] +name = "prerecorded_from_url" +required-features = ["prerecorded"] + +[[example]] +name = "simple_stream" +required-features = ["live"] diff --git a/src/transcription.rs b/src/transcription.rs index fe22ce55..847ec47d 100644 --- a/src/transcription.rs +++ b/src/transcription.rs @@ -19,7 +19,7 @@ pub mod prerecorded; /// /// [api]: https://developers.deepgram.com/api-reference/#transcription #[derive(Debug, Clone)] -pub struct Transcription<'a>(&'a Deepgram); +pub struct Transcription<'a>(#[allow(unused)] &'a Deepgram); impl Deepgram { /// Construct a new [`Transcription`] from a [`Deepgram`]. From 8b19d1904afcadfdac58b7aa922e444b35437428 Mon Sep 17 00:00:00 2001 From: Cliff Dyer Date: Wed, 3 Jul 2024 13:53:51 -0400 Subject: [PATCH 5/5] Test feature compat in CI --- .github/workflows/ci.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 42dab37c..13bb40bb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,6 +7,20 @@ env: RUSTDOCFLAGS: -D warnings jobs: + Features: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install libasound2-dev + run: | + sudo apt-get update + sudo apt-get install libasound2-dev + - name: Check no features + run: cargo check --all-targets --no-default-features + - name: Check prerecorded feature + run: cargo check --all-targets --no-default-features --features=prerecorded + - name: Check live feature + run: cargo check --all-targets --no-default-features --features=live Build: runs-on: ubuntu-latest steps: