-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #2787: model.generate时,传入的是音频字节流,会对采样率校验耗时200ms。 #2820
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
Open
danielalanbates
wants to merge
1
commit into
modelscope:main
Choose a base branch
from
danielalanbates:fix/issue-2787
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |||||||||||||||||
| from funasr.download.file import download_from_url | ||||||||||||||||||
| except: | ||||||||||||||||||
| print("urllib is not installed, if you infer from url, please install it first.") | ||||||||||||||||||
| import pdb | ||||||||||||||||||
| import subprocess | ||||||||||||||||||
| from subprocess import CalledProcessError, run | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -144,11 +143,42 @@ def load_audio_text_image_video( | |||||||||||||||||
| return data_or_path_or_list | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _is_audio_container(data: bytes) -> bool: | ||||||||||||||||||
| """Return True if *data* starts with a recognised container-format magic header. | ||||||||||||||||||
|
|
||||||||||||||||||
| Raw PCM byte streams have no header, so they will return False and the | ||||||||||||||||||
| expensive pydub/ffmpeg validation round-trip can be skipped entirely. | ||||||||||||||||||
| """ | ||||||||||||||||||
| if len(data) < 4: | ||||||||||||||||||
| return False | ||||||||||||||||||
| # WAV – RIFF....WAVE | ||||||||||||||||||
| if data[:4] == b"RIFF": | ||||||||||||||||||
| return True | ||||||||||||||||||
| # MP3 – ID3 tag or sync word (0xFF 0xEx) | ||||||||||||||||||
| if data[:3] == b"ID3" or (data[0] == 0xFF and (data[1] & 0xE0) == 0xE0): | ||||||||||||||||||
| return True | ||||||||||||||||||
| # OGG | ||||||||||||||||||
| if data[:4] == b"OggS": | ||||||||||||||||||
| return True | ||||||||||||||||||
| # FLAC | ||||||||||||||||||
| if data[:4] == b"fLaC": | ||||||||||||||||||
| return True | ||||||||||||||||||
| # MP4 / M4A / AAC – 'ftyp' box at offset 4 | ||||||||||||||||||
| if len(data) >= 8 and data[4:8] == b"ftyp": | ||||||||||||||||||
| return True | ||||||||||||||||||
| return False | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def load_bytes(input): | ||||||||||||||||||
| try: | ||||||||||||||||||
| input = validate_frame_rate(input) | ||||||||||||||||||
| except: | ||||||||||||||||||
| pass | ||||||||||||||||||
| # Only run the (expensive) frame-rate validation when the payload is an | ||||||||||||||||||
| # actual audio container (WAV, MP3, OGG, …). Raw PCM buffers have no | ||||||||||||||||||
| # recognisable header and would cause pydub to spend ~200 ms before | ||||||||||||||||||
| # raising an exception that is then silently swallowed anyway. | ||||||||||||||||||
| if _is_audio_container(input): | ||||||||||||||||||
| try: | ||||||||||||||||||
| input = validate_frame_rate(input) | ||||||||||||||||||
| except: | ||||||||||||||||||
| pass | ||||||||||||||||||
|
Comment on lines
+178
to
+181
Contributor
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. 建议避免使用空的
Suggested change
References
|
||||||||||||||||||
| middle_data = np.frombuffer(input, dtype=np.int16) | ||||||||||||||||||
| middle_data = np.asarray(middle_data) | ||||||||||||||||||
| if middle_data.dtype.kind not in "iu": | ||||||||||||||||||
|
|
||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议增加对 WebM/Matroska 容器格式的检查。WebM 格式(通常包含 Opus 编码的音频)在 Web 应用和流媒体中非常常见。其 EBML 头部标识符为
\x1a\x45\xdf\xa3。