Skip to content

Conversation

@albertreed
Copy link

This change addresses the error:
Conversation Error: { Error: 3 INVALID_ARGUMENT: Invalid 'audio_in': audio frame length is too long.
that results from trying to send chunks of audio that are too long.

@ItsWendell
Copy link

@albertreed @endoplasmic Even though I like the effort in helping the community by solving this issue, I don't think we should implement this within the library itself but should be done outside of the library, or make it an optional route limit the frame length.

Like we're discussing here in the referenced issue, google is probably talking about sample-frames instead of actual bytes in size that you're sending through to Google. (I'm not sure if this is the same or not)

--

As of this PR, there's a million way to process audio and whole libraries to do that for you so I think we should limit or at least separate audio processing from this library. Other applications using this library, who do their own processing, might get into problems if this update PR gets merged.

It's always good to do research on how google exactly wants their audio so let's continue this discussion and see what other people think and what else we can figure out to optimize this!

@albertreed
Copy link
Author

This PR doesn't process the audio - it just formats it to be compatible with google's API.

Copy link
Owner

@endoplasmic endoplasmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions and some styling updates.

// highly responsive.
let chunks = [];
while(chunks.length < data.length / MAX_FRAME_LENGTH) {
chunks.push(data.slice(chunks.length * MAX_FRAME_LENGTH, Math.min(data.length, (chunks.length + 1) * MAX_FRAME_LENGTH)));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I've never done reviewing in github, so forgive my noobness)

Can you break your Math.min into a const and give it a name explaining what it's doing?

while(chunks.length < data.length / MAX_FRAME_LENGTH) {
chunks.push(data.slice(chunks.length * MAX_FRAME_LENGTH, Math.min(data.length, (chunks.length + 1) * MAX_FRAME_LENGTH)));
}
chunks.forEach((chunk) =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the curly braces to wrap the for each, or put it all on 1 line?

// The max number of bytes of audio that can be sent in a single chunk.
// Not documented anywhere by google, but sending more than this amount
// throws an INVALID_REQUEST error stating that audio_in is too long.
const MAX_FRAME_LENGTH = 31 * 1024;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just figured out by process of elimination? Love me the prime number :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, yes. I'm very unfamiliar with the gRPC stuff so if you know a better way, let me know. It's susceptible to changes on their end which is obviously bad.

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

Successfully merging this pull request may close these issues.

3 participants