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,15 +5,16 @@ use google_api_proto::google::cloud::speech::v1::{
StreamingRecognitionConfig, StreamingRecognizeRequest,
};
use google_authz::{Credentials, GoogleAuthz};
use log::{debug, info};
use log::{debug, info, warn};
use tokio::io::AsyncReadExt;
use tokio_stream::wrappers::UnboundedReceiverStream;
use tonic::transport::Channel;
use tracing::Instrument;
#[tokio::main]
async fn main() -> eyre::Result<()> {
tracing_subscriber::fmt::init();
//console_subscriber::init();
// console_subscriber::init();
debug!("starting...");
@ -38,7 +39,7 @@ async fn main() -> eyre::Result<()> {
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 {
streaming_request: Some(StreamingRequest::StreamingConfig(
@ -77,18 +78,10 @@ async fn main() -> eyre::Result<()> {
//debug!("added a buffer to the sender queue: {} bytes", n);
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
.streaming_recognize(tonic::Request::new(message))
.streaming_recognize(UnboundedReceiverStream::new(receiver))
.await?;
let mut inbound = response.into_inner();