Implementation of realtime STT using external stream.
Hello, I am trying to implement spring server that uses STOMP protocol
recieving stream of data , and sends it to azure speech to get STT result.
Currently I am stuck in sending the audio stream to azure. According to the log of my subscription, the recieved audio file is empty. can you give me some advice for it? Below is the code implementation.
(FYI : external stream is from web audio API, and has followed the audio stream condtion suggested below: https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/how-to-use-audio-input-streams )
In spring server the process goes like this:
- create SpeechConfig from my subscription
- create pushStream which is instance of PushAudioInputStream, and create audioConfig using pushStream
PushAudioInputStream pushStream = AudioInputStream.createPushStream();
AudioConfig audioConfig = AudioConfig.fromStreamInput(pushStream);
- start speech recognition
recognizer.startContinuousRecognitionAsync().get();
...
- create buffer and read the audioInputstream then write it on the pushStream (audioInputStream is a ByteArrayInputStream)
while (true){
if (!((bytesRead = audioInputStream.read(readBuffer)) != -1)) break;
if (bytesRead == readBuffer.length){
pushStream.write(readBuffer);
}
else { pushStream.write(Arrays.copyOfRange(readBuffer, 0, bytesRead)); }
}
- stop speech recognition and close the resources.