Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BambooRaptor opened this issue Feb 13, 2024 · 2 comments

Comments

@BambooRaptor
Copy link

BambooRaptor commented Feb 13, 2024

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?

@austibwu
Copy link

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.

@llfbandit
Copy link
Owner

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 llfbandit closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants