jiaaro / pydub

Manipulate audio with a simple and easy high level interface
http://pydub.com
MIT License
8.96k stars 1.05k forks source link

Inconsistency with audio segment duration on silence or Sine #805

Open nikolas-loris-ai opened 3 months ago

nikolas-loris-ai commented 3 months ago

Hello, I'm facing the following issue.

Any help is appreciated

Steps to reproduce

In [48]: beep_segment = Sine(1000, sample_rate=8000).to_audio_segment(duration=4095)

In [49]: beep_segment.duration_seconds
Out[49]: 4.094875

In [52]: silence_segment = AudioSegment.silent(duration=4095, frame_rate=8000)

In [53]: silence_segment.duration_seconds
Out[53]: 4.094875

I'm trying to later replace parts of audio file with this segments and getting the error

ValueError('attempt to assign array of size 186399 to extended slice of size 186400')

Expected behavior

I would expect duration_seconds to be 4095

Actual behavior

Some milliseconds are missing

Your System configuration

Is there an audio file you can include to help us reproduce?

not needed