Skip to content

is there a faster way to play audio? #787

@deostroll

Description

@deostroll

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions