Skip to content

Commit 733dad7

Browse files
committed
feat: new metrics
1 parent 43a249f commit 733dad7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/app.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub async fn main_work<'d>(
180180

181181
let mut metrics = DownloadMetrics::new();
182182
let mut need_compute = true;
183+
let mut start_audio = false;
183184
let mut speed = 1.5;
184185
let mut vol = 3u8;
185186

@@ -195,9 +196,7 @@ pub async fn main_work<'d>(
195196
{
196197
match evt {
197198
Event::Event(Event::GAIA | Event::K0) => {
198-
log::info!("Received event: gaia");
199-
// gui.state = "gaia".to_string();
200-
// gui.display_flush().unwrap();
199+
log::info!("Received event: k0");
201200

202201
if state == State::Listening {
203202
state = State::Idle;
@@ -278,7 +277,7 @@ pub async fn main_work<'d>(
278277
}
279278
submit_audio += data.len() as f32 / 16000.0;
280279
audio_buffer.extend_from_slice(&data);
281-
// 0.25秒提交一次
280+
282281
if audio_buffer.len() >= 8192 && submit_audio > 0.5 {
283282
if !start_submit {
284283
log::info!("Start submitting audio");
@@ -402,9 +401,7 @@ pub async fn main_work<'d>(
402401
gui.display_flush().unwrap();
403402
}
404403
Event::ServerEvent(ServerEvent::StartAudio { text }) => {
405-
if need_compute {
406-
metrics.reset();
407-
}
404+
start_audio = true;
408405
if state != State::Speaking {
409406
log::debug!("Received StartAudio while not in speaking state");
410407
continue;
@@ -425,6 +422,10 @@ pub async fn main_work<'d>(
425422
}
426423

427424
if need_compute {
425+
if start_audio {
426+
metrics.reset();
427+
start_audio = false;
428+
}
428429
metrics.add_data(data.len());
429430
}
430431

@@ -449,6 +450,8 @@ pub async fn main_work<'d>(
449450
continue;
450451
}
451452

453+
start_audio = false;
454+
452455
if recv_audio_buffer.len() > 0 {
453456
if let Err(e) = player_tx.send(AudioEvent::SpeechChunki16(recv_audio_buffer)) {
454457
log::error!("Error sending audio chunk: {:?}", e);

0 commit comments

Comments
 (0)