-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Enforce 25Kb limit for infinite transcription #13301
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,8 @@ | |
STREAMING_LIMIT = 240000 # 4 minutes | ||
SAMPLE_RATE = 16000 | ||
CHUNK_SIZE = int(SAMPLE_RATE / 10) # 100ms | ||
# 25KB API limit. Increasing this will throw error | ||
MAX_STREAMING_CHUNK = 25 * 1024 | ||
|
||
RED = "\033[0;31m" | ||
GREEN = "\033[0;32m" | ||
|
@@ -213,7 +215,23 @@ def generator(self: object) -> object: | |
except queue.Empty: | ||
break | ||
|
||
yield b"".join(data) | ||
# Enforce max streaming chunk size supported by the API | ||
combined_size = sum(len(chunk) for chunk in data) | ||
if combined_size <= MAX_STREAMING_CHUNK: | ||
yield b"".join(data) | ||
else: | ||
run_chunks = [] | ||
run_size = 0 | ||
for chunk in data: | ||
if len(chunk) + run_size > MAX_STREAMING_CHUNK: | ||
yield b"".join(run_chunks) | ||
run_chunks = [chunk] | ||
run_size = len(chunk) | ||
else: | ||
run_chunks.append(chunk) | ||
run_size += len(chunk) | ||
if run_chunks: | ||
yield b"".join(run_chunks) | ||
Comment on lines
+219
to
+234
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code iterates through the current_chunk = []
current_chunk_size = 0
for chunk in data:
if current_chunk_size + len(chunk) <= MAX_STREAMING_CHUNK:
current_chunk.append(chunk)
current_chunk_size += len(chunk)
else:
if current_chunk:
yield b''.join(current_chunk)
current_chunk = [chunk]
current_chunk_size = len(chunk)
if current_chunk:
yield b''.join(current_chunk)
suvigyajain0101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def listen_print_loop(responses: object, stream: object) -> None: | ||
|
Uh oh!
There was an error while loading. Please reload this page.