Skip to content

Commit 37274a1

Browse files
authored
Merge pull request #3 from deepgram-devs/mlodato517-minor-reorg
Get `api_key` first to avoid intermediate builder
2 parents f441091 + dc3d5c8 commit 37274a1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/main.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,14 @@ fn f32_to_i16(sample: f32) -> i16 {
182182
/// also be executed in an async runtime.
183183
async fn connect_to_deepgram(
184184
) -> tokio_tungstenite::WebSocketStream<tokio_tungstenite::MaybeTlsStream<tokio::net::TcpStream>> {
185+
let api_key = std::env::var("DEEPGRAM_API_KEY").expect("Deepgram API Key is required.");
186+
185187
// prepare the connection request with the api key authentication
186188
// TODO: don't hardcode the encoding, sample rate, or number of channels
187-
let builder = http::Request::builder()
189+
let request = http::Request::builder()
188190
.method(http::Method::GET)
189-
.uri("wss://api.deepgram.com/v1/listen?encoding=linear16&sample_rate=44100&channels=1");
190-
191-
let api_key = std::env::var("DEEPGRAM_API_KEY").expect("Deepgram API Key is required.");
192-
let builder = builder.header("Authorization", format!("Token {}", api_key));
193-
let request = builder
191+
.uri("wss://api.deepgram.com/v1/listen?encoding=linear16&sample_rate=44100&channels=1")
192+
.header("Authorization", format!("Token {}", api_key))
194193
.body(())
195194
.expect("Failed to build a connection request to Deepgram.");
196195

0 commit comments

Comments
 (0)