record icon indicating copy to clipboard operation
record copied to clipboard

Trying to stream PCM16 over websockets to Google's Speech-to-Text API results in a jumbled mess.

Open BambooRaptor opened this issue 1 year ago • 2 comments

Package version: ^5.0.4

Environment

  • OS: Android/iOSl

Describe the bug I am trying to use the record library to transcribe audio in realtime. I want to send the stream of audio in PCM16 format over websockets to a custom server, which will then send it to a Speech-to-Text service. However, doing a stream.listen on

final AudioRecorder _recorder = AudioRecorder();

final stream = await _recorder.startStream(const RecordConfig(
    encoder: AudioEncoder.pcm16bits,
    sampleRate: 48000,
));

returns a Uint8List which does not work well since the service expects PCM16 to be a 16bit list. So far, I have tried _recorder.convertBytesToInt16(chunk), a for loop that just sends the data one 8bit int at a time, chunk.buffer.toInt8List(), and just sending the chunk.buffer as is, but nothing has worked.

Expected behavior Ideally, the resulting stream from the PCM16 encoding should be an Int16List to reflect the true nature of the data, but this oversight seems to be there in all the recording libraries for some reason. How could I go about solving this? How can I extract the 16 bit integers for PCM16 from this Uint8List?

BambooRaptor avatar Feb 13 '24 16:02 BambooRaptor

deleting my previous comment because it was completely off base- @BambooRaptor if you are still working this, try parsing every two int8s into an in16 in little endian. before pushing it to the service.

austibwu avatar Feb 20 '24 04:02 austibwu

Why would you convert bytes to integers (16bits) before sending the stream over network? You can only send bytes. I guess your issue is more about the sample rate which should be 8kHz or 16kHz, shouldn't it? Or something else that isn't written here. The stream returns Uint8List because it allows to convert it to integers or floats if needed (float (32bits) is not supported at this time).

So far, there's no issue related to this package. Please, use discussion feature for such concern.

llfbandit avatar Mar 24 '24 16:03 llfbandit