Hey guys! I am trying to stream my microphone audio in byte[ ] form for real time speech to text transcription but I am having trouble.
Disclaimer, I am new to Unity and websockets and am trying to do everything manually at the moment, but am very happy to switch to an easier option with helpful packages or assets from the store. I would happily pay for a service if it would make things run smoothly.
Here is a snippet of code showing how I am currently trying to stream audio but I am sure there must be an easier way?
this.audioClip = Microphone.Start(microphoneDevice, true, recordingTime, SAMPLE_RATE);
audioData = ConvertToByte(audioClip);
// waiting for microphone to start recording
while (Microphone.GetPosition(null) <= 0)
{
}
audioPos = 0;
while (audioPos < audioData.Length)
{
int chunkSize = Mathf.Min(CHUNK_SIZE, audioData.Length - audioPos);
byte[] chunkData = new byte[chunkSize];
System.Buffer.BlockCopy(audioData, audioPos, chunkData, 0, chunkSize);
wsClient.SendAudio(chunkData);
if (chunkSize == audioData.Length - audioPos) //reset to beginning of audioClip
{
audioPos = 0;
}
else
{
audioPos += chunkSize;
}
}
Thanks a lot!