Implementation of realtime STT using external stream.

ywmo 41 Reputation points
2023-02-24T04:13:55.4566667+00:00

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:

  1. create SpeechConfig from my subscription
  2. create pushStream which is instance of PushAudioInputStream, and create audioConfig using pushStream
   PushAudioInputStream pushStream  = AudioInputStream.createPushStream();
   AudioConfig audioConfig = AudioConfig.fromStreamInput(pushStream);
  1. start speech recognition
   recognizer.startContinuousRecognitionAsync().get();
   ...
  1. 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));    }
}
  1. stop speech recognition and close the resources.
Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
1,956 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.