Skip to content
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

fix precision problem of silent #819

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pengzhendong
Copy link

@pengzhendong pengzhendong commented Dec 4, 2024

frame_rate = 16000
duration = 1013
print("Before the pr:", int(frame_rate * (duration / 1000.0)) / frame_rate)
print("After the pr:", int(frame_rate * duration / 1000.0) / frame_rate)
Before the pr: 1.0129375
After the pr: 1.013

If the pr could not be merged, hot fix:

from pydub import AudioSegment
def silent(cls, duration=1000, frame_rate=11025):
    frames = int(frame_rate * duration / 1000.0)
    data = b"\0\0" * frames
    return cls(data, metadata={"channels": 1,
                                "sample_width": 2,
                                "frame_rate": frame_rate,
                                "frame_width": 2})
AudioSegment.silent = classmethod(silent)

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.

1 participant