Skip to content

Fix #2793: bug: utils.load_utils.extract_fbank 函數當遇到 雙聲道音檔時會錯誤#2819

Merged
LauraGPT merged 1 commit intomodelscope:mainfrom
danielalanbates:fix/issue-2793
Feb 27, 2026
Merged

Fix #2793: bug: utils.load_utils.extract_fbank 函數當遇到 雙聲道音檔時會錯誤#2819
LauraGPT merged 1 commit intomodelscope:mainfrom
danielalanbates:fix/issue-2793

Conversation

@danielalanbates
Copy link
Contributor

Fixes #2793

Summary

This PR addresses: bug: utils.load_utils.extract_fbank 函數當遇到 雙聲道音檔時會錯誤

Changes

funasr/utils/load_utils.py | 4 ++++
 1 file changed, 4 insertions(+)

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!

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 resolves a critical bug in the extract_fbank utility function that caused failures when processing multi-channel audio inputs, such as stereo sound files. The fix ensures robust handling of diverse audio formats by automatically downmixing multi-channel data to mono, thereby preventing errors and improving the function's reliability.

Highlights

  • Bug Fix: Stereo Audio Handling: The extract_fbank function now correctly processes multi-channel audio (e.g., stereo) by converting it to a mono channel, resolving an error when such inputs were encountered.

🧠 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
  • funasr/utils/load_utils.py
    • Implemented logic to convert multi-channel audio data to mono before feature extraction.
Activity
  • The pull request was created with the assistance of Claude Sonnet 4.6 by Anthropic.
  • The fix was verified against the existing test suite.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

這個 PR 修復了 extract_fbank 函數在處理雙聲道(stereo)音檔時會報錯的問題(#2793),透過將多聲道訊號平均化為單聲道來確保與後續前端處理流程的相容性。這是一個正確且必要的修復。建議進一步優化代碼結構以減少重複邏輯,並確保所有輸入類型(特別是列表輸入)都能獲得一致的處理。

Comment on lines +203 to +204
elif data.shape[0] > 1:
data = data.mean(dim=0, keepdim=True) # convert stereo/multi-channel to mono
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

此處新增的處理邏輯與下方 torch.Tensor 分支中的代碼完全重複。建議重構此部分,在將 np.ndarray 轉換為 torch.Tensor 後,統一進行維度檢查與多聲道轉單聲道的處理,以減少代碼冗餘並提高可維護性。

Comment on lines +209 to +210
elif data.shape[0] > 1:
data = data.mean(dim=0, keepdim=True) # convert stereo/multi-channel to mono
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

此處邏輯與上方重複。此外,建議檢查 isinstance(data, (list, tuple)) 的分支(第 212 行起)。如果傳入的是包含多聲道音檔的列表,目前的修改並未涵蓋該情況,這會導致在第 218 行計算 data_len 時取得錯誤的數值(聲道數而非時間長度)。建議在處理列表元素的循環中也加入相同的 downmix 邏輯以確保功能完整性。

@LauraGPT LauraGPT merged commit a1bc5b5 into modelscope:main Feb 27, 2026
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.

bug: utils.load_utils.extract_fbank 函數當遇到 雙聲道音檔時會錯誤

2 participants