Skip to content

Commit 3137a45

Browse files
committed
feat: support opus
1 parent 88fa02b commit 3137a45

File tree

7 files changed

+1336
-5
lines changed

7 files changed

+1336
-5
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ _no_default = []
2929
box = ["_no_default"]
3030
cube = ["_no_default"]
3131
cube2 = ["_no_default"]
32+
nfc_cube2 = ["cube2", "mfrc522", "exio"]
3233

3334
mfrc522 = ["i2c", "dep:ndef", "extra_server"]
3435
exio = ["i2c"]
@@ -95,3 +96,8 @@ bindings_module = "esp_sr"
9596
component_dirs = ["components/hal_driver"]
9697
bindings_header = "components/hal_driver/wrapper.h"
9798
bindings_module = "hal_driver"
99+
100+
[[package.metadata.esp-idf-sys.extra_components]]
101+
remote_component = { name = "78/esp-opus", version = "^1.0.5" }
102+
bindings_header = "components/78_opus/bindgen.h"
103+
bindings_module = "xz_78_opus"

src/app.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ async fn select_evt(
9696
Event::ServerEvent(ServerEvent::AudioChunk { .. })=>{
9797
log::debug!("[Select] Received AudioChunk");
9898
}
99+
Event::ServerEvent(ServerEvent::AudioChunki16 { .. })=>{
100+
log::debug!("[Select] Received AudioChunki16");
101+
}
99102
Event::ServerEvent(ServerEvent::HelloChunk { .. })=>{
100103
log::debug!("[Select] Received HelloChunk");
101104
}
@@ -459,6 +462,31 @@ pub async fn main_work<'d>(
459462
recv_audio_buffer.extend_from_slice(data_);
460463
}
461464
}
465+
Event::ServerEvent(ServerEvent::AudioChunki16 { data }) => {
466+
log::debug!("Received audio chunk");
467+
if state != State::Speaking {
468+
log::debug!("Received audio chunk while not speaking");
469+
continue;
470+
}
471+
472+
if need_compute {
473+
if start_audio {
474+
metrics.reset();
475+
start_audio = false;
476+
}
477+
metrics.add_data(data.len() * 2);
478+
}
479+
480+
if speed < SPEED_LIMIT {
481+
if let Err(e) = player_tx.send(AudioEvent::SpeechChunki16(data)) {
482+
log::error!("Error sending audio chunk: {:?}", e);
483+
gui.state = "Error on audio chunk".to_string();
484+
gui.display_flush().unwrap();
485+
}
486+
} else {
487+
recv_audio_buffer.extend_from_slice(&data);
488+
}
489+
}
462490
Event::ServerEvent(ServerEvent::EndAudio) => {
463491
log::info!("Received audio end");
464492

src/codec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod opus;

0 commit comments

Comments
 (0)