Fix #2787: model.generate时,传入的是音频字节流,会对采样率校验耗时200ms。#2820
Fix #2787: model.generate时,传入的是音频字节流,会对采样率校验耗时200ms。#2820danielalanbates wants to merge 1 commit intomodelscope:mainfrom
Conversation
…ad_bytes `validate_frame_rate` calls `pydub.AudioSegment.from_file` which takes ~200 ms. When the caller passes raw PCM bytes (no container header) the call always fails and the exception is silently swallowed, wasting 200 ms on every invocation. Add a lightweight `_is_audio_container` helper that inspects the first few magic bytes of the input. `load_bytes` now only calls `validate_frame_rate` when the payload is a recognised container format (WAV / MP3 / OGG / FLAC / MP4). Raw PCM buffers skip the validation entirely, eliminating the latency hit. Also remove a stray `import pdb` debug statement.
Summary of ChangesHello @danielalanbates, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the performance of audio processing within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
| if len(data) >= 8 and data[4:8] == b"ftyp": | ||
| return True |
There was a problem hiding this comment.
| try: | ||
| input = validate_frame_rate(input) | ||
| except: | ||
| pass |
There was a problem hiding this comment.
建议避免使用空的 except:,因为这会捕获包括 KeyboardInterrupt 和 SystemExit 在内的所有异常,可能会掩盖真正的程序问题。建议改为捕获 Exception 或更具体的异常类型。
| try: | |
| input = validate_frame_rate(input) | |
| except: | |
| pass | |
| try: | |
| input = validate_frame_rate(input) | |
| except Exception: | |
| pass |
References
- PEP 8 建议不要使用空的 except: 语句,而应该捕获具体的异常或至少使用 except Exception:。 (link)
Fixes #2787
Summary
This PR addresses: model.generate时,传入的是音频字节流,会对采样率校验耗时200ms。
Changes
Testing
Please review the changes carefully. The fix was verified against the existing test suite.
This PR was created with the assistance of Claude Sonnet 4.6 by Anthropic | effort: low. Happy to make any adjustments!