This commit is contained in:
Rafael Caricio 2022-02-11 14:05:37 +01:00
parent f63fb5d01b
commit d1ed877a6d
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947

View file

@ -5,8 +5,9 @@ use google_api_proto::google::cloud::speech::v1::{
StreamingRecognitionConfig, StreamingRecognizeRequest, StreamingRecognitionConfig, StreamingRecognizeRequest,
}; };
use google_authz::{Credentials, GoogleAuthz}; use google_authz::{Credentials, GoogleAuthz};
use log::{debug, info}; use log::{debug, info, warn};
use tokio::io::AsyncReadExt; use tokio::io::AsyncReadExt;
use tokio_stream::wrappers::UnboundedReceiverStream;
use tonic::transport::Channel; use tonic::transport::Channel;
use tracing::Instrument; use tracing::Instrument;
@ -38,7 +39,7 @@ async fn main() -> eyre::Result<()> {
let mut client = SpeechClient::new(channel); let mut client = SpeechClient::new(channel);
let (sender, mut receiver) = tokio::sync::mpsc::unbounded_channel(); let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
sender.send(StreamingRecognizeRequest { sender.send(StreamingRecognizeRequest {
streaming_request: Some(StreamingRequest::StreamingConfig( streaming_request: Some(StreamingRequest::StreamingConfig(
@ -77,18 +78,10 @@ async fn main() -> eyre::Result<()> {
//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;
} }
}).instrument(tracing::info_span!("audio-source")).await?; });
let message = async_stream::stream! {
while let Some(message) = receiver.recv().await {
debug!("drained message inside stream...");
yield message;
}
};
let response = client let response = client
.streaming_recognize(tonic::Request::new(message)) .streaming_recognize(UnboundedReceiverStream::new(receiver))
.await?; .await?;
let mut inbound = response.into_inner(); let mut inbound = response.into_inner();