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

Featurize transcription modes #68

Merged
merged 8 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 31 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "1"
tokio = { version = "1.13.0", 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.
Expand All @@ -34,3 +34,32 @@ 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"]
andrewhalle marked this conversation as resolved.
Show resolved Hide resolved
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"]
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion src/transcription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,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`].
Expand Down
Loading