Works
This commit is contained in:
parent
f63fb5d01b
commit
d1ed877a6d
1 changed files with 6 additions and 13 deletions
19
src/main.rs
19
src/main.rs
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue