Use final

This commit is contained in:
Rafael Caricio 2022-04-06 14:47:11 +02:00
parent 2ae0fc21f9
commit 393661f197
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947

View file

@ -18,7 +18,7 @@ async fn main() -> eyre::Result<()> {
debug!("starting..."); debug!("starting...");
let channel = Channel::from_static("https://speech.googleapis.com") let speech_api_channel = Channel::from_static("https://speech.googleapis.com")
.connect() .connect()
.await?; .await?;
@ -26,14 +26,14 @@ async fn main() -> eyre::Result<()> {
.json_file("i-centralvideo-dictate-dev-c184dd68967a.json".as_ref()) .json_file("i-centralvideo-dictate-dev-c184dd68967a.json".as_ref())
.build() .build()
.await?; .await?;
let channel = GoogleAuthz::builder(channel) let auth_channel = GoogleAuthz::builder(speech_api_channel)
.credentials(credentials) .credentials(credentials)
.build() .build()
.await; .await;
debug!("authenticated channel created!"); 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(); let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
@ -71,7 +71,7 @@ async fn main() -> eyre::Result<()> {
BytesMut::from(&buffer.as_slice()[..n]).freeze(), 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); //debug!("added a buffer to the sender queue: {} bytes", n);
tokio::time::sleep(std::time::Duration::from_millis(100)).await; tokio::time::sleep(std::time::Duration::from_millis(100)).await;
} }
@ -85,8 +85,10 @@ async fn main() -> eyre::Result<()> {
while let Some(response) = inbound.message().instrument(tracing::info_span!("transcription-results")).await? { while let Some(response) = inbound.message().instrument(tracing::info_span!("transcription-results")).await? {
let mut num_results = 0; let mut num_results = 0;
for res in &response.results { for res in &response.results {
if res.is_final {
num_results = num_results + 1; num_results = num_results + 1;
info!("Result {} {{", num_results); info!("Result {} {{", num_results);
if let Some(rec) = res.alternatives.first() { if let Some(rec) = res.alternatives.first() {
info!("\tTranscription: {}", rec.transcript); info!("\tTranscription: {}", rec.transcript);
for word_info in &rec.words { for word_info in &rec.words {
@ -106,6 +108,7 @@ async fn main() -> eyre::Result<()> {
info!("}}"); info!("}}");
} }
} }
}
Ok(()) Ok(())
} }