-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for embedded_continuous_recognition
- Loading branch information
1 parent
5484b0c
commit a296803
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
examples/recognizer/embedded_continuous_recognition_from_file.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use super::helpers; | ||
use cognitive_services_speech_sdk_rs::audio::AudioConfig; | ||
use cognitive_services_speech_sdk_rs::speech::{EmbeddedSpeechConfig, SpeechRecognizer}; | ||
use log::*; | ||
use std::env; | ||
use std::time::Duration; | ||
use tokio::time::sleep; | ||
|
||
#[allow(dead_code)] | ||
pub async fn run_example() { | ||
info!("------------------------------------------------------------"); | ||
info!("running embedded continuous_recognition_from_file example..."); | ||
info!("------------------------------------------------------------"); | ||
|
||
let filename = helpers::get_sample_file("turn_on_the_lamp.wav"); | ||
|
||
let audio_config = AudioConfig::from_wav_file_input(&filename).unwrap(); | ||
|
||
let mut speech_config = | ||
EmbeddedSpeechConfig::from_path(env::var("ModelPath").unwrap()).unwrap(); | ||
|
||
let models = speech_config.get_speech_recognition_models().unwrap(); | ||
let model = models.first().unwrap(); | ||
info!("Using first model: {:?}", model); | ||
|
||
speech_config | ||
.set_speech_recognition_model(model, env::var("ModelKey").unwrap()) | ||
.unwrap(); | ||
|
||
let mut speech_recognizer = | ||
SpeechRecognizer::from_embedded_config(speech_config, audio_config).unwrap(); | ||
|
||
helpers::set_callbacks(&mut speech_recognizer); | ||
|
||
if let Err(err) = speech_recognizer.start_continuous_recognition_async().await { | ||
error!("start_continuous_recognition_async error {:?}", err); | ||
} | ||
sleep(Duration::from_millis(10000)).await; | ||
speech_recognizer | ||
.stop_continuous_recognition_async() | ||
.await | ||
.unwrap(); | ||
|
||
info!("example finished!"); | ||
} |