-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add warning for callback_method for streaming * add callback parameter to WebsocketBuilder * fix clippy * add method on websocket to get request id * documentation and error fix
- Loading branch information
Showing
7 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::env; | ||
use std::time::Duration; | ||
|
||
use futures::stream::StreamExt; | ||
|
||
use deepgram::{ | ||
common::options::{Encoding, Endpointing, Language, Options}, | ||
Deepgram, DeepgramError, | ||
}; | ||
|
||
static PATH_TO_FILE: &str = "examples/audio/bueller.wav"; | ||
static AUDIO_CHUNK_SIZE: usize = 3174; | ||
static FRAME_DELAY: Duration = Duration::from_millis(16); | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), DeepgramError> { | ||
let deepgram_api_key = | ||
env::var("DEEPGRAM_API_KEY").expect("DEEPGRAM_API_KEY environmental variable"); | ||
|
||
let dg_client = Deepgram::new(&deepgram_api_key)?; | ||
|
||
let options = Options::builder() | ||
.smart_format(true) | ||
.language(Language::en_US) | ||
.build(); | ||
|
||
let callback_url = env::var("DEEPGRAM_CALLBACK_URL") | ||
.expect("DEEPGRAM_CALLBACK_URL environmental variable") | ||
.parse() | ||
.expect("DEEPGRAM_CALLBACK_URL not a valid URL"); | ||
|
||
let mut results = dg_client | ||
.transcription() | ||
.stream_request_with_options(options) | ||
.keep_alive() | ||
.encoding(Encoding::Linear16) | ||
.sample_rate(44100) | ||
.channels(2) | ||
.endpointing(Endpointing::CustomDurationMs(300)) | ||
.interim_results(true) | ||
.utterance_end_ms(1000) | ||
.vad_events(true) | ||
.no_delay(true) | ||
.callback(callback_url) | ||
.file(PATH_TO_FILE, AUDIO_CHUNK_SIZE, FRAME_DELAY) | ||
.await?; | ||
|
||
println!("Deepgram Request ID: {}", results.request_id()); | ||
while let Some(result) = results.next().await { | ||
println!("got: {:?}", result); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters