### Run Simple Flux Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the example demonstrating the 'flux' feature for real-time processing. ```shell cargo run --example simple_flux ``` -------------------------------- ### Run Microphone Flux Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the example that combines microphone input with the 'flux' real-time processing. ```shell cargo run --example microphone_flux ``` -------------------------------- ### Run Text-to-Speech to File Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the example that converts text to speech and saves the output to a file. ```shell cargo run --example text_to_speech_to_file ``` -------------------------------- ### Run Prerecorded Request Builder Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the example that demonstrates building a prerecorded audio request using a builder pattern. ```shell cargo run --example make_prerecorded_request_builder ``` -------------------------------- ### Run Microphone Stream Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the example that streams audio directly from the microphone to Deepgram. ```shell cargo run --example microphone_stream ``` -------------------------------- ### Run Text-to-Speech to Stream Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the example that converts text to speech and streams the audio output. ```shell cargo run --example text_to_speech_to_stream ``` -------------------------------- ### Run Callback Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the example that utilizes a callback mechanism for handling Deepgram responses. ```shell cargo run --example callback ``` -------------------------------- ### Run Prerecorded Request from URL Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the prerecorded audio processing example that takes an audio source from a URL. ```shell cargo run --example prerecorded_from_url ``` -------------------------------- ### Run Simple Stream Example Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Execute the example demonstrating a simple real-time audio stream to Deepgram. ```shell cargo run --example simple_stream ``` -------------------------------- ### Build Transcription Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-options.md Finalizes the transcription options configuration. This example sets model, language, punctuation, and diarization. ```rust let options = Options::builder() .model(Model::Nova3) .language(Language::en_US) .punctuate(true) .diarize(true) .build(); ``` -------------------------------- ### Start WebSocket Stream with Default Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Initiates a WebSocket streaming request with default transcription options. Use builder methods to configure before connecting. ```rust let builder = dg.transcription().stream_request(); ``` -------------------------------- ### Create Options Builder - Rust Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-options.md Initializes a new Options builder with default settings. Use this as a starting point for configuring transcription options. ```rust use deepgram::common::options::Options; let options = Options::builder().build(); ``` -------------------------------- ### Accessing ChannelResult and Alternatives Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/response-types.md Demonstrates how to get the best transcription hypothesis from a channel's alternatives and how to iterate through additional alternatives if they were requested. ```rust let channel = &response.results.channels[0]; // Get best hypothesis let best = &channel.alternatives[0]; println!("Primary transcript: {}", best.transcript); // Get alternatives if requested for (i, alt) in channel.alternatives.iter().skip(1).enumerate() { println!("Alternative {}: {} (confidence: {})", i+1, alt.transcript, alt.confidence); } ``` -------------------------------- ### Start WebSocket Stream with Custom Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Initiates a WebSocket streaming request with specific, pre-configured transcription options. Ensure options are built correctly before passing them. ```rust let options = Options::builder() .model(Model::Nova2) .punctuate(true) .build(); let builder = dg.transcription().stream_request_with_options(options); ``` -------------------------------- ### Real-Time Transcription Streaming Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/quick-start.md This example demonstrates how to stream audio in real-time for transcription. It includes setting up transcription options, streaming audio from a file with artificial timing, and receiving interim results. Ensure 'audio.wav' exists and is accessible. ```rust use deepgram::{Deepgram, common::options::{Encoding, Options}}; use futures::stream::StreamExt; use std::time::Duration; #[tokio::main] async fn main() -> Result<(), Box> { let dg = Deepgram::new("YOUR_API_KEY")?; let options = Options::builder() .punctuate(true) .build(); let mut stream = dg.transcription() .stream_request_with_options(options) .encoding(Encoding::Linear16) .sample_rate(16000) .interim_results(true) .stream() .await?; // For demo: stream from file with artificial timing let mut audio_file = std::fs::File::open("audio.wav")?; let mut buffer = [0u8; 4096]; // Send audio in chunks loop { match std::io::Read::read(&mut audio_file, &mut buffer)? { 0 => { stream.send_close().await?; break; } n => { stream.send_binary(&buffer[..n]).await?; tokio::time::sleep(Duration::from_millis(20)).await; } } } // Receive results while let Some(result) = stream.next().await { match result { Ok(response) => println!("Interim: {:?}", response), Err(e) => eprintln!("Error: {}", e), } } Ok(()) } ``` -------------------------------- ### Get Project Billing Balance Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves the current balance and billing information for a project. Requires the project ID. ```rust pub async fn get_balance(&self, project_id: &str) -> crate::Result ``` -------------------------------- ### Start Flux Conversational Stream with Default Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Begins configuration of a Flux streaming request using the default model. Customize further using builder methods before establishing a connection. ```rust let builder = dg.transcription().flux_request(); ``` -------------------------------- ### Get Project Details Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves details of a specific project using its unique identifier. The project ID must be valid. ```rust let project = dg.projects().get("project-id-123").await?; println!("Project name: {}", project.name); ``` -------------------------------- ### Start Flux Conversational Stream with Custom Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Begins configuration of a Flux streaming request with specific transcription options. This allows for fine-tuning parameters like the model and eager end-of-turn detection. ```rust let options = Options::builder() .model(Model::FluxGeneralEn) .eager_eot_threshold(0.8) .build(); let builder = dg.transcription().flux_request_with_options(options); ``` -------------------------------- ### Iterating Through ListenResults Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/response-types.md Provides an example of iterating through transcription results, printing transcripts and confidence scores for each channel and alternative. It also shows how to access segmented utterances if enabled. ```rust for channel in &response.results.channels { for alternative in &channel.alternatives { println!("Transcript: {}", alternative.transcript); println!("Confidence: {}", alternative.confidence); } } if let Some(utterances) = &response.results.utterances { for utt in utterances { println!("Utterance [{}s - {}s]: {}", utt.start, utt.end, utt.transcript); } } ``` -------------------------------- ### Set Environment Variable for Audio File Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/examples/README.md Before running some examples, set the FILENAME environment variable to the path of the audio file you want to process. ```shell export FILENAME=./examples/audio/bueller.wav ``` -------------------------------- ### Get Authentication Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Auth instance for generating temporary tokens. This is useful for managing access and permissions. ```rust let auth = deepgram.auth(); let token = auth.grant(None).await?; ``` -------------------------------- ### Prerecorded Transcription with Error Handling Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/quick-start.md This example demonstrates how to transcribe prerecorded audio from a URL using the Deepgram Rust SDK and includes comprehensive error handling for various API and network issues. ```APIDOC ## Prerecorded Transcription with Error Handling ### Description This example demonstrates how to transcribe prerecorded audio from a URL using the Deepgram Rust SDK and includes comprehensive error handling for various API and network issues. ### Method `dg.transcription().prerecorded(source, &options).await` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use deepgram::{Deepgram, DeepgramError, common::{ audio_source::AudioSource, options::Options, }}; #[tokio::main] async fn main() -> Result<(), DeepgramError> { let dg = Deepgram::new("YOUR_API_KEY")?; let source = AudioSource::from_url("https://..."); let options = Options::builder().build(); match dg.transcription().prerecorded(source, &options).await { Ok(response) => { println!("Success! {}", response.results.channels[0].alternatives[0].transcript); } Err(DeepgramError::DeepgramApiError { body, err }) => { eprintln!("API Error: {}", body); eprintln!("HTTP Error: {}", err); } Err(DeepgramError::ReqwestError(e)) if e.is_timeout() => { eprintln!("Request timed out"); } Err(e) => { eprintln!("Other error: {}", e); } } Ok(()) } ``` ### Response #### Success Response (200) - **response** (TranscriptionResponse) - The transcription result object. ``` -------------------------------- ### Get Billing Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Billing instance for accessing billing information. Use this to retrieve details about your account's billing status and history. ```rust let billing = deepgram.billing(); ``` -------------------------------- ### Create Flux Request Builder Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/flux-api.md Initializes a Flux request builder using default settings. This is the starting point for configuring a Flux transcription request. ```rust use deepgram::{Deepgram, common::options::Model}; let dg = Deepgram::new("YOUR_API_KEY")?; let transcription = dg.transcription(); // Default Flux (FluxGeneralEn) let builder = transcription.flux_request(); ``` -------------------------------- ### Get Projects Management Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Projects instance for managing Deepgram projects. Use this to list, create, or modify your projects. ```rust let projects = deepgram.projects(); let project_list = projects.list().await?; ``` -------------------------------- ### Get Invitations Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Invitations instance for managing project invitations. This handler is used to send and manage invitations to join projects. ```rust let invitations = deepgram.invitations(); ``` -------------------------------- ### Get Project Balance Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves the current balance and billing information for a specific project. Essential for managing account credits and billing status. ```APIDOC ## get_balance ### Description Retrieves the current balance and billing information for a project. ### Method Rust SDK Method ### Parameters #### Path Parameters - **project_id** (string) - Required - Project identifier ### Response #### Success Response - **BalanceResponse** - Contains balance and billing details. ``` -------------------------------- ### Add Tokio Runtime to Cargo Project Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/README.md Install the Tokio runtime, which is likely needed for asynchronous operations with the Deepgram SDK. Use the 'full' features for comprehensive support. ```sh cargo add tokio --features full ``` -------------------------------- ### Get Project Usage Statistics Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves usage statistics for a specific project within a given date range. Requires a project ID and query options. ```rust pub async fn get_usage( &self, project_id: &str, options: &Options, ) -> crate::Result ``` -------------------------------- ### Get API Keys Management Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Keys instance for managing API keys within projects. This handler allows for the creation and management of keys. ```rust let keys = deepgram.keys(); ``` -------------------------------- ### Get Members Management Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Members instance for managing project members. Use this to add, remove, or manage users within your projects. ```rust let members = deepgram.members(); ``` -------------------------------- ### Get Member Details Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves the details of a specific member within a project. ```APIDOC ## Members::get(project_id: &str, member_id: &str) ### Description Retrieves details of a specific member. ### Parameters #### Path Parameters - **project_id** (string) - Required - Project identifier - **member_id** (string) - Required - Member identifier ### Returns - `Result` ``` -------------------------------- ### Checking Word Confidence Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/response-types.md An example of iterating through the words in a `ResultAlternative` and identifying words with low confidence. ```rust for word in &alternative.words { if word.confidence < 0.5 { println!("Low confidence word: {} ({})", word.word, word.confidence); } } ``` -------------------------------- ### Submitting Prerecorded Transcription with Callback Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/response-types.md Demonstrates how to submit a prerecorded audio source for transcription and receive a callback at a specified URL. The response contains the request ID for tracking. ```rust let callback_response = dg.transcription() .prerecorded_callback(source, &options, "https://example.com/callback") .await?; println!("Request submitted with ID: {}", callback_response.request_id); // Results will be POSTed to your callback URL ``` -------------------------------- ### Add Deepgram SDK to Cargo Project Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/README.md Install the Deepgram Rust SDK using the Cargo package manager. ```sh cargo add deepgram ``` -------------------------------- ### Keys::create Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Creates a new API key for a project with specified options. The key is only returned once upon creation. ```APIDOC ## Keys::create(project_id: &str, options: &Options) ### Description Creates a new API key for a project. The key is only returned once upon creation. ### Method Rust SDK method call ### Parameters #### Path Parameters - **project_id** (string) - Required - Project identifier - **options** (Options) - Required - Key configuration (name, scopes) ### Returns - **Result** - A result containing the newly created API key details or a Deepgram error. ### Example ```rust use deepgram::manage::keys::options::Options; // Assuming 'dg' is an initialized Deepgram client let opts = Options::builder("my-new-api-key", ["usage:read"]).build(); let new_key = dg.keys().create("your-project-id", &opts).await?; println!("New Key: {}", new_key.key); // Store this securely ``` ``` -------------------------------- ### Word Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/response-types.md Provides details for a single word in the transcription, including its text, start and end times, confidence, and speaker information. ```APIDOC ## Word ### Description Details for an individual word within a transcription. ### Fields - **word** (`String`) - The word text. - **start** (`f64`) - Start time in seconds. - **end** (`f64`) - End time in seconds. - **confidence** (`f64`) - Word-level confidence (0.0-1.0). - **speaker** (`Option`) - Speaker ID (if diarization enabled). ### Example ```rust for word in &alternative.words { if word.confidence < 0.5 { println!("Low confidence word: {} ({})", word.word, word.confidence); } } ``` ``` -------------------------------- ### Creating a Flux Builder Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/flux-api.md Demonstrates how to initialize the Deepgram client and create a Flux request builder, both with default options and with custom configurations. ```APIDOC ## Creating a Flux Builder ### Description This section shows how to create a Flux request builder using the Deepgram SDK. You can use the default Flux model or specify custom options. ### Usage **Default Flux Builder (FluxGeneralEn):** ```rust use deepgram::{Deepgram, common::options::Model}; let dg = Deepgram::new("YOUR_API_KEY")?; let transcription = dg.transcription(); // Default Flux (FluxGeneralEn) let builder = transcription.flux_request(); ``` **Flux Builder with Custom Options:** ```rust use deepgram::common::options::Options; let options = Options::builder() .model(Model::FluxGeneralEn) .eager_eot_threshold(0.8) .build(); let builder = transcription.flux_request_with_options(options); ``` ### Models - **`Model::FluxGeneralEn`**: English-only conversational model. - **`Model::FluxGeneralMulti`**: Multilingual conversational model supporting code-switching. **Example with Multilingual Model and Language Hints:** ```rust use deepgram::common::options::Options; let options = Options::builder() .model(Model::FluxGeneralMulti) .language_hint(vec!["en", "es"]) // Bias toward English and Spanish .build(); let builder = transcription.flux_request_with_options(options); ``` ``` -------------------------------- ### Get Text-to-Speech Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Speak instance for accessing text-to-speech APIs. This handler is used for generating speech from text. ```rust let tts = deepgram.text_to_speech(); ``` -------------------------------- ### Deepgram::new Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Constructs a new Deepgram client using an API key. This is the standard way to initialize the client for Deepgram's hosted API. ```APIDOC ## Deepgram::new(api_key: K) -> Result ### Description Constructs a new Deepgram client pointed at Deepgram's hosted API (`https://api.deepgram.com`). The API key is automatically wrapped with the "Token" authentication prefix. ### Parameters - **api_key** (K, impl AsRef) - Required - Deepgram API key from the console ### Returns - `Result` ### Errors - `DeepgramError::InvalidUrl` if the default base URL cannot be parsed (unlikely) - Error from `reqwest::ClientBuilder::build` ### Example ```rust use deepgram::Deepgram; let deepgram = Deepgram::new("YOUR_DEEPGRAM_API_KEY")?; ``` ``` -------------------------------- ### AudioSource Methods Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/module-reference.md Methods for creating an AudioSource from a URL or a byte buffer. ```APIDOC ## `AudioSource::from_url` ### Description Creates an `AudioSource` from a URL. ### Method `AudioSource::from_url(url: impl Into) -> Self` ## `AudioSource::from_buffer` ### Description Creates an `AudioSource` from a byte buffer. ### Method `AudioSource::from_buffer(buffer: impl Into) -> Self` ## `AudioSource::from_buffer_with_mime_type` ### Description Creates an `AudioSource` from a byte buffer with a specified MIME type. ### Method `AudioSource::from_buffer_with_mime_type(buffer: impl Into, mime_type: impl Into) -> Self` ``` -------------------------------- ### Get Project Usage Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves usage statistics for a specific project within a given date range. This is useful for monitoring API consumption. ```APIDOC ## get_usage ### Description Retrieves usage statistics for a project within a date range. ### Method Rust SDK Method ### Parameters #### Path Parameters - **project_id** (string) - Required - Project identifier #### Query Parameters - **options** (Options) - Required - Query options (start_date, end_date, etc.) ### Response #### Success Response - **UsageResponse** - Contains usage statistics. ``` -------------------------------- ### List Projects Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves all projects accessible with the current API key. Ensure you have a valid API key configured. ```rust let projects = dg.projects().list().await?; for project in projects.projects { println!("Project: {}", project.name); } ``` -------------------------------- ### WebSocket Streaming with Default Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Begins configuration of a WebSocket streaming request with default `Options`. Use builder methods to configure before connecting. ```APIDOC ## WebSocket Streaming with Default Options ### Description Begins configuration of a WebSocket streaming request with default `Options`. Use builder methods to configure before connecting. ### Method ```rust pub fn stream_request(&self) -> WebsocketBuilder<'_> ``` ### Returns `WebsocketBuilder<'_>` ### Example ```rust let builder = dg.transcription().stream_request(); ``` ``` -------------------------------- ### Initialize Deepgram with API Key Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/README.md Use this to initialize the Deepgram client with your API key. Ensure you replace 'YOUR_DEEPGRAM_API_KEY' with your actual key. ```rust use deepgram::Deepgram; let dg = Deepgram::new("YOUR_DEEPGRAM_API_KEY"); ``` -------------------------------- ### Get Authentication Token Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/response-types.md Obtain a JWT access token for authenticating with the Deepgram API. The token expiration can be checked using the `expires_in` field. ```rust let response = dg.auth().grant(Some(&options)).await?; println!("Token: {}", response.access_token); println!("Expires in: {} seconds", response.expires_in.unwrap_or(30.0)); ``` -------------------------------- ### Bump Version with cargo-edit Source: https://github.com/deepgram/deepgram-rust-sdk/wiki/Bumping-Versions Use this command to bump a specific version field (major, minor, patch, or alpha). Ensure `cargo-edit` is installed. ```bash cargo set-version --bump ``` -------------------------------- ### Create Audio Source from URL Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Constructs an `AudioSource` by providing a URL. Deepgram will download the audio content from this URL for transcription. ```rust pub fn from_url(url: impl Into) -> Self ``` -------------------------------- ### Create Audio Source from Buffer with MIME Type Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Constructs an `AudioSource` from a buffer with an explicitly specified MIME type. This is useful when the MIME type cannot be automatically determined. ```rust pub fn from_buffer_with_mime_type(buffer: impl Into, mime_type: impl Into) -> Self ``` -------------------------------- ### Handle Internal Client Error in Rust Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/error-handling.md This example shows how to catch and log unexpected internal errors within the Deepgram client, which are typically rare. ```rust match result { Err(DeepgramError::InternalClientError(e)) => { eprintln!("Internal client error: {}", e); } _ => {} } ``` -------------------------------- ### Create an API Key Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/quick-start.md Creates a new API key for a specified project with given scopes. ```APIDOC ## Create an API Key ### Description Creates a new API key for a specified project with given scopes. ### Method `dg.keys().create(project_id, &options).await` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use deepgram::Deepgram; use deepgram::manage::keys::options::Options; #[tokio::main] async fn main() -> Result<(), Box> { let dg = Deepgram::new("YOUR_API_KEY")?; let options = Options::builder( "my-new-key", ["usage:read", "usage:write"] ).build(); let key = dg.keys() .create("project-id-123", &options) .await?; println!("New key created: {}", key.key_id); println!("Key: {} (store this securely!)", key.key); Ok(()) } ``` ### Response #### Success Response (200) - **key** (Key) - The newly created API key object. ``` -------------------------------- ### Transcription::stream_request_with_options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/module-reference.md Initializes a builder for a real-time WebSocket streaming connection with specified transcription options. ```APIDOC ## Transcription::stream_request_with_options ### Description Initializes a builder for a real-time WebSocket streaming connection with specified transcription options. ### Method Signature `stream_request_with_options(options: Options) -> WebsocketBuilder<'_>` ### Parameters - `options` (Options): Configuration options for the WebSocket stream. ### Returns - `WebsocketBuilder<'_>`: A builder for configuring and initiating a WebSocket stream. ``` -------------------------------- ### Utterance Details Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/response-types.md Information about a detected utterance, including its start and end times, confidence, transcript, and associated words. This is returned when utterance segmentation is enabled. ```APIDOC ## Utterance ### Description Details about a detected utterance, including timing, confidence, transcript, and word-level information. This is part of the transcription results when utterance segmentation is enabled. ### Fields - **start** (f64) - Utterance start time in seconds - **end** (f64) - Utterance end time in seconds - **confidence** (f64) - Utterance confidence (0.0-1.0) - **channel** (usize) - Channel number - **transcript** (String) - Full utterance transcript - **words** (Vec) - Per-word details - **speaker** (Option) - Speaker ID (if diarization enabled) - **id** (Uuid) - Unique utterance identifier ### Example ```rust if let Some(utterances) = &response.results.utterances { for utt in utterances { if let Some(speaker) = utt.speaker { println!("Speaker {}: {}", speaker, utt.transcript); } } } ``` ``` -------------------------------- ### WebsocketBuilder::handle() Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/websocket-streaming.md Creates a bare WebSocket handle for manual audio streaming, allowing for custom audio frame management. ```APIDOC ## WebsocketBuilder::handle() ### Description Creates a bare WebSocket handle for manual audio streaming. ### Returns `Result` ### Usage Connects to Deepgram's WebSocket endpoint without automatically streaming audio. This method is intended for scenarios where you need to manually control the sending of audio frames. ### Example ```rust let mut stream = dg.transcription() .stream_request() .handle() .await?; // Send audio frames manually stream.send_binary(audio_frame).await?; ``` ``` -------------------------------- ### Set Sample Rate for Websocket Stream Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/websocket-streaming.md Configure the audio sample rate in Hertz (Hz). For example, use `16000` for a 16 kHz sample rate. ```rust let builder = dg.transcription() .stream_request() .encoding(Encoding::Linear16) .sample_rate(16000); ``` -------------------------------- ### Projects::get Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves details of a specific project. ```APIDOC ## Projects::get ### Description Retrieves details of a specific project. ### Method GET ### Endpoint /v1/projects/{project_id} ### Parameters #### Path Parameters - **project_id** (string) - Required - Unique identifier of the project ### Response #### Success Response (200) - **id** (string) - The unique identifier of the project. - **name** (string) - The name of the project. - **created** (string) - The date and time the project was created. - **company** (string) - The company associated with the project. - **status** (string) - The status of the project. - **owner_id** (string) - The ID of the project owner. ### Request Example ```rust let project = dg.projects().get("project-id-123").await?; println!("Project name: {}", project.name); ``` ``` -------------------------------- ### Text-to-Speech (Speak) Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/INDEX.md Convert text to speech and save the output to a file. Specify the text, options, and output file path. ```rust dg.text_to_speech() .speak_to_file("Hello", &options, Path::new("out.wav")) .await?; ``` -------------------------------- ### Access Deepgram Client Reference Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Use this method to get a reference to the underlying Deepgram client. This is useful if you need direct access to the client's functionality. ```rust pub fn deepgram(&self) -> &Deepgram ``` ```rust let deepgram_ref = transcription.deepgram(); ``` -------------------------------- ### Real-Time Streaming Transcription Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/INDEX.md Set up a real-time transcription stream. Configure audio encoding and sample rate before initiating the stream. ```rust let mut stream = dg.transcription() .stream_request() .encoding(Encoding::Linear16) .sample_rate(16000) .stream() .await?; while let Some(result) = stream.next().await { // Handle result } ``` -------------------------------- ### Get Usage Management Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Usage instance for querying API usage and requests. This handler helps monitor your Deepgram service consumption. ```rust let usage = deepgram.usage(); ``` -------------------------------- ### Projects::list Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves all projects accessible with the current API key. ```APIDOC ## Projects::list ### Description Retrieves all projects accessible with the current API key. ### Method GET ### Endpoint /v1/projects ### Parameters #### Query Parameters - **limit** (integer) - Optional - Maximum number of projects to return. - **cursor** (string) - Optional - Cursor for pagination. ### Response #### Success Response (200) - **projects** (array) - A list of project objects. - **id** (string) - The unique identifier of the project. - **name** (string) - The name of the project. - **created** (string) - The date and time the project was created. - **company** (string) - The company associated with the project. - **status** (string) - The status of the project. - **owner_id** (string) - The ID of the project owner. ### Request Example ```rust let projects = dg.projects().list().await?; for project in projects.projects { println!("Project: {}", project.name); } ``` ``` -------------------------------- ### Token Options Configuration Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/module-reference.md The `auth::options` module provides types and methods for configuring token generation options, including setting the time-to-live (TTL). ```APIDOC ## `deepgram::auth::options` Module ### Description Enables configuration of token generation parameters. ### Public Types - `Options`: Represents the configuration for token generation. - `OptionsBuilder`: A builder pattern for constructing `Options`. ### Methods - `Options::builder() -> OptionsBuilder`: Creates a new `OptionsBuilder`. - `OptionsBuilder::ttl_seconds(seconds: f64) -> Self`: Sets the time-to-live for the token in seconds. - `OptionsBuilder::build() -> Options`: Constructs the `Options` object from the builder. ``` -------------------------------- ### Get Scopes Information Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Scopes instance for querying available API scopes. This handler provides information about permissions and access levels. ```rust let scopes = deepgram.scopes(); ``` -------------------------------- ### Create Bare Flux Handle for Manual Streaming Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/flux-api.md Obtain a bare Flux handle using the `handle` method for manual control over sending audio frames. This is useful for custom streaming logic. ```rust let mut stream = dg.transcription() .flux_request() .handle() .await?; // Send audio frames manually stream.send_binary(audio_frame).await?; ``` -------------------------------- ### Dynamic Configuration During Streaming Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/flux-api.md Establishes a real-time transcription stream and demonstrates dynamic configuration of thresholds during the stream. It sends audio data and then receives transcription results, allowing for adjustments to end-of-turn detection parameters. ```rust use deepgram::{Deepgram, common::{options::Encoding, flux_response::ConfigureThresholds}}; use futures::stream::StreamExt; use std::time::Duration; #[tokio::main] async fn main() -> Result<(), Box> { let dg = Deepgram::new("YOUR_API_KEY")?; let mut stream = dg.transcription() .flux_request() .encoding(Encoding::Linear16) .sample_rate(16000) .handle() .await?; // Adjust thresholds dynamically let config = ConfigureThresholds { eager_eot_threshold: Some(0.85), eot_timeout_ms: Some(2000), ..Default::default() }; stream.configure(config).await?; // Send audio let audio = vec![/* audio bytes */]; stream.send_binary(audio).await?; // Receive results while let Some(result) = stream.next().await { match result { Ok(response) => println!("{:?}", response), Err(e) => eprintln!("Error: {}", e), } } Ok(()) } ``` -------------------------------- ### Keys::list Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Lists all API keys for a specified project. Requires the project ID. ```APIDOC ## Keys::list(project_id: &str) ### Description Lists all API keys for a project. ### Method Rust SDK method call ### Parameters #### Path Parameters - **project_id** (string) - Required - Project identifier ### Returns - **Result** - A result containing the list of API keys or a Deepgram error. ### Example ```rust // Assuming 'dg' is an initialized Deepgram client let keys = dg.keys().list("your-project-id").await?; ``` ``` -------------------------------- ### Transcription::flux_request_with_options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/module-reference.md Initializes a builder for a Flux conversational streaming connection with specified transcription options. ```APIDOC ## Transcription::flux_request_with_options ### Description Initializes a builder for a Flux conversational streaming connection with specified transcription options. ### Method Signature `flux_request_with_options(options: Options) -> FluxBuilder<'_>` ### Parameters - `options` (Options): Configuration options for the Flux stream. ### Returns - `FluxBuilder<'_>`: A builder for configuring and initiating a Flux stream. ``` -------------------------------- ### Flux Conversational Streaming with Default Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Begins configuration of a Flux streaming request with default `Model::FluxGeneralEn`. Use builder methods to customize before connecting. ```APIDOC ## Flux Conversational Streaming with Default Options ### Description Begins configuration of a Flux streaming request. Defaults to `Model::FluxGeneralEn`. Use builder methods to customize before connecting. ### Method ```rust pub fn flux_request(&self) -> FluxBuilder<'_> ``` ### Returns `FluxBuilder<'_>` ### Example ```rust let builder = dg.transcription().flux_request(); ``` ``` -------------------------------- ### Emit VAD Events for Websocket Stream Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/websocket-streaming.md Enable the `vad_events` option to receive Voice Activity Detection (VAD) events, which signal the start and end of speech segments. ```rust let builder = dg.transcription() .stream_request() .vad_events(true); ``` -------------------------------- ### Encode Transcription Options to URL-encoded String Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-options.md Use this method to get a URL-encoded string representation of your transcription options, useful for debugging. Ensure you handle the `Result` as the operation can fail. ```rust let options = Options::builder() .model(Model::Nova2) .punctuate(true) .build(); let encoded = options.urlencoded()?; println!("{}", encoded); // "model=nova-2&punctuate=true" ``` -------------------------------- ### AudioSource::from_url Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Constructs an audio source that instructs Deepgram to download audio from the specified URL. ```APIDOC ## AudioSource::from_url ### Description Constructs an audio source that instructs Deepgram to download audio from the specified URL. ### Signature ```rust pub fn from_url(url: impl Into) -> Self ``` ``` -------------------------------- ### deepgram::manage::usage Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/module-reference.md Provides functionality for tracking and retrieving usage data for a Deepgram project. This includes getting overall usage, listing requests, and retrieving field information. ```APIDOC ## `deepgram::manage::usage` Module ### Methods - `get_usage(project_id: &str, options: &Options) -> Result` - `list_requests(project_id: &str, options: &Options) -> Result` - `get_fields(project_id: &str, options: &Options) -> Result` ``` -------------------------------- ### Get Transcription Handler Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Creates a new Transcription instance for accessing speech-to-text APIs. Use this to interact with prerecorded audio transcription, live streaming, and Flux conversational APIs. ```rust let transcription = deepgram.transcription(); ``` -------------------------------- ### Enable Smart Formatting Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-options.md Use `smart_format(true)` to enable smart formatting for elements like currency, dates, and times. This option is available via the `OptionsBuilder`. ```rust let options = Options::builder() .smart_format(true) .build(); ``` -------------------------------- ### FluxBuilder::handle Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/flux-api.md Creates a bare Flux handle for manual audio streaming. ```APIDOC ## FluxBuilder::handle() -> Result ### Description Creates a bare Flux handle for manual audio streaming. ### Returns - `Result` ### Request Example ```rust let mut stream = dg.transcription() .flux_request() .handle() .await?; // Send audio frames manually stream.send_binary(audio_frame).await?; ``` ``` -------------------------------- ### Initialize Deepgram Client with Async/Await in Rust Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/INDEX.md Set up the Deepgram client for asynchronous operations using `#[tokio::main]` or another compatible runtime. All I/O operations with the Deepgram SDK are asynchronous. ```rust #[tokio::main] async fn main() -> Result<(), Box> { let dg = Deepgram::new("API_KEY")?; // Use dg... Ok(()) } ``` -------------------------------- ### Define Custom Topics Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-options.md Use this option to specify custom topics for detection. Provide a vector of strings representing the topics. ```rust let options = Options::builder() .topics(true) .custom_topics(vec!["pricing", "support", "feature_request"]) .build(); ``` -------------------------------- ### Construct Deepgram Client with API Key Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/deepgram-client.md Use this constructor to create a Deepgram client with your API key for authenticating with Deepgram's hosted API. The API key is automatically prefixed with 'Token'. ```rust use deepgram::Deepgram; let deepgram = Deepgram::new("YOUR_DEEPGRAM_API_KEY")?; ``` -------------------------------- ### Flux Connection Builder and Stream Methods Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/module-reference.md Methods for building and interacting with a Flux connection for real-time audio streaming. ```APIDOC ## `deepgram::listen::flux` Module ### Builder Methods - `encoding(encoding: Encoding) -> Self` - `sample_rate(rate: u32) -> Self` - `stream() -> Result` - `file(path, frame_size, frame_delay) -> Result` - `handle() -> Result` ### Stream Methods - `send(message: Message) -> Result<()>` - `send_binary(data: impl Into>) -> Result<()>` - `send_close() -> Result<()>` - `configure(config: ConfigureThresholds) -> Result<()>` - `next() -> Option>` (Stream trait) ``` -------------------------------- ### Process Search Results and Hit Locations Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/response-types.md Iterate through search results to display the search query and the specific locations (start and end times) where each term was found. This is useful for analyzing search term occurrences within the transcribed audio. ```rust if let Some(search_results) = &channel.search { for result in search_results { println!("Search term: {}", result.query); for hit in &result.hits { println!(" Found at: {}s - {}s", hit.start, hit.end); } } } ``` -------------------------------- ### WebSocket Streaming with Custom Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Begins configuration of a WebSocket streaming request with specific `Options`. Pre-configured transcription options are required. ```APIDOC ## WebSocket Streaming with Custom Options ### Description Begins configuration of a WebSocket streaming request with specific `Options`. Pre-configured transcription options are required. ### Method ```rust pub fn stream_request_with_options(&self, options: Options) -> WebsocketBuilder<'_> ``` ### Parameters #### Path Parameters - **options** (Options) - Required - Pre-configured transcription options ### Returns `WebsocketBuilder<'_>` ### Example ```rust let options = Options::builder() .model(Model::Nova2) .punctuate(true) .build(); let builder = dg.transcription().stream_request_with_options(options); ``` ``` -------------------------------- ### Client-Side Token Authentication Pattern Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/authentication-api.md Demonstrates a common pattern for using temporary tokens in client applications. It involves generating a token on the server and then using it to authenticate API requests from the client. ```rust // Server-side: Generate a token #[tokio::main] async fn generate_token() -> Result { let dg = Deepgram::new("YOUR_API_KEY")?; let options = deepgram::auth::options::Options::builder() .ttl_seconds(300.0) // 5 minutes for a user session .build(); let response = dg.auth().grant(Some(&options)).await?; Ok(response.access_token) } // Client-side: Use the token #[tokio::main] async fn transcribe_with_token(token: String) -> Result<(), deepgram::DeepgramError> { let dg = Deepgram::with_temp_token(&token)?; let transcription = dg.transcription(); // Use transcription API with the temporary token Ok(()) } ``` -------------------------------- ### Build the Deepgram SDK Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/README.md Compile the Deepgram Rust SDK from source using Cargo. ```sh cargo build ``` -------------------------------- ### Simple Real-Time WebSocket Streaming Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/websocket-streaming.md Initiates a real-time transcription stream with custom options, including punctuation and interim results. Suitable for live audio input. ```rust use deepgram::{Deepgram, common::options::{Encoding, Options}}; use futures::stream::StreamExt; use std::time::Duration; #[tokio::main] async fn main() -> Result<(), Box> { let dg = Deepgram::new("YOUR_API_KEY")?; let options = Options::builder() .punctuate(true) .build(); let mut stream = dg.transcription() .stream_request_with_options(options) .encoding(Encoding::Linear16) .sample_rate(16000) .interim_results(true) .stream() .await?; while let Some(result) = stream.next().await { match result { Ok(response) => println!("Result: {:?}", response), Err(e) => eprintln!("Error: {}", e), } } Ok(()) } ``` -------------------------------- ### List All Members Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Lists all members in a specified project. ```APIDOC ## Members::list_all(project_id: &str) ### Description Lists all members in a project. ### Parameters #### Path Parameters - **project_id** (string) - Required - Project identifier ### Returns - `Result` ``` -------------------------------- ### Set Audio Sample Rate with FluxBuilder Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/flux-api.md Configure the audio sample rate in Hz using the `sample_rate` method. This is essential for accurate audio processing. ```rust let builder = dg.transcription() .flux_request() .sample_rate(16000); ``` -------------------------------- ### Keys::get Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Retrieves details of a specific API key. Requires both the project ID and the key ID. ```APIDOC ## Keys::get(project_id: &str, key_id: &str) ### Description Retrieves details of a specific API key. ### Method Rust SDK method call ### Parameters #### Path Parameters - **project_id** (string) - Required - Project identifier - **key_id** (string) - Required - Key identifier ### Returns - **Result** - A result containing the API key details or a Deepgram error. ### Example ```rust // Assuming 'dg' is an initialized Deepgram client let key_details = dg.keys().get("your-project-id", "your-key-id").await?; ``` ``` -------------------------------- ### Authenticate with API Key Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/quick-start.md Initialize the Deepgram client using your API key. Ensure the API key is kept secret. ```rust use deepgram::Deepgram; #[tokio::main] async fn main() -> Result<(), Box> { let deepgram = Deepgram::new("YOUR_API_KEY")?; Ok(()) } ``` -------------------------------- ### Create Audio Source from Buffer Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Constructs an `AudioSource` from a buffer, such as bytes or a file. This buffer will be uploaded to Deepgram for transcription. ```rust pub fn from_buffer(buffer: impl Into) -> Self ``` -------------------------------- ### List Project API Requests Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Lists all API requests made by a project, optionally filtered by date range and limit. Requires a project ID and query options. ```rust pub async fn list_requests( &self, project_id: &str, options: &Options, ) -> crate::Result ``` -------------------------------- ### Provide Language Hints - Rust Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-options.md Supplies hints to bias automatic language detection, particularly useful for the Flux model when dealing with multiple potential languages. ```rust let options = Options::builder() .model(Model::FluxGeneralMulti) .language_hint(vec!["en", "es"]) .build(); ``` -------------------------------- ### Flux Conversational Streaming with Custom Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-api.md Begins configuration of a Flux streaming request with specific `Options`. Pre-configured transcription options are required. ```APIDOC ## Flux Conversational Streaming with Custom Options ### Description Begins configuration of a Flux streaming request with specific `Options`. Pre-configured transcription options are required. ### Method ```rust pub fn flux_request_with_options(&self, options: Options) -> FluxBuilder<'_> ``` ### Parameters #### Path Parameters - **options** (Options) - Required - Pre-configured transcription options ### Returns `FluxBuilder<'_>` ### Example ```rust let options = Options::builder() .model(Model::FluxGeneralEn) .eager_eot_threshold(0.8) .build(); let builder = dg.transcription().flux_request_with_options(options); ``` ``` -------------------------------- ### Topic Detection Options Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/transcription-options.md Configure options for topic detection, including enabling it and defining custom topics. ```APIDOC ## OptionsBuilder::topics(enabled: bool) -> Self ### Description Enables topic detection. ### Parameters - **enabled** (bool) - Required - Enable detection ### Request Example ```rust let options = Options::builder() .topics(true) .build(); ``` ``` ```APIDOC ## OptionsBuilder::custom_topics(topics: Vec>) -> Self ### Description Defines custom topics to detect. ### Parameters - **topics** (Vec>) - Required - Custom topic strings ### Request Example ```rust let options = Options::builder() .topics(true) .custom_topics(vec!["pricing", "support", "feature_request"]) .build(); ``` ``` -------------------------------- ### Invitations API - Send Source: https://github.com/deepgram/deepgram-rust-sdk/blob/main/_autodocs/management-api.md Sends an invitation to join a project. ```APIDOC ## Invitations API - Send ### Description Sends an invitation to join a project. ### Method POST ### Endpoint /v1/projects/{project_id}/invitations ### Parameters #### Path Parameters - **project_id** (string) - Required - Project identifier #### Request Body - **email** (string) - Required - Email of the invitation recipient - **role** (string) - Required - Role to assign to the invited member ```