Open esgraham opened 4 years ago
Recommendation: recognizeOnceAsync
recognizeOnceAsync
method that returns a Future<T>
.get()
method on the future will block the current thread.ExecutorService
to get the results from the Future on a background thread. The ExecutorService
used in the Cognitive Services samples is the cached thread pool (Executors.newCachedThreadPool()
).Recommendation: stopContinuousRecognitionAsync
ExecutorService
set up for speech recognition to "await" the get()
call on the Future returned by stopContinuousRecognitionAsync
.Recommendation: SpeakTextAsync
and SpeakSsmlAsync
ExecutorService
that we set up for speech recognition for resolving the FutureRecommendation: AudioTrack
cancel(true)
on the Future<T>
returned by the SpeakTextAsync
method will stop playing any audio.Recommendation: recognizeOnce
recognizeOnceAsync
or recognizeOnce
seems to block the calling thread until speech recognition is complete, so the simplest option is to just use recognizeOnce
and run it on a background thread.Recommendation: stopContinuousRecognition
stopContinuousRecognition
will block the calling thread until complete. I believe this is desired behavior, so we may not need to switch this call onto a background thread, but it may lead to a poor UX if the stop / cancel operation takes too long.Recommendation: speakText
and speakSsml
Recommendation: AVAudioPlayer.stop
stop
method to cancel any active audio.A minor modification to the above, I actually recommend we do not use the Speech SDK for text-to-speech playback, because it does not support cancellation. Using the Speech SDK to get the audio data to play on something like AVAudioPlayer
(iOS) or AudioTrack
(Android) is not as efficient as piping the bytes directly from a REST call to Cognitive Services.
I believe we can efficiently use the Speech SDK to stream audio, if we leverage the PushAudioOutputStream
and direct the bytes written to the output stream directly to the AVAudioPlayer
/ AudioTrack
.
SpeechConfig speechConfig = SpeechConfig.fromSubscription(...);
CustomPushAudioOutputStreamCallback callback = new CustomPushAudioOutputStreamCallback();
PushAudioOutputStream outputStream = PushAudioOutputStream.create(callback);
AudioConfig audioConfig = AudioConfig.fromStreamOutput(outputStream);
SpeechSynthesizer synthesizer = new SpeechSynthesizer(speechConfig, audioConfig);
Description
As an architect, I want to understand how Cordova implements Async functionality, so that I can determine if plugin should implement the Speech SDK async functions.
Acceptance Criteria