diff --git a/src/main.rs b/src/main.rs index 49b9edf..17a903b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ async fn main() -> eyre::Result<()> { debug!("starting..."); - let channel = Channel::from_static("https://speech.googleapis.com") + let speech_api_channel = Channel::from_static("https://speech.googleapis.com") .connect() .await?; @@ -26,14 +26,14 @@ async fn main() -> eyre::Result<()> { .json_file("i-centralvideo-dictate-dev-c184dd68967a.json".as_ref()) .build() .await?; - let channel = GoogleAuthz::builder(channel) + let auth_channel = GoogleAuthz::builder(speech_api_channel) .credentials(credentials) .build() .await; debug!("authenticated channel created!"); - let mut client = SpeechClient::new(channel); + let mut client = SpeechClient::new(auth_channel); let (sender, receiver) = tokio::sync::mpsc::unbounded_channel(); @@ -71,7 +71,7 @@ async fn main() -> eyre::Result<()> { BytesMut::from(&buffer.as_slice()[..n]).freeze(), )), }; - sender.send(request).unwrap(); + let result = sender.send(request); //debug!("added a buffer to the sender queue: {} bytes", n); tokio::time::sleep(std::time::Duration::from_millis(100)).await; } @@ -85,25 +85,28 @@ async fn main() -> eyre::Result<()> { while let Some(response) = inbound.message().instrument(tracing::info_span!("transcription-results")).await? { let mut num_results = 0; for res in &response.results { - num_results = num_results + 1; - info!("Result {} {{", num_results); - if let Some(rec) = res.alternatives.first() { - info!("\tTranscription: {}", rec.transcript); - for word_info in &rec.words { - // let start_time: WordTimestamp = word_info.start_time.into(); - let start_time = word_info.start_time.as_ref().unwrap(); - let end_time = word_info.end_time.as_ref().unwrap(); - info!( - "\t - {}: [{}.{} - {}.{}]", - word_info.word, - start_time.seconds, - start_time.nanos, - end_time.seconds, - end_time.nanos - ); + if res.is_final { + num_results = num_results + 1; + info!("Result {} {{", num_results); + + if let Some(rec) = res.alternatives.first() { + info!("\tTranscription: {}", rec.transcript); + for word_info in &rec.words { + // let start_time: WordTimestamp = word_info.start_time.into(); + let start_time = word_info.start_time.as_ref().unwrap(); + let end_time = word_info.end_time.as_ref().unwrap(); + info!( + "\t - {}: [{}.{} - {}.{}]", + word_info.word, + start_time.seconds, + start_time.nanos, + end_time.seconds, + end_time.nanos + ); + } } + info!("}}"); } - info!("}}"); } }