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

is there a faster way to play audio? #787

Open
deostroll opened this issue Mar 25, 2024 · 0 comments
Open

is there a faster way to play audio? #787

deostroll opened this issue Mar 25, 2024 · 0 comments

Comments

@deostroll
Copy link

Is there a faster way to play (without pauses)?

from pydub import AudioSegment
from argparse import ArgumentParser
from pydub.playback import play

if __name__ == '__main__':
    parser = ArgumentParser('test.py')
    parser.add_argument('file')

    args = parser.parse_args()

    sound = AudioSegment.from_file(args.file)

    length = len(sound)

    print('length:', length)

    # play(sound)

    idx = 0 
    inc = 1024
    cnt = 0
    while idx < length:
        if idx + inc > length:
            clip = sound[idx:]
        else:
            clip = sound[idx: idx + inc]
            cnt += 1
            print('Count:', cnt)
        idx = idx + inc
        play(clip)

    print('done')

Run this script with a suitably big audio file. I ran one with 20s length. You will hear the pauses between chunks. (Incidentally on my machine I only have ffmpeg installed. Therefore it defaults to ffplay. And there is a conversion to wav file prior to playing the audio. (https://github.com/jiaaro/pydub/blob/master/pydub/playback.py#L15)

Looking for a smoother alternative. Perhaps my code is to blame too!

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

No branches or pull requests

1 participant