Matrix commited on
Commit
65f3e54
·
1 Parent(s): 978cd83

chore: use env-filter for tracing log

Browse files
Files changed (6) hide show
  1. Cargo.lock +31 -3
  2. Cargo.toml +2 -2
  3. docker-compose.yaml +0 -0
  4. src/config.rs +5 -0
  5. src/main.rs +9 -6
  6. src/whisper.rs +8 -9
Cargo.lock CHANGED
@@ -1134,6 +1134,15 @@ version = "0.4.20"
1134
  source = "registry+https://github.com/rust-lang/crates.io-index"
1135
  checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
1136
 
 
 
 
 
 
 
 
 
 
1137
  [[package]]
1138
  name = "memchr"
1139
  version = "2.6.4"
@@ -1549,8 +1558,17 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
1549
  dependencies = [
1550
  "aho-corasick",
1551
  "memchr",
1552
- "regex-automata",
1553
- "regex-syntax",
 
 
 
 
 
 
 
 
 
1554
  ]
1555
 
1556
  [[package]]
@@ -1561,9 +1579,15 @@ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
1561
  dependencies = [
1562
  "aho-corasick",
1563
  "memchr",
1564
- "regex-syntax",
1565
  ]
1566
 
 
 
 
 
 
 
1567
  [[package]]
1568
  name = "regex-syntax"
1569
  version = "0.8.2"
@@ -2186,10 +2210,14 @@ version = "0.3.17"
2186
  source = "registry+https://github.com/rust-lang/crates.io-index"
2187
  checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
2188
  dependencies = [
 
2189
  "nu-ansi-term",
 
 
2190
  "sharded-slab",
2191
  "smallvec",
2192
  "thread_local",
 
2193
  "tracing-core",
2194
  "tracing-log",
2195
  ]
 
1134
  source = "registry+https://github.com/rust-lang/crates.io-index"
1135
  checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
1136
 
1137
+ [[package]]
1138
+ name = "matchers"
1139
+ version = "0.1.0"
1140
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1141
+ checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
1142
+ dependencies = [
1143
+ "regex-automata 0.1.10",
1144
+ ]
1145
+
1146
  [[package]]
1147
  name = "memchr"
1148
  version = "2.6.4"
 
1558
  dependencies = [
1559
  "aho-corasick",
1560
  "memchr",
1561
+ "regex-automata 0.4.3",
1562
+ "regex-syntax 0.8.2",
1563
+ ]
1564
+
1565
+ [[package]]
1566
+ name = "regex-automata"
1567
+ version = "0.1.10"
1568
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1569
+ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
1570
+ dependencies = [
1571
+ "regex-syntax 0.6.29",
1572
  ]
1573
 
1574
  [[package]]
 
1579
  dependencies = [
1580
  "aho-corasick",
1581
  "memchr",
1582
+ "regex-syntax 0.8.2",
1583
  ]
1584
 
1585
+ [[package]]
1586
+ name = "regex-syntax"
1587
+ version = "0.6.29"
1588
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1589
+ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
1590
+
1591
  [[package]]
1592
  name = "regex-syntax"
1593
  version = "0.8.2"
 
2210
  source = "registry+https://github.com/rust-lang/crates.io-index"
2211
  checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77"
2212
  dependencies = [
2213
+ "matchers",
2214
  "nu-ansi-term",
2215
+ "once_cell",
2216
+ "regex",
2217
  "sharded-slab",
2218
  "smallvec",
2219
  "thread_local",
2220
+ "tracing",
2221
  "tracing-core",
2222
  "tracing-log",
2223
  ]
Cargo.toml CHANGED
@@ -19,7 +19,7 @@ serde_yaml = "0.9"
19
  tokio = { version = "1.33", features = ["macros", "rt-multi-thread", "sync"] }
20
  tokio-stream = "0.1"
21
  tracing = "0.1"
22
- tracing-subscriber = "0.3"
23
  whisper-rs = "0.9.0-rc.2"
24
  whisper-rs-sys = "0.7"
25
 
@@ -28,5 +28,5 @@ version = "1.3"
28
  features = ["websocket", "static-files"]
29
 
30
  [target.aarch64-apple-darwin.dependencies.whisper-rs]
31
- version ="0.9.0-rc.2"
32
  features = ["coreml"]
 
19
  tokio = { version = "1.33", features = ["macros", "rt-multi-thread", "sync"] }
20
  tokio-stream = "0.1"
21
  tracing = "0.1"
22
+ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
23
  whisper-rs = "0.9.0-rc.2"
24
  whisper-rs-sys = "0.7"
25
 
 
28
  features = ["websocket", "static-files"]
29
 
30
  [target.aarch64-apple-darwin.dependencies.whisper-rs]
31
+ version = "0.9.0-rc.2"
32
  features = ["coreml"]
docker-compose.yaml ADDED
File without changes
src/config.rs CHANGED
@@ -4,6 +4,7 @@ use config::{Config, Environment, File};
4
  use once_cell::sync::Lazy;
5
  use serde::Deserialize;
6
  use whisper_rs::FullParams;
 
7
 
8
  pub(crate) static SETTINGS: Lazy<Settings> =
9
  Lazy::new(|| Settings::new().expect("Failed to initialize settings"));
@@ -86,6 +87,10 @@ impl Settings {
86
  .map_err(anyhow::Error::from)?;
87
 
88
  config.try_deserialize::<Self>().map_err(Into::into)
 
 
 
 
89
  }
90
  }
91
 
 
4
  use once_cell::sync::Lazy;
5
  use serde::Deserialize;
6
  use whisper_rs::FullParams;
7
+ use tracing::debug;
8
 
9
  pub(crate) static SETTINGS: Lazy<Settings> =
10
  Lazy::new(|| Settings::new().expect("Failed to initialize settings"));
 
87
  .map_err(anyhow::Error::from)?;
88
 
89
  config.try_deserialize::<Self>().map_err(Into::into)
90
+ .map(|settings| {
91
+ debug!("Settings: {settings:?}");
92
+ settings
93
+ })
94
  }
95
  }
96
 
src/main.rs CHANGED
@@ -19,6 +19,8 @@ use poem::{
19
  };
20
  use serde::{Deserialize, Serialize};
21
  use tokio::select;
 
 
22
 
23
  use crate::{config::*, lesson::*, whisper::*};
24
 
@@ -34,11 +36,12 @@ struct Context {
34
 
35
  #[tokio::main]
36
  async fn main() -> Result<(), std::io::Error> {
37
- tracing_subscriber::fmt::init();
 
 
 
38
 
39
- if tracing::enabled!(tracing::Level::DEBUG) {
40
- tracing::debug!("Transcribe client version: {}", PKG_VERSION);
41
- }
42
 
43
  let shared_config = aws_config::load_from_env().await;
44
  let ctx = Context {
@@ -95,8 +98,8 @@ async fn stream_speaker(
95
  ws.on_upgrade(|mut socket| async move {
96
  let _origin_tx = lesson.voice_channel();
97
  let mut transcribe_rx = lesson.transcript_channel();
98
- let whisper =
99
- WhisperHandler::new(SETTINGS.whisper.clone(), prompt).expect("failed to create whisper");
100
  let mut whisper_transcribe_rx = whisper.subscribe();
101
  loop {
102
  select! {
 
19
  };
20
  use serde::{Deserialize, Serialize};
21
  use tokio::select;
22
+ use tracing::debug;
23
+ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
24
 
25
  use crate::{config::*, lesson::*, whisper::*};
26
 
 
36
 
37
  #[tokio::main]
38
  async fn main() -> Result<(), std::io::Error> {
39
+ tracing_subscriber::registry()
40
+ .with(fmt::layer())
41
+ .with(EnvFilter::from_default_env())
42
+ .init();
43
 
44
+ debug!("Transcribe client version: {}", PKG_VERSION);
 
 
45
 
46
  let shared_config = aws_config::load_from_env().await;
47
  let ctx = Context {
 
98
  ws.on_upgrade(|mut socket| async move {
99
  let _origin_tx = lesson.voice_channel();
100
  let mut transcribe_rx = lesson.transcript_channel();
101
+ let whisper = WhisperHandler::new(SETTINGS.whisper.clone(), prompt)
102
+ .expect("failed to create whisper");
103
  let mut whisper_transcribe_rx = whisper.subscribe();
104
  loop {
105
  select! {
src/whisper.rs CHANGED
@@ -8,6 +8,7 @@ use std::{
8
 
9
  use once_cell::sync::Lazy;
10
  use tokio::sync::{broadcast, mpsc, oneshot};
 
11
  use whisper_rs::{convert_integer_to_float_audio, WhisperContext, WhisperState, WhisperToken};
12
  use whisper_rs_sys::WHISPER_SAMPLE_RATE;
13
 
@@ -124,15 +125,13 @@ impl WhisperHandler {
124
  }
125
  };
126
 
127
- if tracing::enabled!(tracing::Level::TRACE) {
128
- for segment in segments.iter() {
129
- tracing::trace!(
130
- "[{}-{}]s SEGMENT: {}",
131
- segment.start_timestamp as f32 / 1000.0,
132
- segment.end_timestamp as f32 / 1000.0,
133
- segment.text
134
- );
135
- }
136
  }
137
 
138
  if let Err(e) = shared_transcription_tx.send(segments) {
 
8
 
9
  use once_cell::sync::Lazy;
10
  use tokio::sync::{broadcast, mpsc, oneshot};
11
+ use tracing::trace;
12
  use whisper_rs::{convert_integer_to_float_audio, WhisperContext, WhisperState, WhisperToken};
13
  use whisper_rs_sys::WHISPER_SAMPLE_RATE;
14
 
 
125
  }
126
  };
127
 
128
+ for segment in segments.iter() {
129
+ trace!(
130
+ "[{}-{}]s SEGMENT: {}",
131
+ segment.start_timestamp as f32 / 1000.0,
132
+ segment.end_timestamp as f32 / 1000.0,
133
+ segment.text
134
+ );
 
 
135
  }
136
 
137
  if let Err(e) = shared_transcription_tx.send(segments) {