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,25 +85,28 @@ 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 {
num_results = num_results + 1; if res.is_final {
info!("Result {} {{", num_results); num_results = num_results + 1;
if let Some(rec) = res.alternatives.first() { info!("Result {} {{", num_results);
info!("\tTranscription: {}", rec.transcript);
for word_info in &rec.words { if let Some(rec) = res.alternatives.first() {
// let start_time: WordTimestamp = word_info.start_time.into(); info!("\tTranscription: {}", rec.transcript);
let start_time = word_info.start_time.as_ref().unwrap(); for word_info in &rec.words {
let end_time = word_info.end_time.as_ref().unwrap(); // let start_time: WordTimestamp = word_info.start_time.into();
info!( let start_time = word_info.start_time.as_ref().unwrap();
"\t - {}: [{}.{} - {}.{}]", let end_time = word_info.end_time.as_ref().unwrap();
word_info.word, info!(
start_time.seconds, "\t - {}: [{}.{} - {}.{}]",
start_time.nanos, word_info.word,
end_time.seconds, start_time.seconds,
end_time.nanos start_time.nanos,
); end_time.seconds,
end_time.nanos
);
}
} }
info!("}}");
} }
info!("}}");
} }
} }