working example
This commit is contained in:
parent
9ef6213ed9
commit
7262352247
1 changed files with 15 additions and 13 deletions
28
src/main.rs
28
src/main.rs
|
@ -42,7 +42,8 @@ async fn main() -> eyre::Result<()> {
|
||||||
StreamingRecognitionConfig {
|
StreamingRecognitionConfig {
|
||||||
config: Some(RecognitionConfig {
|
config: Some(RecognitionConfig {
|
||||||
encoding: AudioEncoding::Flac.into(), // matching current example file
|
encoding: AudioEncoding::Flac.into(), // matching current example file
|
||||||
sample_rate_hertz: 48000, // matching current example file
|
sample_rate_hertz: 44_100, // matching current example file
|
||||||
|
audio_channel_count: 2,
|
||||||
language_code: "en-US".to_string(), // we only support en-US to start with
|
language_code: "en-US".to_string(), // we only support en-US to start with
|
||||||
model: "video".to_string(), // dictate does not set this option
|
model: "video".to_string(), // dictate does not set this option
|
||||||
use_enhanced: true, // dictate does not set this option
|
use_enhanced: true, // dictate does not set this option
|
||||||
|
@ -59,18 +60,19 @@ async fn main() -> eyre::Result<()> {
|
||||||
yield request;
|
yield request;
|
||||||
let file = tokio::fs::File::open("some-audio.flac").await.unwrap();
|
let file = tokio::fs::File::open("some-audio.flac").await.unwrap();
|
||||||
let mut audio_file = tokio::io::BufReader::new(file);
|
let mut audio_file = tokio::io::BufReader::new(file);
|
||||||
// read file chunk
|
// read file chunk
|
||||||
let mut buffer = [0; 1024 * 5];
|
let mut buffer = [0; 1024 * 50];
|
||||||
while audio_file.read(&mut buffer).await.is_ok() {
|
while let Ok(n) = audio_file.read(&mut buffer[..]).await {
|
||||||
// send to server
|
// send to server
|
||||||
let request = StreamingRecognizeRequest {
|
let request = StreamingRecognizeRequest {
|
||||||
streaming_request: Some(StreamingRequest::AudioContent(
|
streaming_request: Some(StreamingRequest::AudioContent(
|
||||||
BytesMut::from(buffer.as_slice()).freeze(),
|
BytesMut::from(&buffer.as_slice()[..n]).freeze(),
|
||||||
)),
|
)),
|
||||||
};
|
};
|
||||||
yield request;
|
yield request;
|
||||||
debug!("added a buffer to the sender queue");
|
// debug!("added a buffer to the sender queue: {} bytes", n);
|
||||||
}
|
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
|
|
Loading…
Reference in a new issue