Skip to content

Commit 3bacf63

Browse files
committed
Update dependencies to latest version
1 parent b5cdc94 commit 3bacf63

File tree

3 files changed

+46
-59
lines changed

3 files changed

+46
-59
lines changed

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@ categories = ["api-bindings", "multimedia::audio"]
2121
# TODO Investigate which of these dependencies can go behind features.
2222
bytes = "1"
2323
futures = "0.3"
24-
http = "0.2"
24+
http = "1.3"
2525
pin-project = "1"
26-
reqwest = { version = "0.11.22", default-features = false, features = [
26+
reqwest = { version = "^0.12", default-features = false, features = [
2727
"json",
2828
"rustls-tls",
2929
"stream",
3030
] }
31-
serde = { version = "1.0.215", features = ["derive"] }
31+
serde = { version = "1.0.219", features = ["derive"] }
3232
serde_json = "1"
3333
serde_urlencoded = "0.7"
34-
thiserror = "1"
35-
tokio = { version = "1.38.0", features = ["full"] }
36-
tokio-stream = "0.1.15"
37-
tokio-tungstenite = { version = "0.20.1", features = [
34+
thiserror = "2"
35+
tokio = { version = "1.45.1", features = ["full"] }
36+
tokio-stream = "0.1.17"
37+
tokio-tungstenite = { version = "0.27.0", features = [
3838
"rustls-tls-webpki-roots",
3939
], optional = true }
40-
tokio-util = { version = "0.7.1", features = ["codec", "io"] }
41-
tungstenite = { version = "0.20.1", optional = true }
40+
tokio-util = { version = "0.7.15", features = ["codec", "io"] }
41+
tungstenite = { version = "^0.27.0", optional = true }
4242
url = "2"
4343
uuid = { version = "1", features = ["serde"] }
4444
# Dependencies below are specified only to satisfy minimal-versions.
45-
sha256 = "1.5.0"
46-
anyhow = "1.0.86"
45+
sha256 = "1.6.0"
46+
anyhow = "1.0.98"
4747

4848
[dev-dependencies]
49-
cpal = "0.13"
49+
cpal = "^0.16"
5050
crossbeam = "0.8"
5151
audio = "0.2.0"
52-
rodio = { version = "0.17.0" }
52+
rodio = { version = "0.20" }
5353
pkg-config = { version = "0.3.30"}
5454

5555
[features]

examples/transcription/websocket/microphone_stream.rs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::thread;
33

44
use bytes::{BufMut, Bytes, BytesMut};
55
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
6-
use cpal::Sample;
6+
use cpal::{Sample, SampleFormat};
77
use crossbeam::channel::RecvError;
88
use deepgram::common::options::Encoding;
99
use futures::channel::mpsc::{self, Receiver as FuturesReceiver};
@@ -12,6 +12,25 @@ use futures::SinkExt;
1212

1313
use deepgram::{Deepgram, DeepgramError};
1414

15+
macro_rules! create_stream {
16+
($device:ident, $config:expr, $sync_tx:ident, $sample_type:ty) => {
17+
$device
18+
.build_input_stream(
19+
&$config.into(),
20+
move |data: &[$sample_type], _: &_| {
21+
let mut bytes = BytesMut::with_capacity(data.len() * 2);
22+
for sample in data {
23+
bytes.put_i16_le(sample.to_sample());
24+
}
25+
$sync_tx.send(bytes.freeze()).unwrap();
26+
},
27+
|_| panic!(),
28+
None,
29+
)
30+
.unwrap()
31+
};
32+
}
33+
1534
fn microphone_as_stream() -> FuturesReceiver<Result<Bytes, RecvError>> {
1635
let (sync_tx, sync_rx) = crossbeam::channel::unbounded();
1736
let (mut async_tx, async_rx) = mpsc::channel(1);
@@ -30,45 +49,12 @@ fn microphone_as_stream() -> FuturesReceiver<Result<Bytes, RecvError>> {
3049
// dbg!(&config);
3150

3251
let stream = match config.sample_format() {
33-
cpal::SampleFormat::F32 => device
34-
.build_input_stream(
35-
&config.into(),
36-
move |data: &[f32], _: &_| {
37-
let mut bytes = BytesMut::with_capacity(data.len() * 2);
38-
for sample in data {
39-
bytes.put_i16_le(sample.to_i16());
40-
}
41-
sync_tx.send(bytes.freeze()).unwrap();
42-
},
43-
|_| panic!(),
44-
)
45-
.unwrap(),
46-
cpal::SampleFormat::I16 => device
47-
.build_input_stream(
48-
&config.into(),
49-
move |data: &[i16], _: &_| {
50-
let mut bytes = BytesMut::with_capacity(data.len() * 2);
51-
for sample in data {
52-
bytes.put_i16_le(*sample);
53-
}
54-
sync_tx.send(bytes.freeze()).unwrap();
55-
},
56-
|_| panic!(),
57-
)
58-
.unwrap(),
59-
cpal::SampleFormat::U16 => device
60-
.build_input_stream(
61-
&config.into(),
62-
move |data: &[u16], _: &_| {
63-
let mut bytes = BytesMut::with_capacity(data.len() * 2);
64-
for sample in data {
65-
bytes.put_i16_le(sample.to_i16());
66-
}
67-
sync_tx.send(bytes.freeze()).unwrap();
68-
},
69-
|_| panic!(),
70-
)
71-
.unwrap(),
52+
SampleFormat::F32 => create_stream!(device, config, sync_tx, f32),
53+
SampleFormat::I16 => create_stream!(device, config, sync_tx, i16),
54+
SampleFormat::U16 => create_stream!(device, config, sync_tx, u16),
55+
sample_format => {
56+
panic!("Unsupported sample format: {:?}", sample_format);
57+
}
7258
};
7359

7460
stream.play().unwrap();

src/listen/websocket.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use tokio_tungstenite::{tungstenite::protocol::Message, MaybeTlsStream, WebSocke
3535
use tungstenite::{
3636
handshake::client,
3737
protocol::frame::coding::{Data, OpCode},
38+
Utf8Bytes,
3839
};
3940
use url::Url;
4041
use uuid::Uuid;
@@ -517,7 +518,7 @@ async fn run_worker(
517518
// eprintln!("<worker> received websocket close");
518519
return Err(DeepgramError::WebsocketClose {
519520
code: closeframe.code.into(),
520-
reason: closeframe.reason.into_owned(),
521+
reason: closeframe.reason.to_string(),
521522
});
522523
}
523524

@@ -571,13 +572,13 @@ async fn run_worker(
571572
if is_open {
572573
match message {
573574
Some(WsMessage::Audio(audio))=> {
574-
send_message!(ws_stream_send, response_tx, Message::Binary(audio.0));
575+
send_message!(ws_stream_send, response_tx, Message::Binary(Bytes::from(audio.0)));
575576
last_sent_message = tokio::time::Instant::now();
576577

577578
}
578579
Some(WsMessage::ControlMessage(msg)) => {
579580
send_message!(ws_stream_send, response_tx, Message::Text(
580-
serde_json::to_string(&msg).unwrap_or_default()
581+
Utf8Bytes::from(serde_json::to_string(&msg).unwrap_or_default())
581582
));
582583
last_sent_message = tokio::time::Instant::now();
583584
if msg == ControlMessage::CloseStream {
@@ -587,7 +588,7 @@ async fn run_worker(
587588
None => {
588589
// Input stream is shut down. Keep processing responses.
589590
send_message!(ws_stream_send, response_tx, Message::Text(
590-
serde_json::to_string(&ControlMessage::CloseStream).unwrap_or_default()
591+
Utf8Bytes::from(serde_json::to_string(&ControlMessage::CloseStream).unwrap_or_default())
591592
));
592593
is_open = false;
593594
}
@@ -598,9 +599,9 @@ async fn run_worker(
598599
}
599600
// eprintln!("<worker> post loop");
600601
if let Err(err) = ws_stream_send
601-
.send(Message::Text(
602+
.send(Message::Text(Utf8Bytes::from(
602603
serde_json::to_string(&ControlMessage::CloseStream).unwrap_or_default(),
603-
))
604+
)))
604605
.await
605606
{
606607
// If the response channel is closed, there's nothing to be done about it now.

0 commit comments

Comments
 (0)